Oolite
Loading...
Searching...
No Matches
OOScript Class Reference

#include <OOScript.h>

Inheritance diagram for OOScript:
Collaboration diagram for OOScript:

Instance Methods

(NSString *) - name
(NSString *) - scriptDescription
(NSString *) - version
(NSString *) - displayName
(BOOL) - requiresTickle
(void) - runWithTarget:
(NSString *) - descriptionComponents [implementation]
(BOOL) - callMethod:inContext:withArguments:count:result:
(BOOL) - callMethod:inContext:withArguments:count:result:

Class Methods

(NSArray *) + worldScriptsAtPath:
(NSArray *) + scriptsFromFileNamed:
(NSArray *) + scriptsFromList:
(NSArray *) + scriptsFromFileAtPath:
(id) + jsScriptFromFileNamed:properties:
(id) + jsAIScriptFromFileNamed:properties:

Detailed Description

Definition at line 40 of file OOScript.h.

Method Documentation

◆ callMethod:inContext:withArguments:count:result: [1/2]

- (BOOL) callMethod: (JSAtom) methodID
inContext: (JSContext*) context
withArguments: (JSValueConst*) argv
count: (int) argc
result: (JSValue*) outResult 

Reimplemented in OOJSScript.

Provided by category OOScript(JavaScriptEvents).

Definition at line 600 of file OOJSScript.m.

600 :(JSAtom)methodID
601 inContext:(JSContext*)context
602 withArguments:(JSValueConst*)argv
603 count:(int)argc
604 result:(JSValue*)outResult
605{
606 if (outResult != NULL)
607 *outResult = JS_UNDEFINED;
608 return NO;
609}
unsigned count
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque

◆ callMethod:inContext:withArguments:count:result: [2/2]

- (BOOL) callMethod: (jsid) methodID
inContext: (JSContext*) context
withArguments: (jsval*) argv
count: (intN) argc
result: (jsval*) outResult 

Reimplemented in OOJSScript.

Provided by category OOScript(JavaScriptEvents).

Definition at line 600 of file OOJSScript.m.

600 :(JSAtom)methodID
601 inContext:(JSContext*)context
602 withArguments:(JSValueConst*)argv
603 count:(int)argc
604 result:(JSValue*)outResult
605{
606 if (outResult != NULL)
607 *outResult = JS_UNDEFINED;
608 return NO;
609}

Referenced by PlayerEntity::doWorldEventUntilMissionScreen:, PlayerEntity::doWorldScriptEvent:inContext:withArguments:count:timeLimit:, and OOCommodities(OOPrivate)::modifyGood:withScript:atStation:inSystem:localMode:.

Here is the caller graph for this function:

◆ descriptionComponents

- (NSString *) descriptionComponents
implementation

Reimplemented in OOJSScript.

Definition at line 227 of file OOScript.m.

228{
229 return [NSString stringWithFormat:@"\"%@\" version %@", [self name], [self version]];
230}

References descriptionComponents, name, and version.

Referenced by descriptionComponents.

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

◆ displayName

- (NSString *) displayName

Reimplemented in OOJSScript.

Definition at line 250 of file OOScript.m.

251{
252 NSString* name = [self name];
253 NSString* version = [self version];
254
255 if (version != nil)
256 return [NSString stringWithFormat:@"%@ %@", name, version];
257 else if (name != nil)
258 return [NSString stringWithFormat:@"%@", name];
259 else
260 return nil;
261}
return nil
NSString * name()
Definition OOScript.m:232
NSString * version()
Definition OOScript.m:244

References displayName, name, nil, and version.

Referenced by displayName, ResourceManager::loadScripts, and OOPListScript::runWithTarget:.

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

◆ jsAIScriptFromFileNamed:properties:

+ (id) jsAIScriptFromFileNamed: (NSString*) fileName
properties: (NSDictionary*) properties 

Definition at line 202 of file OOScript.m.

