Oolite
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:
(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 35 of file OOPListScript.h.

Method Documentation

◆ dealloc

- (void) dealloc
implementation

Definition at line 63 of file OOPListScript.m.

64{
65 [_script release];
66 [_metadata release];
67
68 [super dealloc];
69}

References dealloc.

Referenced by dealloc.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ initWithName:scriptArray:metadata:

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

Provided by category OOPListScript(SetUp).

Definition at line 173 of file OOPListScript.m.

173 :(NSString*)name scriptArray:(NSArray*)script metadata:(NSDictionary*)metadata
174{
175 self = [super init];
176 if (self != nil) {
177 _script = [script retain];
178 if (name != nil) {
179 if (metadata == nil)
180 metadata = [NSDictionary dictionaryWithObject:name forKey:kMDKeyName];
181 else {
182 NSMutableDictionary* mutableMetadata = [[metadata mutableCopy] autorelease];
183 [mutableMetadata setObject:name forKey:kMDKeyName];
184 metadata = mutableMetadata;
185 }
186 }
187 _metadata = [metadata copy];
188 }
189
190 return self;
191}
return nil
NSDictionary * _metadata
NSString * name()
NSArray * _script

◆ loadCachedScripts:

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

Provided by category OOPListScript(SetUp).

Definition at line 152 of file OOPListScript.m.

152 :(NSDictionary*)cachedScripts
153{
154 NSString* key = nil;
155
156 NSMutableArray* result = [NSMutableArray arrayWithCapacity:[cachedScripts count]];
157
158 foreachkey(key, cachedScripts)
159 {
160 NSDictionary* cacheValue = [cachedScripts oo_dictionaryForKey:key];
161 NSArray* scriptArray = [cacheValue oo_arrayForKey:kKeyScript];
162 NSDictionary* metadata = [cacheValue oo_dictionaryForKey:kKeyMetadata];
163 OOPListScript* script = [[self alloc] initWithName:key scriptArray:scriptArray metadata:metadata];
164 if (script != nil) {
165 [result addObject:script];
166 [script release];
167 }
168 }
169
170 return [[result copy] autorelease];
171}
#define foreachkey(VAR, DICT)

Referenced by scriptsInPListFile:.

Here is the caller graph for this function:

◆ name

- (NSString *) name
implementation

Reimplemented from OOScript.

Definition at line 71 of file OOPListScript.m.

72{
73 return [_metadata objectForKey:kMDKeyName];
74}

References name.

Referenced by name, and runWithTarget:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ requiresTickle

- (BOOL) requiresTickle
implementation

Reimplemented from OOScript.

Definition at line 86 of file OOPListScript.m.

87{
88 return YES;
89}

References requiresTickle.

Referenced by requiresTickle.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ runWithTarget:

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

Reimplemented from OOScript.

Definition at line 91 of file OOPListScript.m.

91 :(Entity*)target
92{
93 if (target != nil && ![target isKindOfClass:[ShipEntity class]]) {
94 OOLog(@"script.legacy.run.badTarget", @"Expected ShipEntity or nil for target, got %@.", [target class]);
95 return;
96 }
97
98 OOLog(@"script.legacy.run", @"Running script %@", [self displayName]);
99 OOLogIndentIf(@"script.legacy.run");
100
101 [PLAYER runScriptActions:_script
102 withContextName:[self name]
103 forTarget:(ShipEntity*)target];
104
105 OOLogOutdentIf(@"script.legacy.run");
106}
#define OOLogOutdentIf(class)
Definition OOLogging.h:112
#define OOLog(class, format,...)
Definition OOLogging.h:84
#define OOLogIndentIf(class)
Definition OOLogging.h:107
NSString * displayName()
Definition OOScript.m:250

References OOScript::displayName, name, nil, OOLog, OOLogIndentIf, and OOLogOutdentIf.

Here is the call graph for this function:

◆ scriptDescription

- (NSString *) scriptDescription
implementation

Reimplemented from OOScript.

Definition at line 76 of file OOPListScript.m.

77{
78 return [_metadata objectForKey:kMDKeyDescription];
79}

References scriptDescription.

Referenced by scriptDescription.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ scriptsFromDictionaryOfScripts:filePath:

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

Provided by category OOPListScript(SetUp).

Definition at line 112 of file OOPListScript.m.

112 :(NSDictionary*)dictionary filePath:(NSString*)filePath
113{
114 NSMutableArray* result = nil;
115 NSString* key = nil;
116 NSArray* scriptArray = nil;
117 NSDictionary* metadata = nil;
118 NSMutableDictionary* cachedScripts = nil;
119 OOPListScript* script = nil;
120
121 NSUInteger count = [dictionary count];
122 result = [NSMutableArray arrayWithCapacity:count];
123 cachedScripts = [NSMutableDictionary dictionaryWithCapacity:count];
124
125 metadata = [dictionary objectForKey:kKeyMetadata];
126 if (![metadata isKindOfClass:[NSDictionary class]])
127 metadata = nil;
128
129 foreachkey(key, dictionary)
130 {
131 scriptArray = [dictionary objectForKey:key];
132 if ([key isKindOfClass:[NSString class]] &&
133 [scriptArray isKindOfClass:[NSArray class]] && ![key isEqual:kKeyMetadata]) {
134 scriptArray = OOSanitizeLegacyScript(scriptArray, key, NO);
135 if (scriptArray != nil) {
136 script = [[self alloc] initWithName:key scriptArray:scriptArray metadata:metadata];
137 if (script != nil) {
138 [result addObject:script];
139 [cachedScripts setObject:[NSDictionary dictionaryWithObjectsAndKeys:scriptArray, kKeyScript, metadata, kKeyMetadata, nil] forKey:key];
140
141 [script release];
142 }
143 }
144 }
145 }
146
147 [[OOCacheManager sharedCache] setObject:cachedScripts forKey:filePath inCache:kCacheName];
148
149 return [[result copy] autorelease];
150}
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()

Referenced by scriptsInPListFile:.

Here is the caller graph for this function:

◆ scriptsInPListFile:

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

Definition at line 50 of file OOPListScript.m.

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

References loadCachedScripts:, nil, OOCacheManager::objectForKey:inCache:, OODictionaryFromFile(), scriptsFromDictionaryOfScripts:filePath:, and OOCacheManager::sharedCache.

Referenced by OOScript::scriptsFromFileAtPath:, and OOScript::worldScriptsAtPath:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ version

- (NSString *) version
implementation

Reimplemented from OOScript.

Definition at line 81 of file OOPListScript.m.

82{
83 return [_metadata objectForKey:kMDKeyVersion];
84}

References version.

Referenced by version.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ _metadata

- (NSDictionary*) _metadata
private

Definition at line 38 of file OOPListScript.h.

◆ _script

- (NSArray*) _script
private

Definition at line 37 of file OOPListScript.h.


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