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;
129 NSArray *scriptArray =
nil;
130 NSDictionary *metadata =
nil;
131 NSMutableDictionary *cachedScripts =
nil;
134 NSUInteger
count = [dictionary count];
135 result = [NSMutableArray arrayWithCapacity:count];
136 cachedScripts = [NSMutableDictionary dictionaryWithCapacity:count];
138 metadata = [dictionary objectForKey:kKeyMetadata];
139 if (![metadata isKindOfClass:[NSDictionary class]]) metadata =
nil;
143 scriptArray = [dictionary objectForKey:key];
144 if ([key isKindOfClass:[NSString class]] &&
145 [scriptArray isKindOfClass:[NSArray class]] &&
149 if (scriptArray !=
nil)
151 script = [[
self alloc] initWithName:key scriptArray:scriptArray metadata:metadata];
154 [result addObject:script];
155 [cachedScripts setObject:[NSDictionary dictionaryWithObjectsAndKeys:scriptArray, kKeyScript, metadata, kKeyMetadata, nil] forKey:key];
165 return [[result copy] autorelease];
169+ (NSArray *) loadCachedScripts:(NSDictionary *)cachedScripts
173 NSMutableArray *result = [NSMutableArray arrayWithCapacity:[cachedScripts count]];
177 NSDictionary *cacheValue = [cachedScripts oo_dictionaryForKey:key];
178 NSArray *scriptArray = [cacheValue oo_arrayForKey:kKeyScript];
179 NSDictionary *metadata = [cacheValue oo_dictionaryForKey:kKeyMetadata];
180 OOPListScript *script = [[
self alloc] initWithName:key scriptArray:scriptArray metadata:metadata];
183 [result addObject:script];
188 return [[result copy] autorelease];
192- (id)initWithName:(NSString *)name scriptArray:(NSArray *)script metadata:(NSDictionary *)metadata
197 _script = [script retain];
200 if (metadata ==
nil) metadata = [NSDictionary dictionaryWithObject:name forKey:kMDKeyName];
203 NSMutableDictionary *mutableMetadata = [[metadata mutableCopy] autorelease];
204 [mutableMetadata setObject:name forKey:kMDKeyName];
205 metadata = mutableMetadata;
208 _metadata = [metadata copy];
#define foreachkey(VAR, DICT)
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 * loadCachedScripts:(NSDictionary *cachedScripts)
NSArray * scriptsFromDictionaryOfScripts:filePath:(NSDictionary *dictionary,[filePath] NSString *filePath)