202 :(NSString*)fileName properties:(NSDictionary*)properties
203{
204 NSString* extension = nil;
205 NSString* path = nil;
206
207 if ([fileName length] == 0)
208 return nil;
209
210 extension = [[fileName pathExtension] lowercaseString];
211 if ([extension isEqualToString:@"js"] || [extension isEqualToString:@"es"]) {
212 path = [ResourceManager pathForFileNamed:fileName inFolder:@"AIs"];
213 if (path == nil) {
214 OOLogERR(@"script.load.notFound", @"Could not find script file %@.", fileName);
215 return nil;
216 }
217 return [OOJSScript scriptWithPath:path properties:properties];
218 } else if ([extension isEqualToString:@"plist"]) {
219 OOLogERR(@"script.load.badName", @"Can't load script named %@ - legacy scripts are not supported in this context.", fileName);
220 return nil;
221 }
222
223 OOLogERR(@"script.load.badName", @"Don't know how to load a script from %@.", fileName);
224 return nil;
225}
#define OOLogERR(class, format,...)
Definition OOLogging.h:125
id scriptWithPath:properties:(NSString *path,[properties] NSDictionary *properties)
Definition OOJSScript.m:89
NSString * pathForFileNamed:inFolder:(NSString *fileName,[inFolder] NSString *folderName)

References nil, OOLogERR, ResourceManager::pathForFileNamed:inFolder:, and OOJSScript::scriptWithPath:properties:.

Referenced by ShipEntity(AI)::setAIScript:.

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

◆ jsScriptFromFileNamed:properties:

+ (id) jsScriptFromFileNamed: (NSString*) fileName
properties: (NSDictionary*) properties 

Definition at line 177 of file OOScript.m.

177 :(NSString*)fileName properties:(NSDictionary*)properties
178{
179 NSString* extension = nil;
180 NSString* path = nil;
181
182 if ([fileName length] == 0)
183 return nil;
184
185 extension = [[fileName pathExtension] lowercaseString];
186 if ([extension isEqualToString:@"js"] || [extension isEqualToString:@"es"]) {
187 path = [ResourceManager pathForFileNamed:fileName inFolder:@"Scripts"];
188 if (path == nil) {
189 OOLogERR(@"script.load.notFound", @"Could not find script file %@.", fileName);
190 return nil;
191 }
192 return [OOJSScript scriptWithPath:path properties:properties];
193 } else if ([extension isEqualToString:@"plist"]) {
194 OOLogERR(@"script.load.badName", @"Can't load script named %@ - legacy scripts are not supported in this context.", fileName);
195 return nil;
196 }
197
198 OOLogERR(@"script.load.badName", @"Don't know how to load a script from %@.", fileName);
199 return nil;
200}

References nil, OOLogERR, ResourceManager::pathForFileNamed:inFolder:, and OOJSScript::scriptWithPath:properties:.

Referenced by Universe::addConditionScripts:, PlayerEntity(Scripting)::addEqScriptForKey:, PlayerEntity::commodityScriptNamed:, OOJavaScriptEngine(Private)::createMainThreadContext, OOCharacter::setCharacterScript:, OOVisualEffectEntity::setScript:, ShipEntity::setShipScript:, PlayerEntity::setUpAndConfirmOK:saveGame:, and PlayerEntity::setUpShipFromDictionary:.

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

◆ name

- (NSString *) name

Reimplemented in OOJSScript, and OOPListScript.

Definition at line 232 of file OOScript.m.

233{
234 OOLogERR(kOOLogSubclassResponsibility, @"%@", @"OOScript should not be used directly!");
235 return nil;
236}
NSString *const kOOLogSubclassResponsibility
Definition OOLogging.m:595

References kOOLogSubclassResponsibility, name, nil, and OOLogERR.

Referenced by descriptionComponents, displayName, ResourceManager::loadScripts, name, and scriptsFromList:.

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

◆ requiresTickle

- (BOOL) requiresTickle

Reimplemented in OOPListScript.

Definition at line 263 of file OOScript.m.

264{
265 return NO;
266}

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

Reimplemented in OOJSScript, and OOPListScript.

Definition at line 268 of file OOScript.m.

268 :(Entity*)target
269{
270 OOLogERR(kOOLogSubclassResponsibility, @"%@", @"OOScript should not be used directly!");
271}

References kOOLogSubclassResponsibility, and OOLogERR.

◆ scriptDescription

- (NSString *) scriptDescription

Reimplemented in OOJSScript, and OOPListScript.

Definition at line 238 of file OOScript.m.

239{
240 OOLogERR(kOOLogSubclassResponsibility, @"%@", @"OOScript should not be used directly!");
241 return nil;
242}

References kOOLogSubclassResponsibility, nil, OOLogERR, and scriptDescription.

Referenced by scriptDescription.

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

◆ scriptsFromFileAtPath:

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

Definition at line 151 of file OOScript.m.

151 :(NSString*)filePath
152{
153 // oo_oxzFile always returns false for directories
154 if (![[NSFileManager defaultManager] oo_oxzFileExistsAtPath:filePath])
155 return nil;
156
157 NSString* extension = [[filePath pathExtension] lowercaseString];
158
159 if ([extension isEqualToString:@"js"] || [extension isEqualToString:@"es"]) {
160 NSArray* result = nil;
161 OOScript* script = [OOJSScript scriptWithPath:filePath properties:nil];
162 if (script != nil)
163 result = [NSArray arrayWithObject:script];
164 return result;
165 } else if ([extension isEqualToString:@"plist"]) {
166 OOStandardsDeprecated([NSString stringWithFormat:@"Legacy script %@ is deprecated", filePath]);
167 if (OOEnforceStandards()) {
168 return nil;
169 }
170 return [OOPListScript scriptsInPListFile:filePath];
171 }
172
173 OOLogERR(@"script.load.badName", @"Don't know how to load a script from %@.", filePath);
174 return nil;
175}
void OOStandardsDeprecated(NSString *message)
BOOL OOEnforceStandards(void)
NSArray * scriptsInPListFile:(NSString *filePath)

References nil, OOEnforceStandards(), OOLogERR, OOStandardsDeprecated(), OOPListScript::scriptsInPListFile:, and OOJSScript::scriptWithPath:properties:.

Referenced by scriptsFromFileNamed:.

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

◆ scriptsFromFileNamed:

+ (NSArray *) scriptsFromFileNamed: (NSString*) fileName

Definition at line 119 of file OOScript.m.

119 :(NSString*)fileName
120{
121 NSArray* result = nil;
122 NSString* path = [ResourceManager pathForFileNamed:fileName inFolder:@"Scripts"];
123 if (path != nil) {
124 result = [self scriptsFromFileAtPath:path];
125 }
126
127 if (result == nil) {
128 OOLogERR(@"script.load.notFound", @"Could not find script file %@.", fileName);
129 }
130
131 return result;
132}

References nil, OOLogERR, ResourceManager::pathForFileNamed:inFolder:, and scriptsFromFileAtPath:.

Referenced by scriptsFromList:.

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

◆ scriptsFromList:

+ (NSArray *) scriptsFromList: (NSArray*) fileNames

Definition at line 134 of file OOScript.m.

134 :(NSArray*)fileNames
135{
136 NSString* name = nil;
137 NSMutableArray* result = nil;
138 NSArray* scripts = nil;
139
140 result = [NSMutableArray arrayWithCapacity:[fileNames count]];
141
142 foreach (name, fileNames) {
143 scripts = [self scriptsFromFileNamed:name];
144 if (scripts != nil)
145 [result addObjectsFromArray:scripts];
146 }
147
148 return result;
149}

References name, nil, and scriptsFromFileNamed:.

Referenced by worldScriptsAtPath:.

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

◆ version

- (NSString *) version

Reimplemented in OOJSScript, and OOPListScript.

Definition at line 244 of file OOScript.m.

245{
246 OOLogERR(kOOLogSubclassResponsibility, @"%@", @"OOScript should not be used directly!");
247 return nil;
248}

References kOOLogSubclassResponsibility, nil, OOLogERR, and version.

Referenced by descriptionComponents, displayName, and version.

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

