Oolite 1.91.0.7644-241112-7f5034b
Loading...
Searching...
No Matches
OOPListScript Class Reference

#include <OOPListScript.h>

+ Inheritance diagram for OOPListScript:
+ Collaboration diagram for OOPListScript:

Instance Methods

(void) - dealloc [implementation]
 
(NSString *) - name [implementation]
 
(NSString *) - scriptDescription [implementation]
 
(NSString *) - version [implementation]
 
(BOOL) - requiresTickle [implementation]
 
(void) - runWithTarget: [implementation]
 
(id) - initWithName:scriptArray:metadata: [implementation]
 
- Instance Methods inherited from OOScript
(NSString *) - displayName
 
(NSString *) - descriptionComponents [implementation]
 
(BOOL) - callMethod:inContext:withArguments:count:result:
 

Class Methods

(NSArray *) + scriptsInPListFile:
 
(NSArray *) + scriptsFromDictionaryOfScripts:filePath: [implementation]
 
(NSArray *) + loadCachedScripts: [implementation]
 
- Class Methods inherited from OOScript
(NSArray *) + worldScriptsAtPath:
 
(NSArray *) + scriptsFromFileNamed:
 
(NSArray *) + scriptsFromList:
 
(NSArray *) + scriptsFromFileAtPath:
 
(id) + jsScriptFromFileNamed:properties:
 
(id) + jsAIScriptFromFileNamed:properties:
 

Private Attributes

NSArray * _script
 
NSDictionary * _metadata
 

Detailed Description

Definition at line 36 of file OOPListScript.h.

Method Documentation

◆ dealloc

- (void) dealloc
implementation

Definition at line 39 of file OOPListScript.m.

70{
71 [_script release];
72 [_metadata release];
73
74 [super dealloc];
75}

◆ initWithName:scriptArray:metadata:

- (id) initWithName: (NSString *) name
scriptArray: (NSArray *) script
metadata: (NSDictionary *) metadata 
implementation

Provided by category OOPListScript(SetUp).

Definition at line 39 of file OOPListScript.m.

194 :(NSString *)name scriptArray:(NSArray *)script metadata:(NSDictionary *)metadata
195{
196 self = [super init];
197 if (self != nil)
198 {
199 _script = [script retain];
200 if (name != nil)
201 {
202 if (metadata == nil) metadata = [NSDictionary dictionaryWithObject:name forKey:kMDKeyName];
203 else
204 {
205 NSMutableDictionary *mutableMetadata = [[metadata mutableCopy] autorelease];
206 [mutableMetadata setObject:name forKey:kMDKeyName];
207 metadata = mutableMetadata;
208 }
209 }
210 _metadata = [metadata copy];
211 }
212
213 return self;
214}
return nil

◆ loadCachedScripts:

+ (NSArray *) loadCachedScripts: (NSDictionary *) cachedScripts
implementation

Provided by category OOPListScript(SetUp).

Definition at line 39 of file OOPListScript.m.

170 :(NSDictionary *)cachedScripts
171{
172 NSEnumerator *keyEnum = nil;
173 NSString *key = nil;
174
175 NSMutableArray *result = [NSMutableArray arrayWithCapacity:[cachedScripts count]];
176
177 for (keyEnum = [cachedScripts keyEnumerator]; (key = [keyEnum nextObject]); )
178 {
179 NSDictionary *cacheValue = [cachedScripts oo_dictionaryForKey:key];
180 NSArray *scriptArray = [cacheValue oo_arrayForKey:kKeyScript];
181 NSDictionary *metadata = [cacheValue oo_dictionaryForKey:kKeyMetadata];
182 OOPListScript *script = [[self alloc] initWithName:key scriptArray:scriptArray metadata:metadata];
183 if (script != nil)
184 {
185 [result addObject:script];
186 [script release];
187 }
188 }
189
190 return [[result copy] autorelease];
191}

◆ name

- (NSString *) name
implementation

Reimplemented from OOScript.

Definition at line 39 of file OOPListScript.m.

79{
80 return [_metadata objectForKey:kMDKeyName];
81}

◆ requiresTickle

- (BOOL) requiresTickle
implementation

Reimplemented from OOScript.

Definition at line 39 of file OOPListScript.m.

97{
98 return YES;
99}

◆ runWithTarget:

- (void) runWithTarget: (Entity *) target
implementation

Reimplemented from OOScript.

Definition at line 39 of file OOPListScript.m.

