Oolite 1.91.0.7644-241112-7f5034b
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:
 

Class Methods

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

Detailed Description

Definition at line 41 of file OOScript.h.

Method Documentation

◆ callMethod:inContext:withArguments:count:result:

- (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 55 of file OOJSScript.m.

652 :(jsid)methodID
653 inContext:(JSContext *)context
654 withArguments:(jsval *)argv count:(intN)argc
655 result:(jsval *)outResult
656{
657 return NO;
658}
unsigned count

◆ descriptionComponents

- (NSString *) descriptionComponents
implementation

Reimplemented in OOJSScript.

Definition at line 40 of file OOScript.m.

251{
252 return [NSString stringWithFormat:@"\"%@\" version %@", [self name], [self version]];
253}

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

+ Here is the call graph for this function:

◆ displayName

- (NSString *) displayName

Definition at line 40 of file OOScript.m.

278{
279 NSString *name = [self name];
280 NSString *version = [self version];
281
282 if (version != nil) return [NSString stringWithFormat:@"%@ %@", name, version];
283 else if (name != nil) return [NSString stringWithFormat:@"%@", name];
284 else return nil;
285}
return nil
NSString * name()
Definition OOScript.m:256
NSString * version()
Definition OOScript.m:270

◆ jsAIScriptFromFileNamed:properties:

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

Definition at line 40 of file OOScript.m.

221 :(NSString *)fileName properties:(NSDictionary *)properties
222{
223 NSString *extension = nil;
224 NSString *path = nil;
225
226 if ([fileName length] == 0) return nil;
227
228 extension = [[fileName pathExtension] lowercaseString];
229 if ([extension isEqualToString:@"js"] || [extension isEqualToString:@"es"])
230 {
231 path = [ResourceManager pathForFileNamed:fileName inFolder:@"AIs"];
232 if (path == nil)
233 {
234 OOLogERR(@"script.load.notFound", @"Could not find script file %@.", fileName);
235 return nil;
236 }
237 return [OOJSScript scriptWithPath:path properties:properties];
238 }
239 else if ([extension isEqualToString:@"plist"])
240 {
241 OOLogERR(@"script.load.badName", @"Can't load script named %@ - legacy scripts are not supported in this context.", fileName);
242 return nil;
243 }
244
245 OOLogERR(@"script.load.badName", @"Don't know how to load a script from %@.", fileName);
246 return nil;
247}
#define OOLogERR(class, format,...)
Definition OOLogging.h:112
id scriptWithPath:properties:(NSString *path,[properties] NSDictionary *properties)
Definition OOJSScript.m:112
NSString * pathForFileNamed:inFolder:(NSString *fileName,[inFolder] NSString *folderName)

◆ jsScriptFromFileNamed:properties:

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

Definition at line 40 of file OOScript.m.

192 :(NSString *)fileName properties:(NSDictionary *)properties
193{
194 NSString *extension = nil;
195 NSString *path = nil;
196
197 if ([fileName length] == 0) return nil;
198
199 extension = [[fileName pathExtension] lowercaseString];
200 if ([extension isEqualToString:@"js"] || [extension isEqualToString:@"es"])
201 {
202 path = [ResourceManager pathForFileNamed:fileName inFolder:@"Scripts"];
203 if (path == nil)
204 {
205 OOLogERR(@"script.load.notFound", @"Could not find script file %@.", fileName);
206 return nil;
207 }
208 return [OOJSScript scriptWithPath:path properties:properties];
209 }
210 else if ([extension isEqualToString:@"plist"])
211 {
212 OOLogERR(@"script.load.badName", @"Can't load script named %@ - legacy scripts are not supported in this context.", fileName);
213 return nil;
214 }
215
216 OOLogERR(@"script.load.badName", @"Don't know how to load a script from %@.", fileName);
217 return nil;
218}

◆ name

- (NSString *) name

Reimplemented in OOPListScript.

Definition at line 40 of file OOScript.m.

257{
258 OOLogERR(kOOLogSubclassResponsibility, @"%@", @"OOScript should not be used directly!");
259 return nil;
260}
NSString *const kOOLogSubclassResponsibility
Definition OOLogging.m:646

◆ requiresTickle

- (BOOL) requiresTickle

Reimplemented in OOPListScript.

Definition at line 40 of file OOScript.m.

289{
290 return NO;
291}

◆ runWithTarget:

- (void) runWithTarget: (Entity *) target

Reimplemented in OOJSScript, and OOPListScript.

Definition at line 40 of file OOScript.m.

294 :(Entity *)target
295{
296 OOLogERR(kOOLogSubclassResponsibility, @"%@", @"OOScript should not be used directly!");
297}

◆ scriptDescription

- (NSString *) scriptDescription

Reimplemented in OOJSScript, and OOPListScript.

Definition at line 40 of file OOScript.m.

264{
265 OOLogERR(kOOLogSubclassResponsibility, @"%@", @"OOScript should not be used directly!");
266 return nil;
267}

◆ scriptsFromFileAtPath:

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

Definition at line 40 of file OOScript.m.

163 :(NSString *)filePath
164{
165 // oo_oxzFile always returns false for directories
166 if (![[NSFileManager defaultManager] oo_oxzFileExistsAtPath:filePath]) return nil;
167
168 NSString *extension = [[filePath pathExtension] lowercaseString];
169
170 if ([extension isEqualToString:@"js"] || [extension isEqualToString:@"es"])
171 {
172 NSArray *result = nil;
173 OOScript *script = [OOJSScript scriptWithPath:filePath properties:nil];
174 if (script != nil) result = [NSArray arrayWithObject:script];
175 return result;
176 }
177 else if ([extension isEqualToString:@"plist"])
178 {
179 OOStandardsDeprecated([NSString stringWithFormat:@"Legacy script %@ is deprecated",filePath]);
180 if (OOEnforceStandards())
181 {
182 return nil;
183 }
184 return [OOPListScript scriptsInPListFile:filePath];
185 }
186
187 OOLogERR(@"script.load.badName", @"Don't know how to load a script from %@.", filePath);
188 return nil;
189}
void OOStandardsDeprecated(NSString *message)
BOOL OOEnforceStandards(void)
NSArray * scriptsInPListFile:(NSString *filePath)

◆ scriptsFromFileNamed:

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

Definition at line 40 of file OOScript.m.

126 :(NSString *)fileName
127{
128 NSArray *result = nil;
129 NSString *path = [ResourceManager pathForFileNamed:fileName inFolder:@"Scripts"];
130 if (path != nil)
131 {
132 result = [self scriptsFromFileAtPath:path];
133 }
134
135 if (result == nil)
136 {
137 OOLogERR(@"script.load.notFound", @"Could not find script file %@.", fileName);
138 }
139
140 return result;
141}

◆ scriptsFromList:

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

Definition at line 40 of file OOScript.m.

144 :(NSArray *)fileNames
145{
146 NSEnumerator *nameEnum = nil;
147 NSString *name = nil;
148 NSMutableArray *result = nil;
149 NSArray *scripts = nil;
150
151 result = [NSMutableArray arrayWithCapacity:[fileNames count]];
152
153 for (nameEnum = [fileNames objectEnumerator]; (name = [nameEnum nextObject]); )
154 {
155 scripts = [self scriptsFromFileNamed:name];
156 if (scripts != nil) [result addObjectsFromArray:scripts];
157 }
158
159 return result;
160}

Referenced by descriptionComponents.

+ Here is the caller graph for this function:

◆ version

- (NSString *) version

Reimplemented in OOPListScript.

Definition at line 40 of file OOScript.m.

271{
272 OOLogERR(kOOLogSubclassResponsibility, @"%@", @"OOScript should not be used directly!");
273 return nil;
274}

◆ worldScriptsAtPath:

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

Definition at line 40 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 {
60 names = OOArrayFromFile(filePath);
61 if (names != nil)
62 {
63 foundScript = YES;
64 result = [self scriptsFromList:names];
65 }
66 }
67
68 // Second, try to load a JavaScript.
69 if (result == nil)
70 {
71 filePath = [path stringByAppendingPathComponent:@"script.js"];
72 if ([fmgr oo_oxzFileExistsAtPath:filePath]) foundScript = YES;
73 else
74 {
75 filePath = [path stringByAppendingPathComponent:@"script.es"];
76 if ([fmgr oo_oxzFileExistsAtPath:filePath]) foundScript = YES;
77 }
78 if (foundScript)
79 {
80 OOLog(kOOLogLoadScriptJavaScript, @"Trying to load JavaScript script %@", filePath);
82
83 script = [OOJSScript scriptWithPath:filePath properties:nil];
84 if (script != nil)
85 {
86 result = [NSArray arrayWithObject:script];
87 OOLog(kOOLogLoadScriptOK, @"Successfully loaded JavaScript script %@", filePath);
88 }
89 else OOLogERR(kOOLogLoadScriptParseError, @"Failed to load JavaScript script %@", filePath);
90
92 }
93 }
94
95 // Third, try to load a plist script.
96 if (result == nil)
97 {
98 filePath = [path stringByAppendingPathComponent:@"script.plist"];
99 if ([fmgr oo_oxzFileExistsAtPath:filePath])
100 {
101 OOStandardsDeprecated([NSString stringWithFormat:@"Legacy script %@ is deprecated",filePath]);
102 if (!OOEnforceStandards())
103 {
104 foundScript = YES;
105 OOLog(kOOLogLoadScriptPList, @"Trying to load property list script %@", filePath);
107
108 result = [OOPListScript scriptsInPListFile:filePath];
109 if (result != nil) OOLog(kOOLogLoadScriptOK, @"Successfully loaded property list script %@", filePath);
110 else OOLogERR(kOOLogLoadScriptParseError, @"Failed to load property list script %@", filePath);
111
113 }
114 }
115 }
116
117 if (result == nil && foundScript)
118 {
119 OOLog(kOOLogLoadScriptNone, @"No script could be loaded from %@", path);
120 }
121
122 return result;
123}
#define OOLogOutdentIf(class)
Definition OOLogging.h:102
#define OOLog(class, format,...)
Definition OOLogging.h:88
#define OOLogIndentIf(class)
Definition OOLogging.h:101
NSArray * OOArrayFromFile(NSString *path)
static NSString *const kOOLogLoadScriptPList
Definition OOScript.m:37
static NSString *const kOOLogLoadScriptNone
Definition OOScript.m:40
static NSString *const kOOLogLoadScriptOK
Definition OOScript.m:38
static NSString *const kOOLogLoadScriptParseError
Definition OOScript.m:39
static NSString *const kOOLogLoadScriptJavaScript
Definition OOScript.m:36

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