◆ worldScriptsAtPath:

+ (NSArray *) worldScriptsAtPath: (NSString*) path

Definition at line 45 of file OOScript.m.

45 :(NSString*)path
46{
47 NSFileManager* fmgr = nil;
48 NSString* filePath = nil;
49 NSArray* names = nil;
50 NSArray* result = nil;
51 id script = nil;
52 BOOL foundScript = NO;
53
54 fmgr = [NSFileManager defaultManager];
55
56 // First, look for world-scripts.plist.
57 filePath = [path stringByAppendingPathComponent:@"world-scripts.plist"];
58 if (filePath != nil) {
59 names = OOArrayFromFile(filePath);
60 if (names != nil) {
61 foundScript = YES;
62 result = [self scriptsFromList:names];
63 }
64 }
65
66 // Second, try to load a JavaScript.
67 if (result == nil) {
68 filePath = [path stringByAppendingPathComponent:@"script.js"];
69 if ([fmgr oo_oxzFileExistsAtPath:filePath])
70 foundScript = YES;
71 else {
72 filePath = [path stringByAppendingPathComponent:@"script.es"];
73 if ([fmgr oo_oxzFileExistsAtPath:filePath])
74 foundScript = YES;
75 }
76 if (foundScript) {
77 OOLog(kOOLogLoadScriptJavaScript, @"Trying to load JavaScript script %@", filePath);
79
80 script = [OOJSScript scriptWithPath:filePath properties:nil];
81 if (script != nil) {
82 result = [NSArray arrayWithObject:script];
83 OOLog(kOOLogLoadScriptOK, @"Successfully loaded JavaScript script %@", filePath);
84 } else
85 OOLogERR(kOOLogLoadScriptParseError, @"Failed to load JavaScript script %@", filePath);
86
88 }
89 }
90
91 // Third, try to load a plist script.
92 if (result == nil) {
93 filePath = [path stringByAppendingPathComponent:@"script.plist"];
94 if ([fmgr oo_oxzFileExistsAtPath:filePath]) {
95 OOStandardsDeprecated([NSString stringWithFormat:@"Legacy script %@ is deprecated", filePath]);
96 if (!OOEnforceStandards()) {
97 foundScript = YES;
98 OOLog(kOOLogLoadScriptPList, @"Trying to load property list script %@", filePath);
100
101 result = [OOPListScript scriptsInPListFile:filePath];
102 if (result != nil)
103 OOLog(kOOLogLoadScriptOK, @"Successfully loaded property list script %@", filePath);
104 else
105 OOLogERR(kOOLogLoadScriptParseError, @"Failed to load property list script %@", filePath);
106
108 }
109 }
110 }
111
112 if (result == nil && foundScript) {
113 OOLog(kOOLogLoadScriptNone, @"No script could be loaded from %@", path);
114 }
115
116 return result;
117}
#define OOLogOutdentIf(class)
Definition OOLogging.h:112
#define OOLog(class, format,...)
Definition OOLogging.h:84
#define OOLogIndentIf(class)
Definition OOLogging.h:107
NSArray * OOArrayFromFile(NSString *path)
static NSString *const kOOLogLoadScriptPList
Definition OOScript.m:38
static NSString *const kOOLogLoadScriptNone
Definition OOScript.m:41
static NSString *const kOOLogLoadScriptOK
Definition OOScript.m:39
static NSString *const kOOLogLoadScriptParseError
Definition OOScript.m:40
static NSString *const kOOLogLoadScriptJavaScript
Definition OOScript.m:37

References kOOLogLoadScriptJavaScript, kOOLogLoadScriptNone, kOOLogLoadScriptOK, kOOLogLoadScriptParseError, kOOLogLoadScriptPList, nil, OOArrayFromFile(), OOEnforceStandards(), OOLog, OOLogERR, OOLogIndentIf, OOLogOutdentIf, OOStandardsDeprecated(), scriptsFromList:, OOPListScript::scriptsInPListFile:, and OOJSScript::scriptWithPath:properties:.

Referenced by ResourceManager::loadScripts.

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

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