102 :(Entity *)target
103{
104 if (target != nil && ![target isKindOfClass:[ShipEntity class]])
105 {
106 OOLog(@"script.legacy.run.badTarget", @"Expected ShipEntity or nil for target, got %@.", [target class]);
107 return;
108 }
109
110 OOLog(@"script.legacy.run", @"Running script %@", [self displayName]);
111 OOLogIndentIf(@"script.legacy.run");
112
113 [PLAYER runScriptActions:_script
114 withContextName:[self name]
115 forTarget:(ShipEntity *)target];
116
117 OOLogOutdentIf(@"script.legacy.run");
118}
#define OOLogOutdentIf(class)
Definition OOLogging.h:102
#define OOLog(class, format,...)
Definition OOLogging.h:88
#define OOLogIndentIf(class)
Definition OOLogging.h:101
NSString * displayName()
Definition OOScript.m:277

◆ scriptDescription

- (NSString *) scriptDescription
implementation

Reimplemented from OOScript.

Definition at line 39 of file OOPListScript.m.

85{
86 return [_metadata objectForKey:kMDKeyDescription];
87}

◆ scriptsFromDictionaryOfScripts:filePath:

+ (NSArray *) scriptsFromDictionaryOfScripts: (NSDictionary *) dictionary
filePath: (NSString *) filePath 
implementation

Provided by category OOPListScript(SetUp).

Definition at line 39 of file OOPListScript.m.

125 :(NSDictionary *)dictionary filePath:(NSString *)filePath
126{
127 NSMutableArray *result = nil;
128 NSEnumerator *keyEnum = nil;
129 NSString *key = nil;
130 NSArray *scriptArray = nil;
131 NSDictionary *metadata = nil;
132 NSMutableDictionary *cachedScripts = nil;
133 OOPListScript *script = nil;
134
135 NSUInteger count = [dictionary count];
136 result = [NSMutableArray arrayWithCapacity:count];
137 cachedScripts = [NSMutableDictionary dictionaryWithCapacity:count];
138
139 metadata = [dictionary objectForKey:kKeyMetadata];
140 if (![metadata isKindOfClass:[NSDictionary class]]) metadata = nil;
141
142 for (keyEnum = [dictionary keyEnumerator]; (key = [keyEnum nextObject]); )
143 {
144 scriptArray = [dictionary objectForKey:key];
145 if ([key isKindOfClass:[NSString class]] &&
146 [scriptArray isKindOfClass:[NSArray class]] &&
147 ![key isEqual:kKeyMetadata])
148 {
149 scriptArray = OOSanitizeLegacyScript(scriptArray, key, NO);
150 if (scriptArray != nil)
151 {
152 script = [[self alloc] initWithName:key scriptArray:scriptArray metadata:metadata];
153 if (script != nil)
154 {
155 [result addObject:script];
156 [cachedScripts setObject:[NSDictionary dictionaryWithObjectsAndKeys:scriptArray, kKeyScript, metadata, kKeyMetadata, nil] forKey:key];
157
158 [script release];
159 }
160 }
161 }
162 }
163
164 [[OOCacheManager sharedCache] setObject:cachedScripts forKey:filePath inCache:kCacheName];
165
166 return [[result copy] autorelease];
167}
NSArray * OOSanitizeLegacyScript(NSArray *script, NSString *context, BOOL allowAIMethods)
static NSString *const kKeyMetadata
unsigned count
void setObject:forKey:inCache:(id inElement,[forKey] NSString *inKey,[inCache] NSString *inCacheKey)
OOCacheManager * sharedCache()

◆ scriptsInPListFile:

+ (NSArray *) scriptsInPListFile: (NSString *) filePath

Definition at line 39 of file OOPListScript.m.

53 :(NSString *)filePath
54{
55 NSDictionary *cachedScripts = [[OOCacheManager sharedCache] objectForKey:filePath inCache:kCacheName];
56 if (cachedScripts != nil)
57 {
58 return [self loadCachedScripts:cachedScripts];
59 }
60 else
61 {
62 NSDictionary *dict = OODictionaryFromFile(filePath);
63 if (dict == nil) return nil;
64 return [self scriptsFromDictionaryOfScripts:dict filePath:filePath];
65 }
66}
NSDictionary * OODictionaryFromFile(NSString *path)
id objectForKey:inCache:(NSString *inKey,[inCache] NSString *inCacheKey)

Referenced by OOScript::descriptionComponents.

+ Here is the caller graph for this function:

◆ version

- (NSString *) version
implementation

Reimplemented from OOScript.

Definition at line 39 of file OOPListScript.m.

91{
92 return [_metadata objectForKey:kMDKeyVersion];
93}

Member Data Documentation

◆ _metadata

- (NSDictionary*) _metadata
private

Definition at line 40 of file OOPListScript.h.

◆ _script

- (NSArray*) _script
private

Definition at line 39 of file OOPListScript.h.


The documentation for this class was generated from the following files: