Line data Source code
1 0 : /*
2 :
3 : OOJSEquipmentInfo.m
4 :
5 :
6 : Oolite
7 : Copyright (C) 2004-2013 Giles C Williams and contributors
8 :
9 : This program is free software; you can redistribute it and/or
10 : modify it under the terms of the GNU General Public License
11 : as published by the Free Software Foundation; either version 2
12 : of the License, or (at your option) any later version.
13 :
14 : This program is distributed in the hope that it will be useful,
15 : but WITHOUT ANY WARRANTY; without even the implied warranty of
16 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 : GNU General Public License for more details.
18 :
19 : You should have received a copy of the GNU General Public License
20 : along with this program; if not, write to the Free Software
21 : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
22 : MA 02110-1301, USA.
23 :
24 : */
25 :
26 : #import "OOJSEquipmentInfo.h"
27 : #import "OOJavaScriptEngine.h"
28 : #import "OOEquipmentType.h"
29 : #import "OOJSPlayer.h"
30 : #import "OODebugStandards.h"
31 :
32 0 : static JSObject *sEquipmentInfoPrototype;
33 :
34 :
35 : static JSBool EquipmentInfoGetProperty(JSContext *context, JSObject *this, jsid propID, jsval *value);
36 : static JSBool EquipmentInfoSetProperty(JSContext *context, JSObject *this, jsid propID, JSBool strict, jsval *value);
37 :
38 : static JSBool EquipmentInfoGetAllEqipment(JSContext *context, JSObject *this, jsid propID, jsval *value);
39 :
40 :
41 : // Methods
42 : static JSBool EquipmentInfoStaticInfoForKey(JSContext *context, uintN argc, jsval *vp);
43 :
44 :
45 0 : enum
46 : {
47 : // Property IDs
48 : kEquipmentInfo_calculatedPrice,
49 : kEquipmentInfo_canBeDamaged,
50 : kEquipmentInfo_canCarryMultiple,
51 : kEquipmentInfo_damageProbability,
52 : kEquipmentInfo_description,
53 : kEquipmentInfo_displayColor,
54 : kEquipmentInfo_effectiveTechLevel,
55 : kEquipmentInfo_equipmentKey,
56 : kEquipmentInfo_fastAffinityDefensive,
57 : kEquipmentInfo_fastAffinityOffensive,
58 : kEquipmentInfo_defaultActivateKey,
59 : kEquipmentInfo_defaultModeKey,
60 : kEquipmentInfo_incompatibleEquipment,
61 : kEquipmentInfo_installationTime,
62 : kEquipmentInfo_isAvailableToAll,
63 : kEquipmentInfo_isAvailableToNPCs,
64 : kEquipmentInfo_isAvailableToPlayer,
65 : kEquipmentInfo_isExternalStore, // is missile or mine
66 : kEquipmentInfo_isPortableBetweenShips,
67 : kEquipmentInfo_isVisible,
68 : kEquipmentInfo_name,
69 : kEquipmentInfo_price,
70 : kEquipmentInfo_provides,
71 : kEquipmentInfo_repairTime,
72 : kEquipmentInfo_requiredCargoSpace,
73 : kEquipmentInfo_requiresAnyEquipment,
74 : kEquipmentInfo_requiresCleanLegalRecord,
75 : kEquipmentInfo_requiresEmptyPylon,
76 : kEquipmentInfo_requiresEquipment,
77 : kEquipmentInfo_requiresFreePassengerBerth,
78 : kEquipmentInfo_requiresFullFuel,
79 : kEquipmentInfo_requiresMountedPylon,
80 : kEquipmentInfo_requiresNonCleanLegalRecord,
81 : kEquipmentInfo_requiresNonFullFuel,
82 : kEquipmentInfo_scriptInfo, // arbitrary data for scripts, dictionary, read-only
83 : kEquipmentInfo_scriptName,
84 : kEquipmentInfo_techLevel,
85 : kEquipmentInfo_weaponInfo
86 : };
87 :
88 :
89 0 : static JSPropertySpec sEquipmentInfoProperties[] =
90 : {
91 : // JS name ID flags
92 : { "calculatedPrice", kEquipmentInfo_calculatedPrice, OOJS_PROP_READONLY_CB },
93 : { "canBeDamaged", kEquipmentInfo_canBeDamaged, OOJS_PROP_READONLY_CB },
94 : { "canCarryMultiple", kEquipmentInfo_canCarryMultiple, OOJS_PROP_READONLY_CB },
95 : { "damageProbability", kEquipmentInfo_damageProbability, OOJS_PROP_READONLY_CB },
96 : { "description", kEquipmentInfo_description, OOJS_PROP_READONLY_CB },
97 : { "displayColor", kEquipmentInfo_displayColor, OOJS_PROP_READWRITE_CB },
98 : { "effectiveTechLevel", kEquipmentInfo_effectiveTechLevel, OOJS_PROP_READWRITE_CB },
99 : { "equipmentKey", kEquipmentInfo_equipmentKey, OOJS_PROP_READONLY_CB },
100 : { "fastAffinityDefensive", kEquipmentInfo_fastAffinityDefensive, OOJS_PROP_READONLY_CB },
101 : { "fastAffinityOffensive", kEquipmentInfo_fastAffinityOffensive, OOJS_PROP_READONLY_CB },
102 : { "defaultActivateKey", kEquipmentInfo_defaultActivateKey, OOJS_PROP_READONLY_CB },
103 : { "defaultModeKey", kEquipmentInfo_defaultModeKey, OOJS_PROP_READONLY_CB },
104 : { "incompatibleEquipment", kEquipmentInfo_incompatibleEquipment, OOJS_PROP_READONLY_CB },
105 : { "installationTime", kEquipmentInfo_installationTime, OOJS_PROP_READONLY_CB },
106 : { "isAvailableToAll", kEquipmentInfo_isAvailableToAll, OOJS_PROP_READONLY_CB },
107 : { "isAvailableToNPCs", kEquipmentInfo_isAvailableToNPCs, OOJS_PROP_READONLY_CB },
108 : { "isAvailableToPlayer", kEquipmentInfo_isAvailableToPlayer, OOJS_PROP_READONLY_CB },
109 : { "isExternalStore", kEquipmentInfo_isExternalStore, OOJS_PROP_READONLY_CB },
110 : { "isPortableBetweenShips", kEquipmentInfo_isPortableBetweenShips, OOJS_PROP_READONLY_CB },
111 : { "isVisible", kEquipmentInfo_isVisible, OOJS_PROP_READONLY_CB },
112 : { "name", kEquipmentInfo_name, OOJS_PROP_READONLY_CB },
113 : { "price", kEquipmentInfo_price, OOJS_PROP_READONLY_CB },
114 : { "provides", kEquipmentInfo_provides, OOJS_PROP_READONLY_CB },
115 : { "repairTime", kEquipmentInfo_repairTime, OOJS_PROP_READONLY_CB },
116 : { "requiredCargoSpace", kEquipmentInfo_requiredCargoSpace, OOJS_PROP_READONLY_CB },
117 : { "requiresAnyEquipment", kEquipmentInfo_requiresAnyEquipment, OOJS_PROP_READONLY_CB },
118 : { "requiresCleanLegalRecord", kEquipmentInfo_requiresCleanLegalRecord, OOJS_PROP_READONLY_CB },
119 : { "requiresEmptyPylon", kEquipmentInfo_requiresEmptyPylon, OOJS_PROP_READONLY_CB },
120 : { "requiresEquipment", kEquipmentInfo_requiresEquipment, OOJS_PROP_READONLY_CB },
121 : { "requiresFreePassengerBerth", kEquipmentInfo_requiresFreePassengerBerth, OOJS_PROP_READONLY_CB },
122 : { "requiresFullFuel", kEquipmentInfo_requiresFullFuel, OOJS_PROP_READONLY_CB },
123 : { "requiresMountedPylon", kEquipmentInfo_requiresMountedPylon, OOJS_PROP_READONLY_CB },
124 : { "requiresNonCleanLegalRecord", kEquipmentInfo_requiresNonCleanLegalRecord, OOJS_PROP_READONLY_CB },
125 : { "requiresNonFullFuel", kEquipmentInfo_requiresNonFullFuel, OOJS_PROP_READONLY_CB },
126 : { "scriptInfo", kEquipmentInfo_scriptInfo, OOJS_PROP_READONLY_CB },
127 : { "scriptName", kEquipmentInfo_scriptName, OOJS_PROP_READONLY_CB },
128 : { "techLevel", kEquipmentInfo_techLevel, OOJS_PROP_READONLY_CB },
129 : { "weaponInfo", kEquipmentInfo_weaponInfo, OOJS_PROP_READONLY_CB },
130 : { 0 }
131 : };
132 :
133 :
134 0 : static JSPropertySpec sEquipmentInfoStaticProperties[] =
135 : {
136 : { "allEquipment", 0, OOJS_PROP_READONLY_CB, EquipmentInfoGetAllEqipment },
137 : { 0 }
138 : };
139 :
140 :
141 0 : static JSFunctionSpec sEquipmentInfoMethods[] =
142 : {
143 : // JS name Function min args
144 : { "toString", OOJSObjectWrapperToString, 0 },
145 : { 0 }
146 : };
147 :
148 :
149 0 : static JSFunctionSpec sEquipmentInfoStaticMethods[] =
150 : {
151 : // JS name Function min args
152 : { "infoForKey", EquipmentInfoStaticInfoForKey, 0 },
153 : { 0 }
154 : };
155 :
156 :
157 0 : static JSClass sEquipmentInfoClass =
158 : {
159 : "EquipmentInfo",
160 : JSCLASS_HAS_PRIVATE,
161 :
162 : JS_PropertyStub, // addProperty
163 : JS_PropertyStub, // delProperty
164 : EquipmentInfoGetProperty, // getProperty
165 : EquipmentInfoSetProperty, // setProperty
166 : JS_EnumerateStub, // enumerate
167 : JS_ResolveStub, // resolve
168 : JS_ConvertStub, // convert
169 : OOJSObjectWrapperFinalize, // finalize
170 : JSCLASS_NO_OPTIONAL_MEMBERS
171 : };
172 :
173 :
174 0 : DEFINE_JS_OBJECT_GETTER(JSEquipmentInfoGetEquipmentType, &sEquipmentInfoClass, sEquipmentInfoPrototype, OOEquipmentType);
175 :
176 :
177 : // *** Public ***
178 :
179 0 : void InitOOJSEquipmentInfo(JSContext *context, JSObject *global)
180 : {
181 : sEquipmentInfoPrototype = JS_InitClass(context, global, NULL, &sEquipmentInfoClass, OOJSUnconstructableConstruct, 0, sEquipmentInfoProperties, sEquipmentInfoMethods, sEquipmentInfoStaticProperties, sEquipmentInfoStaticMethods);
182 :
183 : OOJSRegisterObjectConverter(&sEquipmentInfoClass, OOJSBasicPrivateObjectConverter);
184 : }
185 :
186 :
187 0 : OOEquipmentType *JSValueToEquipmentType(JSContext *context, jsval value)
188 : {
189 : OOJS_PROFILE_ENTER
190 :
191 : if (JSVAL_IS_OBJECT(value))
192 : {
193 : JSObject *object = JSVAL_TO_OBJECT(value);
194 : if (JS_InstanceOf(context, JSVAL_TO_OBJECT(value), &sEquipmentInfoClass, NULL))
195 : {
196 : return (OOEquipmentType *)JS_GetPrivate(context, object);
197 : }
198 : }
199 :
200 : NSString *string = OOStringFromJSValue(context, value);
201 : if (string != nil) return [OOEquipmentType equipmentTypeWithIdentifier:string];
202 : return nil;
203 :
204 : OOJS_PROFILE_EXIT
205 : }
206 :
207 :
208 0 : NSString *JSValueToEquipmentKey(JSContext *context, jsval value)
209 : {
210 : return [JSValueToEquipmentType(context, value) identifier];
211 : }
212 :
213 :
214 0 : NSString *JSValueToEquipmentKeyRelaxed(JSContext *context, jsval value, BOOL *outExists)
215 : {
216 : OOJS_PROFILE_ENTER
217 :
218 : NSString *result = nil;
219 : BOOL exists = NO;
220 : id objValue = OOJSNativeObjectFromJSValue(context, value);
221 :
222 : if ([objValue isKindOfClass:[OOEquipmentType class]])
223 : {
224 : result = [objValue identifier];
225 : exists = YES;
226 : }
227 : else if ([objValue isKindOfClass:[NSString class]])
228 : {
229 : /* To enforce deliberate backwards incompatibility, reject strings
230 : ending with _DAMAGED unless someone actually named an equip that
231 : way.
232 : */
233 : exists = [OOEquipmentType equipmentTypeWithIdentifier:objValue] != nil;
234 : if (exists || ![objValue hasSuffix:@"_DAMAGED"])
235 : {
236 : result = objValue;
237 : }
238 : }
239 :
240 : if (outExists != NULL) *outExists = exists;
241 : return result;
242 :
243 : OOJS_PROFILE_EXIT
244 : }
245 :
246 :
247 : // *** Implementation stuff ***
248 :
249 0 : static JSBool EquipmentInfoGetProperty(JSContext *context, JSObject *this, jsid propID, jsval *value)
250 : {
251 : if (!JSID_IS_INT(propID)) return YES;
252 :
253 : OOJS_NATIVE_ENTER(context)
254 :
255 : OOEquipmentType *eqType = nil;
256 : id result = nil;
257 : NSUInteger inst_time;
258 :
259 : if (EXPECT_NOT(!JSEquipmentInfoGetEquipmentType(context, this, &eqType))) return NO;
260 :
261 : switch (JSID_TO_INT(propID))
262 : {
263 : case kEquipmentInfo_equipmentKey:
264 : result = [eqType identifier];
265 : break;
266 :
267 : case kEquipmentInfo_name:
268 : result = [eqType name];
269 : break;
270 :
271 : case kEquipmentInfo_calculatedPrice:
272 : if ([[eqType identifier] isEqual:@"EQ_FUEL"])
273 : {
274 : return JS_NewNumberValue(context, (PLAYER_MAX_FUEL - [OOPlayerForScripting() fuel]) * [eqType price] * [OOPlayerForScripting() fuelChargeRate], value);
275 : }
276 : else if ([[eqType identifier] isEqual:@"EQ_RENOVATION"])
277 : {
278 : return JS_NewNumberValue(context, [OOPlayerForScripting() renovationCosts], value);
279 : }
280 : else
281 : {
282 : return JS_NewNumberValue(context, [OOPlayerForScripting() adjustPriceByScriptForEqKey:[eqType identifier] withCurrent:[eqType price]], value);
283 : }
284 : case kEquipmentInfo_canCarryMultiple:
285 : *value = OOJSValueFromBOOL([eqType canCarryMultiple]);
286 : return YES;
287 :
288 : case kEquipmentInfo_canBeDamaged:
289 : *value = OOJSValueFromBOOL([eqType canBeDamaged]);
290 : return YES;
291 :
292 : case kEquipmentInfo_description:
293 : result = [eqType descriptiveText];
294 : break;
295 :
296 : case kEquipmentInfo_damageProbability:
297 : return JS_NewNumberValue(context, [eqType damageProbability], value);
298 :
299 : case kEquipmentInfo_displayColor:
300 : result = [[eqType displayColor] normalizedArray];
301 : break;
302 :
303 : case kEquipmentInfo_fastAffinityDefensive:
304 : *value = OOJSValueFromBOOL([eqType fastAffinityDefensive]);
305 : return YES;
306 :
307 : case kEquipmentInfo_fastAffinityOffensive:
308 : *value = OOJSValueFromBOOL([eqType fastAffinityOffensive]);
309 : return YES;
310 :
311 : case kEquipmentInfo_defaultActivateKey:
312 : result = [eqType defaultActivateKey];
313 : break;
314 :
315 : case kEquipmentInfo_defaultModeKey:
316 : result = [eqType defaultModeKey];
317 : break;
318 :
319 : case kEquipmentInfo_techLevel:
320 : *value = INT_TO_JSVAL((int32_t)[eqType techLevel]);
321 : return YES;
322 :
323 : case kEquipmentInfo_effectiveTechLevel:
324 : *value = INT_TO_JSVAL((int32_t)[eqType effectiveTechLevel]);
325 : return YES;
326 :
327 : case kEquipmentInfo_price:
328 : return JS_NewNumberValue(context, [eqType price], value);
329 :
330 : case kEquipmentInfo_provides:
331 : result = [eqType providesForScripting];
332 : break;
333 :
334 : case kEquipmentInfo_installationTime:
335 : inst_time = [eqType installTime];
336 : if (inst_time == 0)
337 : {
338 : inst_time = [eqType price] + 600;
339 : }
340 : *value = INT_TO_JSVAL((int32_t)inst_time);
341 : return YES;
342 :
343 : case kEquipmentInfo_isAvailableToAll:
344 : *value = OOJSValueFromBOOL([eqType isAvailableToAll]);
345 : return YES;
346 :
347 : case kEquipmentInfo_isAvailableToNPCs:
348 : *value = OOJSValueFromBOOL([eqType isAvailableToNPCs]);
349 : return YES;
350 :
351 : case kEquipmentInfo_isAvailableToPlayer:
352 : *value = OOJSValueFromBOOL([eqType isAvailableToPlayer]);
353 : return YES;
354 :
355 : case kEquipmentInfo_repairTime:
356 : *value = INT_TO_JSVAL((int32_t)[eqType repairTime]);
357 : return YES;
358 :
359 : case kEquipmentInfo_requiresEmptyPylon:
360 : *value = OOJSValueFromBOOL([eqType requiresEmptyPylon]);
361 : return YES;
362 :
363 : case kEquipmentInfo_requiresMountedPylon:
364 : *value = OOJSValueFromBOOL([eqType requiresMountedPylon]);
365 : return YES;
366 :
367 : case kEquipmentInfo_requiresCleanLegalRecord:
368 : *value = OOJSValueFromBOOL([eqType requiresCleanLegalRecord]);
369 : return YES;
370 :
371 : case kEquipmentInfo_requiresNonCleanLegalRecord:
372 : *value = OOJSValueFromBOOL([eqType requiresNonCleanLegalRecord]);
373 : return YES;
374 :
375 : case kEquipmentInfo_requiresFreePassengerBerth:
376 : *value = OOJSValueFromBOOL([eqType requiresFreePassengerBerth]);
377 : return YES;
378 :
379 : case kEquipmentInfo_requiresFullFuel:
380 : *value = OOJSValueFromBOOL([eqType requiresFullFuel]);
381 : return YES;
382 :
383 : case kEquipmentInfo_requiresNonFullFuel:
384 : *value = OOJSValueFromBOOL([eqType requiresNonFullFuel]);
385 : return YES;
386 :
387 : case kEquipmentInfo_isExternalStore:
388 : *value = OOJSValueFromBOOL([eqType isMissileOrMine]);
389 : return YES;
390 :
391 : case kEquipmentInfo_isPortableBetweenShips:
392 : *value = OOJSValueFromBOOL([eqType isPortableBetweenShips]);
393 : return YES;
394 :
395 : case kEquipmentInfo_isVisible:
396 : *value = OOJSValueFromBOOL([eqType isVisible]);
397 : return YES;
398 :
399 : case kEquipmentInfo_requiredCargoSpace:
400 : *value = INT_TO_JSVAL((int32_t)[eqType requiredCargoSpace]);
401 : return YES;
402 :
403 : case kEquipmentInfo_requiresEquipment:
404 : result = [[eqType requiresEquipment] allObjects];
405 : break;
406 :
407 : case kEquipmentInfo_requiresAnyEquipment:
408 : result = [[eqType requiresAnyEquipment] allObjects];
409 : break;
410 :
411 : case kEquipmentInfo_incompatibleEquipment:
412 : result = [[eqType incompatibleEquipment] allObjects];
413 : break;
414 :
415 : case kEquipmentInfo_scriptInfo:
416 : result = [eqType scriptInfo];
417 : if (result == nil) result = [NSDictionary dictionary]; // empty rather than null
418 : break;
419 :
420 : case kEquipmentInfo_scriptName:
421 : result = [eqType scriptName];
422 : if (result == nil) result = @"";
423 : break;
424 :
425 : case kEquipmentInfo_weaponInfo:
426 : result = [eqType weaponInfo];
427 : if (result == nil) result = [NSDictionary dictionary]; // empty rather than null
428 : break;
429 :
430 : default:
431 : OOJSReportBadPropertySelector(context, this, propID, sEquipmentInfoProperties);
432 : return NO;
433 : }
434 :
435 : *value = OOJSValueFromNativeObject(context, result);
436 : return YES;
437 :
438 : OOJS_NATIVE_EXIT
439 : }
440 :
441 :
442 0 : static JSBool EquipmentInfoSetProperty(JSContext *context, JSObject *this, jsid propID, JSBool strict, jsval *value)
443 : {
444 : if (!JSID_IS_INT(propID)) return YES;
445 :
446 : OOJS_NATIVE_ENTER(context)
447 :
448 : OOEquipmentType *eqType = nil;
449 : int32 iValue;
450 : OOColor *colorForScript = nil;
451 :
452 : if (EXPECT_NOT(!JSEquipmentInfoGetEquipmentType(context, this, &eqType))) return NO;
453 :
454 : switch (JSID_TO_INT(propID))
455 : {
456 : case kEquipmentInfo_displayColor:
457 : colorForScript = [OOColor colorWithDescription:OOJSNativeObjectFromJSValue(context, *value)];
458 : if (colorForScript != nil || JSVAL_IS_NULL(*value))
459 : {
460 : [eqType setDisplayColor:colorForScript];
461 : return YES;
462 : }
463 : break;
464 : case kEquipmentInfo_effectiveTechLevel:
465 : OOStandardsDeprecated([NSString stringWithFormat:@"TL99 for variable tech level is deprecated for %@",[eqType identifier]]);
466 : if (!OOEnforceStandards() && [eqType techLevel] == kOOVariableTechLevel)
467 : {
468 : if (JSVAL_IS_NULL(*value))
469 : {
470 : // reset mission variable
471 : [OOPlayerForScripting() setMissionVariable:nil
472 : forKey:[@"mission_TL_FOR_" stringByAppendingString:[eqType identifier]]];
473 : return YES;
474 : }
475 : if (JS_ValueToInt32(context, *value, &iValue))
476 : {
477 : if (iValue < 0) iValue = 0;
478 : if (15 < iValue && iValue != kOOVariableTechLevel) iValue = 15;
479 : [OOPlayerForScripting() setMissionVariable:[NSString stringWithFormat:@"%u", iValue]
480 : forKey:[@"mission_TL_FOR_" stringByAppendingString:[eqType identifier]]];
481 : return YES;
482 : }
483 : }
484 : else
485 : {
486 : OOJSReportWarning(context, @"Cannot modify effective tech level for %@, because its base tech level is not 99.", [eqType identifier]);
487 : return YES;
488 : }
489 : break;
490 :
491 : default:
492 : OOJSReportBadPropertySelector(context, this, propID, sEquipmentInfoProperties);
493 : return NO;
494 : }
495 :
496 : OOJSReportBadPropertyValue(context, this, propID, sEquipmentInfoProperties, *value);
497 : return NO;
498 :
499 : OOJS_NATIVE_EXIT
500 : }
501 :
502 :
503 0 : static JSBool EquipmentInfoGetAllEqipment(JSContext *context, JSObject *this, jsid propID, jsval *value)
504 : {
505 : OOJS_NATIVE_ENTER(context)
506 :
507 : *value = OOJSValueFromNativeObject(context, [OOEquipmentType allEquipmentTypes]);
508 : return YES;
509 :
510 : OOJS_NATIVE_EXIT
511 : }
512 :
513 :
514 : @implementation OOEquipmentType (OOJavaScriptExtensions)
515 :
516 0 : - (jsval) oo_jsValueInContext:(JSContext *)context
517 : {
518 : if (_jsSelf == NULL)
519 : {
520 : _jsSelf = JS_NewObject(context, &sEquipmentInfoClass, sEquipmentInfoPrototype, NULL);
521 : if (_jsSelf != NULL)
522 : {
523 : if (!JS_SetPrivate(context, _jsSelf, [self retain])) _jsSelf = NULL;
524 : }
525 : }
526 :
527 : return OBJECT_TO_JSVAL(_jsSelf);
528 : }
529 :
530 :
531 0 : - (NSString *) oo_jsClassName
532 : {
533 : return @"EquipmentInfo";
534 : }
535 :
536 :
537 0 : - (void) oo_clearJSSelf:(JSObject *)selfVal
538 : {
539 : if (_jsSelf == selfVal) _jsSelf = NULL;
540 : }
541 :
542 : @end
543 :
544 :
545 : // *** Static methods ***
546 :
547 : // infoForKey(key : String): EquipmentInfo
548 0 : static JSBool EquipmentInfoStaticInfoForKey(JSContext *context, uintN argc, jsval *vp)
549 : {
550 : OOJS_NATIVE_ENTER(context)
551 :
552 : NSString *key = nil;
553 :
554 : if (argc > 0) key = OOStringFromJSValue(context, OOJS_ARGV[0]);
555 : if (key == nil)
556 : {
557 : OOJSReportBadArguments(context, @"EquipmentInfo", @"infoForKey", MIN(argc, 1U), OOJS_ARGV, nil, @"string");
558 : return NO;
559 : }
560 :
561 : OOJS_RETURN_OBJECT([OOEquipmentType equipmentTypeWithIdentifier:key]);
562 :
563 : OOJS_NATIVE_EXIT
564 : }
|