39static NSString *
const kCacheName =
@"sanitized legacy scripts";
42@interface OOPListScript (SetUp)
44+ (NSArray *)scriptsFromDictionaryOfScripts:(NSDictionary *)dictionary filePath:(NSString *)filePath;
45+ (NSArray *) loadCachedScripts:(NSDictionary *)cachedScripts;
46- (id)initWithName:(NSString *)name scriptArray:(NSArray *)script metadata:(NSDictionary *)metadata;
53+ (NSArray *)scriptsInPListFile:(NSString *)filePath
56 if (cachedScripts !=
nil)
63 if (dict ==
nil)
return nil;
80 return [_metadata objectForKey:kMDKeyName];
84- (NSString *)scriptDescription
86 return [_metadata objectForKey:kMDKeyDescription];
92 return [_metadata objectForKey:kMDKeyVersion];
96- (BOOL) requiresTickle
102- (void)runWithTarget:(
Entity *)target
104 if (target !=
nil && ![target isKindOfClass:[
ShipEntity class]])
106 OOLog(
@"script.legacy.run.badTarget",
@"Expected ShipEntity or nil for target, got %@.", [target
class]);
110 OOLog(
@"script.legacy.run",
@"Running script %@", [
self displayName]);
113 [PLAYER runScriptActions:_script
114 withContextName:[
self name]
115 forTarget:(ShipEntity *)target];
123@implementation OOPListScript (SetUp)
125+ (NSArray *)scriptsFromDictionaryOfScripts:(NSDictionary *)dictionary filePath:(NSString *)filePath
127 NSMutableArray *result =
nil;
128 NSEnumerator *keyEnum =
nil;
130 NSArray *scriptArray =
nil;
131 NSDictionary *metadata =
nil;
132 NSMutableDictionary *cachedScripts =
nil;
135 NSUInteger
count = [dictionary count];
136 result = [NSMutableArray arrayWithCapacity:count];
137 cachedScripts = [NSMutableDictionary dictionaryWithCapacity:count];
139 metadata = [dictionary objectForKey:kKeyMetadata];
140 if (![metadata isKindOfClass:[NSDictionary
class]]) metadata =
nil;
142 for (keyEnum = [dictionary keyEnumerator]; (key = [keyEnum nextObject]); )
144 scriptArray = [dictionary objectForKey:key];
145 if ([key isKindOfClass:[NSString
class]] &&
146 [scriptArray isKindOfClass:[NSArray
class]] &&
150 if (scriptArray !=
nil)
152 script = [[
self alloc] initWithName:key scriptArray:scriptArray metadata:metadata];
155 [result addObject:script];
156 [cachedScripts setObject:[NSDictionary dictionaryWithObjectsAndKeys:scriptArray, kKeyScript, metadata, kKeyMetadata, nil] forKey:key];
166 return [[result copy] autorelease];
170+ (NSArray *) loadCachedScripts:(NSDictionary *)cachedScripts
172 NSEnumerator *keyEnum =
nil;
175 NSMutableArray *result = [NSMutableArray arrayWithCapacity:[cachedScripts count]];
177 for (keyEnum = [cachedScripts keyEnumerator]; (key = [keyEnum nextObject]); )
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];
185 [result addObject:script];
190 return [[result copy] autorelease];
194- (id)initWithName:(NSString *)name scriptArray:(NSArray *)script metadata:(NSDictionary *)metadata
199 _script = [script retain];
202 if (metadata ==
nil) metadata = [NSDictionary dictionaryWithObject:name forKey:kMDKeyName];
205 NSMutableDictionary *mutableMetadata = [[metadata mutableCopy] autorelease];
206 [mutableMetadata setObject:name forKey:kMDKeyName];
207 metadata = mutableMetadata;
210 _metadata = [metadata copy];
NSArray * OOSanitizeLegacyScript(NSArray *script, NSString *context, BOOL allowAIMethods)
#define OOLogOutdentIf(class)
#define OOLog(class, format,...)
#define OOLogIndentIf(class)
NSDictionary * OODictionaryFromFile(NSString *path)
static NSString *const kCacheName
static NSString *const kMDKeyDescription
static NSString *const kKeyMetadata
static NSString *const kKeyScript
static NSString *const kMDKeyVersion
static NSString *const kMDKeyName
void setObject:forKey:inCache:(id inElement,[forKey] NSString *inKey,[inCache] NSString *inCacheKey)
id objectForKey:inCache:(NSString *inKey,[inCache] NSString *inCacheKey)
OOCacheManager * sharedCache()
NSArray * scriptsFromDictionaryOfScripts:filePath:(NSDictionary *dictionary,[filePath] NSString *filePath)
NSArray * loadCachedScripts:(NSDictionary *cachedScripts)