Oolite
Loading...
Searching...
No Matches
OOJSGlobal.m File Reference
Include dependency graph for OOJSGlobal.m:

Go to the source code of this file.

Enumerations

enum  { kGlobal_galaxyNumber , kGlobal_global , kGlobal_guiScreen }

Functions

static JSValue GlobalGetProperty (OOJS_GETTER_ARGS)
static JSValue GlobalLog (OOJS_NATIVE_ARGS)
static JSValue GlobalExpandDescription (OOJS_NATIVE_ARGS)
static JSValue GlobalKeyBindingDescription (OOJS_NATIVE_ARGS)
static JSValue GlobalExpandMissionText (OOJS_NATIVE_ARGS)
static JSValue GlobalDisplayNameForCommodity (OOJS_NATIVE_ARGS)
static JSValue GlobalRandomName (OOJS_NATIVE_ARGS)
static JSValue GlobalRandomInhabitantsDescription (OOJS_NATIVE_ARGS)
static JSValue GlobalSetScreenBackground (OOJS_NATIVE_ARGS)
static JSValue GlobalSetScreenOverlay (OOJS_NATIVE_ARGS)
static JSValue GlobalGetScreenBackgroundForKey (OOJS_NATIVE_ARGS)
static JSValue GlobalSetScreenBackgroundForKey (OOJS_NATIVE_ARGS)
static JSValue GlobalAutoAIForRole (OOJS_NATIVE_ARGS)
static JSValue GlobalPauseGame (OOJS_NATIVE_ARGS)
static JSValue GlobalGetGuiColorSettingForKey (OOJS_NATIVE_ARGS)
static JSValue GlobalSetGuiColorSettingForKey (OOJS_NATIVE_ARGS)
static JSValue GlobalSetExtraGuiScreenKeys (OOJS_NATIVE_ARGS)
static JSValue GlobalClearExtraGuiScreenKeys (OOJS_NATIVE_ARGS)
void SetUpOOJSGlobal (JSContext *context, JSValueConst global)
static JSValue GetParam (JSContext *context, JSValueConst object, const char *key)

Variables

static NSString *const kOOLogDebugMessage = @"script.debug.message"
static const JSCFunctionListEntry sGlobalProperties []
static const JSCFunctionListEntry sGlobalMethods []

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
kGlobal_galaxyNumber 
kGlobal_global 
kGlobal_guiScreen 

Definition at line 90 of file OOJSGlobal.m.

90 {
91 // Property IDs
92 kGlobal_galaxyNumber, // galaxy number, integer, read-only
93 kGlobal_global, // global.global.global.global, integer, read-only
94 kGlobal_guiScreen, // current GUI screen, string, read-only
95#ifdef OO_DEBUG_MONITOR_ENABLED
96 kGlobal_timeAccelerationFactor // time acceleration, float, read/write
97#endif
98};
@ kGlobal_guiScreen
Definition OOJSGlobal.m:108
@ kGlobal_global
Definition OOJSGlobal.m:107
@ kGlobal_galaxyNumber
Definition OOJSGlobal.m:106

Function Documentation

◆ GetParam()

JSValue GetParam ( JSContext * context,
JSValueConst object,
const char * key )
static

Definition at line 411 of file OOJSGlobal.m.

412{
413 JSValue value = JS_GetPropertyStr(context, object, key);
414 if (JS_IsException(value)) {
416 return JS_UNDEFINED;
417 }
418 return value;
419}
OOINLINE void OOJSReportPendingException(JSContext *context)

References OOJSReportPendingException().

Referenced by GlobalSetExtraGuiScreenKeys(), and StationSetInterface().

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

◆ GlobalAutoAIForRole()

JSValue GlobalAutoAIForRole ( OOJS_NATIVE_ARGS )
static

Definition at line 753 of file OOJSGlobal.m.

754{
755 OOJS_NATIVE_ENTER(context)
756
757 NSString* string = nil;
758
759 if (argc > 0)
760 string = OOStringFromJSValue(context, OOJS_ARGV[0]);
761 if (string == nil) {
762 OOJSReportBadArguments(context, nil, @"autoAIForRole", MIN(argc, 1), OOJS_ARGV, nil, @"string");
763 return JS_EXCEPTION;
764 }
765
766 NSDictionary* autoAIMap = [ResourceManager dictionaryFromFilesNamed:@"autoAImap.plist" inFolder:@"Config" andMerge:YES];
767 NSString* autoAI = [autoAIMap oo_stringForKey:string];
768
769 OOJS_RETURN_OBJECT(autoAI);
770
772}
#define OOJS_NATIVE_ENTER(cx)
#define OOJS_NATIVE_EXIT
#define OOJS_RETURN_OBJECT(o)
NSString * OOStringFromJSValue(JSContext *context, jsval value)
#define OOJS_ARGV
void OOJSReportBadArguments(JSContext *context, NSString *scriptClass, NSString *function, uintN argc, jsval *argv, NSString *message, NSString *expectedArgsDescription)
#define MIN(A, B)
Definition OOMaths.h:91
return nil
NSDictionary * dictionaryFromFilesNamed:inFolder:andMerge:(NSString *fileName,[inFolder] NSString *folderName,[andMerge] BOOL mergeFiles)

References ResourceManager::dictionaryFromFilesNamed:inFolder:andMerge:, MIN, nil, OOJS_ARGV, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_OBJECT, OOJSReportBadArguments(), and OOStringFromJSValue().

Here is the call graph for this function:

◆ GlobalClearExtraGuiScreenKeys()

JSValue GlobalClearExtraGuiScreenKeys ( OOJS_NATIVE_ARGS )
static

Definition at line 373 of file OOJSGlobal.m.

374{
375 OOJS_NATIVE_ENTER(context)
376
377 BOOL result = NO;
379
380 if (EXPECT_NOT(argc < 2)) {
381 OOJSReportBadArguments(context, nil, @"setExtraGuiScreenKeys", 0, OOJS_ARGV, nil, @"missing arguments");
382 return JS_EXCEPTION;
383 }
384
385 NSString* key = OOStringFromJSValue(context, OOJS_ARGV[0]);
386 if (EXPECT_NOT(key == nil || [key isEqualToString:@""])) {
387 OOJSReportBadArguments(context, nil, @"clearExtraGuiScreenKeys", 1, OOJS_ARGV, nil, @"key");
388 return JS_EXCEPTION;
389 }
390
392 if (!gui) {
393 OOJSReportBadArguments(context, nil, @"clearExtraGuiScreenKeys", 0, OOJS_ARGV, nil, @"guiScreen invalid entry");
394 return JS_EXCEPTION;
395 }
396
397 [player clearExtraGuiScreenKeys:gui key:key];
398
399 result = YES;
400 OOJS_RETURN_BOOL(result);
401
403}
OOINLINE OOGUIScreenID OOGUIScreenIDFromJSValue(JSContext *context, jsval value)
#define EXPECT_NOT(x)
PlayerEntity * OOPlayerForScripting(void)
Definition OOJSPlayer.m:175
#define OOJS_RETURN_BOOL(v)
OOGUIScreenID
void clearExtraGuiScreenKeys:key:(OOGUIScreenID gui,[key] NSString *key)

References PlayerEntity::clearExtraGuiScreenKeys:key:, EXPECT_NOT, nil, OOGUIScreenIDFromJSValue(), OOJS_ARGV, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_BOOL, OOJSReportBadArguments(), OOPlayerForScripting(), and OOStringFromJSValue().

Here is the call graph for this function:

◆ GlobalDisplayNameForCommodity()

JSValue GlobalDisplayNameForCommodity ( OOJS_NATIVE_ARGS )
static

Definition at line 313 of file OOJSGlobal.m.

314{
315 OOJS_NATIVE_ENTER(context)
316
317 NSString* string = nil;
318
319 if (argc > 0)
320 string = OOStringFromJSValue(context, OOJS_ARGV[0]);
321 if (string == nil) {
322 OOJSReportBadArguments(context, nil, @"displayNameForCommodity", MIN(argc, 1), OOJS_ARGV, nil, @"string");
323 return JS_EXCEPTION;
324 }
326
328}
NSString * CommodityDisplayNameForSymbolicName(NSString *symbolicName)

References CommodityDisplayNameForSymbolicName(), MIN, nil, OOJS_ARGV, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_OBJECT, OOJSReportBadArguments(), and OOStringFromJSValue().

Here is the call graph for this function:

◆ GlobalExpandDescription()

JSValue GlobalExpandDescription ( OOJS_NATIVE_ARGS )
static

Definition at line 237 of file OOJSGlobal.m.

238{
239 OOJS_NATIVE_ENTER(context)
240
241 NSString* string = nil;
242 NSDictionary* overrides = nil;
243
244 if (argc > 0)
245 string = OOStringFromJSValue(context, OOJS_ARGV[0]);
246 if (string == nil) {
247 OOJSReportBadArguments(context, nil, @"expandDescription", MIN(argc, 1), OOJS_ARGV, nil, @"string");
248 return JS_EXCEPTION;
249 }
250 if (argc > 1) {
251 overrides = OOJSDictionaryFromStringTable(context, OOJS_ARGV[1]);
252 }
253
257
258 OOJS_RETURN_OBJECT(string);
259
261}
#define OOJS_END_FULL_NATIVE
#define OOJS_BEGIN_FULL_NATIVE(context)
NSDictionary * OOJSDictionaryFromStringTable(JSContext *context, jsval value)
@ kOOExpandForJavaScript
Report warnings through JavaScript runtime system instead of normal logging.
@ kOOExpandGoodRNG
Use RANDROT for selecting from description arrays and for N expansion.
NSString * OOExpandDescriptionString(Random_Seed seed, NSString *string, NSDictionary *overrides, NSDictionary *legacyLocals, NSString *systemName, OOExpandOptions options)
const Random_Seed kNilRandomSeed

References kNilRandomSeed, kOOExpandForJavaScript, kOOExpandGoodRNG, MIN, nil, OOExpandDescriptionString(), OOJS_ARGV, OOJS_BEGIN_FULL_NATIVE, OOJS_END_FULL_NATIVE, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_OBJECT, OOJSDictionaryFromStringTable(), OOJSReportBadArguments(), and OOStringFromJSValue().

Here is the call graph for this function:

◆ GlobalExpandMissionText()

JSValue GlobalExpandMissionText ( OOJS_NATIVE_ARGS )
static

Definition at line 287 of file OOJSGlobal.m.

288{
289 OOJS_NATIVE_ENTER(context)
290
291 NSString* string = nil;
292 NSDictionary* overrides = nil;
293
294 if (argc > 0)
295 string = OOStringFromJSValue(context, OOJS_ARGV[0]);
296 if (string == nil) {
297 OOJSReportBadArguments(context, nil, @"expandMissionText", MIN(argc, 1), OOJS_ARGV, nil, @"string");
298 return JS_EXCEPTION;
299 }
300 if (argc > 1) {
301 overrides = OOJSDictionaryFromStringTable(context, OOJS_ARGV[1]);
302 }
303
304 string = [[UNIVERSE missiontext] oo_stringForKey:string];
306
307 OOJS_RETURN_OBJECT(string);
308
310}
@ kOOExpandBackslashN
Convert literal "\\n"s to line breaks (used for missiontext.plist for historical reasons).

References kNilRandomSeed, kOOExpandBackslashN, kOOExpandForJavaScript, kOOExpandGoodRNG, MIN, nil, OOExpandDescriptionString(), OOJS_ARGV, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_OBJECT, OOJSDictionaryFromStringTable(), OOJSReportBadArguments(), and OOStringFromJSValue().

Here is the call graph for this function:

◆ GlobalGetGuiColorSettingForKey()

JSValue GlobalGetGuiColorSettingForKey ( OOJS_NATIVE_ARGS )
static

Definition at line 643 of file OOJSGlobal.m.

644{
645 OOJS_NATIVE_ENTER(context)
646
647 if (EXPECT_NOT(argc == 0)) {
648 OOJSReportBadArguments(context, nil, @"getGuiColorForKey", 0, OOJS_ARGV, nil, @"missing arguments");
649 return JS_EXCEPTION;
650 }
651 NSString* key = OOStringFromJSValue(context, OOJS_ARGV[0]);
652 if (EXPECT_NOT(key == nil || [key isEqualToString:@""])) {
653 OOJSReportBadArguments(context, nil, @"getGuiColorForKey", 0, OOJS_ARGV, nil, @"key");
654 return JS_EXCEPTION;
655 }
656 if ([key rangeOfString:@"color"].location == NSNotFound) {
657 OOJSReportBadArguments(context, nil, @"getGuiColorForKey", 0, OOJS_ARGV, nil, @"valid color key setting");
658 return JS_EXCEPTION;
659 }
660
661 GuiDisplayGen* gui = [UNIVERSE gui];
662 OOColor* col = [gui colorFromSetting:key defaultValue:nil];
663
664 OOJS_RETURN_OBJECT([col normalizedArray]);
665
667}
OOColor * colorFromSetting:defaultValue:(NSString *setting,[defaultValue] OOColor *def)

References GuiDisplayGen::colorFromSetting:defaultValue:, EXPECT_NOT, nil, OOJS_ARGV, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_OBJECT, OOJSReportBadArguments(), and OOStringFromJSValue().

Here is the call graph for this function:

◆ GlobalGetProperty()

JSValue GlobalGetProperty ( OOJS_GETTER_ARGS )
static

Definition at line 141 of file OOJSGlobal.m.

142{
143 OOJS_NATIVE_ENTER(context)
144
146
147 switch (magic) {
149 return JS_NewInt32(context, [player currentGalaxyID]);
150
152 return OOJSValueFromGUIScreenID(context, [player guiScreen]);
153
154#ifdef OO_DEBUG_MONITOR_ENABLED
155 case kGlobal_timeAccelerationFactor:
156 return JS_NewNumber(context, [UNIVERSE timeAccelerationFactor]);
157#endif
158
159 default:
161 return JS_EXCEPTION;
162 }
163
165}
OOINLINE jsval OOJSValueFromGUIScreenID(JSContext *context, OOGUIScreenID value)
static JSPropertySpec sGlobalProperties[]
Definition OOJSGlobal.m:114
void OOJSReportBadPropertySelector(JSContext *context, JSObject *thisObj, jsid propID, JSPropertySpec *propertySpec)
#define OOJS_COUNT(array)
#define UNIVERSE
Definition Universe.h:827

References kGlobal_galaxyNumber, kGlobal_guiScreen, OOJS_COUNT, OOJS_GETTER_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJSReportBadPropertySelector(), OOJSValueFromGUIScreenID(), OOPlayerForScripting(), sGlobalProperties, and UNIVERSE.

Here is the call graph for this function:

◆ GlobalGetScreenBackgroundForKey()

JSValue GlobalGetScreenBackgroundForKey ( OOJS_NATIVE_ARGS )
static

Definition at line 566 of file OOJSGlobal.m.

567{
568 OOJS_NATIVE_ENTER(context)
569
570 if (EXPECT_NOT(argc == 0)) {
571 OOJSReportBadArguments(context, nil, @"getScreenBackgroundDefault", 0, OOJS_ARGV, nil, @"missing arguments");
572 return JS_EXCEPTION;
573 }
574 NSString* key = OOStringFromJSValue(context, OOJS_ARGV[0]);
575 if (EXPECT_NOT(key == nil || [key isEqualToString:@""])) {
576 OOJSReportBadArguments(context, nil, @"getScreenBackgroundDefault", 0, OOJS_ARGV, nil, @"key");
577 return JS_EXCEPTION;
578 }
579 NSDictionary* descriptor = [UNIVERSE screenTextureDescriptorForKey:key];
580
581 OOJS_RETURN_OBJECT(descriptor);
582
584}

References EXPECT_NOT, nil, OOJS_ARGV, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_OBJECT, OOJSReportBadArguments(), and OOStringFromJSValue().

Here is the call graph for this function:

◆ GlobalKeyBindingDescription()

JSValue GlobalKeyBindingDescription ( OOJS_NATIVE_ARGS )
static

Definition at line 263 of file OOJSGlobal.m.

264{
265 OOJS_NATIVE_ENTER(context)
266
267 NSString* string = nil;
269
270 if (argc > 0)
271 string = OOStringFromJSValue(context, OOJS_ARGV[0]);
272 if (string == nil) {
273 OOJSReportBadArguments(context, nil, @"keyBindingDescription", MIN(argc, 1), OOJS_ARGV, nil, @"string");
274 return JS_EXCEPTION;
275 }
276
278 string = [player keyBindingDescription2:string];
280
281 OOJS_RETURN_OBJECT(string);
282
284}
NSString * keyBindingDescription2:(NSString *binding)

References PlayerEntity::keyBindingDescription2:, MIN, nil, OOJS_ARGV, OOJS_BEGIN_FULL_NATIVE, OOJS_END_FULL_NATIVE, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_OBJECT, OOJSReportBadArguments(), OOPlayerForScripting(), and OOStringFromJSValue().

Here is the call graph for this function:

◆ GlobalLog()

JSValue GlobalLog ( OOJS_NATIVE_ARGS )
static

Definition at line 198 of file OOJSGlobal.m.

199{
200 OOJS_NATIVE_ENTER(context)
201
202 NSString* message = nil;
203 NSString* messageClass = nil;
204
205 if (EXPECT_NOT(argc < 1)) {
207 }
208 if (argc < 2) {
209 messageClass = kOOLogDebugMessage;
210 message = OOStringFromJSValue(context, OOJS_ARGV[0]);
211 } else {
212 messageClass = OOStringFromJSValueEvenIfNull(context, OOJS_ARGV[0]);
213 if (!OOLogWillDisplayMessagesInClass(messageClass)) {
214 // Do nothing (and short-circuit) if message class is filtered out.
216 }
217
218 message = [NSString concatenationOfStringsFromJavaScriptValues:OOJS_ARGV + 1 count:argc - 1 separator:@", " inContext:context];
219 }
220
222 OOLog(messageClass, @"%@", message);
223
224#if OOJSENGINE_MONITOR_SUPPORT
225 [[OOJavaScriptEngine sharedEngine] sendMonitorLogMessage:message
226 withMessageClass:nil
227 inContext:context];
228#endif
230
232
234}
NSString * OOStringFromJSValueEvenIfNull(JSContext *context, jsval value)
#define OOJS_RETURN_VOID
BOOL OOLogWillDisplayMessagesInClass(NSString *inMessageClass)
Definition OOLogging.m:136
#define OOLog(class, format,...)
Definition OOLogging.h:84
static NSString *const kOOLogDebugMessage
OOJavaScriptEngine * sharedEngine()

References EXPECT_NOT, kOOLogDebugMessage, nil, OOJS_ARGV, OOJS_BEGIN_FULL_NATIVE, OOJS_END_FULL_NATIVE, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_VOID, OOLog, OOLogWillDisplayMessagesInClass(), OOStringFromJSValue(), OOStringFromJSValueEvenIfNull(), and OOJavaScriptEngine::sharedEngine.

Here is the call graph for this function:

◆ GlobalPauseGame()

JSValue GlobalPauseGame ( OOJS_NATIVE_ARGS )
static

Definition at line 775 of file OOJSGlobal.m.

776{
777 OOJS_NATIVE_ENTER(context)
778
779 BOOL result = NO;
780 PlayerEntity* player = PLAYER;
781
782 if (player) {
783 OOGUIScreenID guiScreen = [player guiScreen];
784
785 if (guiScreen != GUI_SCREEN_LONG_RANGE_CHART && guiScreen != GUI_SCREEN_MISSION && guiScreen != GUI_SCREEN_REPORT && guiScreen != GUI_SCREEN_KEYBOARD_ENTRY && guiScreen != GUI_SCREEN_SAVE) {
786 [UNIVERSE pauseGame];
787 result = YES;
788 }
789 }
790
791 OOJS_RETURN_BOOL(result);
792
794}
#define PLAYER
OOGUIScreenID guiScreen()

References PlayerEntity::guiScreen, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_BOOL, and PLAYER.

Here is the call graph for this function:

◆ GlobalRandomInhabitantsDescription()

JSValue GlobalRandomInhabitantsDescription ( OOJS_NATIVE_ARGS )
static

Definition at line 352 of file OOJSGlobal.m.

353{
354 OOJS_NATIVE_ENTER(context)
355
356 NSString* string = nil;
357 Random_Seed aSeed;
358 int isPlural = YES;
359
360 if (argc > 0 && (isPlural = JS_ToBool(context, OOJS_ARGV[0])) < 0) {
361 JS_FreeValue(context, JS_GetException(context));
362 OOJSReportBadArguments(context, nil, @"randomInhabitantsDescription", 1, OOJS_ARGV, nil, @"boolean");
363 return JS_EXCEPTION;
364 }
365
367 string = [UNIVERSE getSystemInhabitants:Ranrot() % OO_SYSTEMS_PER_GALAXY plural:isPlural];
368 OOJS_RETURN_OBJECT(string);
369
371}
void make_pseudo_random_seed(Random_Seed *seed_ptr)

References make_pseudo_random_seed(), nil, OOJS_ARGV, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_OBJECT, and OOJSReportBadArguments().

Here is the call graph for this function:

◆ GlobalRandomName()

JSValue GlobalRandomName ( OOJS_NATIVE_ARGS )
static

Definition at line 331 of file OOJSGlobal.m.

332{
333 OOJS_NATIVE_ENTER(context)
334
335 /* Temporarily set the system generation seed to a "really random" seed,
336 so randomName() isn't repeatable.
337 */
338 RNG_Seed savedSeed = currentRandomSeed();
340
341 NSString* result = OOExpand(@"%N");
342
343 // Restore seed.
344 setRandomSeed(savedSeed);
345
346 OOJS_RETURN_OBJECT(result);
347
349}
#define OOExpand(string,...)
void setRandomSeed(RNG_Seed a_seed)
RNG_Seed currentRandomSeed(void)
unsigned Ranrot(void)

References currentRandomSeed(), OOExpand, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_OBJECT, Ranrot(), and setRandomSeed().

Here is the call graph for this function:

◆ GlobalSetExtraGuiScreenKeys()

JSValue GlobalSetExtraGuiScreenKeys ( OOJS_NATIVE_ARGS )
static

Definition at line 421 of file OOJSGlobal.m.

422{
423 OOJS_NATIVE_ENTER(context)
424
425 BOOL result = NO;
426 JSValue callback = JS_UNDEFINED;
427 JSValue value = JS_UNDEFINED;
428 NSString* key = nil;
429 OOGUIScreenID gui;
430 NSDictionary* keydefs = NULL;
431 JSValue params = JS_UNDEFINED;
433 // The SpiderMonkey version always described two arguments from argv[1] on; don't read past argv.
434 int defArgc = MIN(argc - 1, 2);
435
436 if (EXPECT_NOT(argc < 1)) {
437 OOJSReportBadArguments(context, nil, @"setExtraGuiScreenKeys", 0, OOJS_ARGV, nil, @"key, definition");
438 return JS_EXCEPTION;
439 }
440 key = OOStringFromJSValue(context, OOJS_ARGV[0]);
441
442 // Validate arguments.
443 // (SpiderMonkey's JS_ValueToObject() accepted null and undefined, yielding no object; treat them as invalid.)
444 if (argc >= 2 && !JS_IsNull(OOJS_ARGV[1]) && !JS_IsUndefined(OOJS_ARGV[1])) {
445 params = JS_ToObject(context, OOJS_ARGV[1]);
446 if (JS_IsException(params)) {
447 JS_FreeValue(context, JS_GetException(context));
448 params = JS_UNDEFINED;
449 }
450 }
451 if (!JS_IsObject(params)) {
452 OOJSReportBadArguments(context, @"global", @"setExtraGuiScreenKeys", defArgc, &OOJS_ARGV[1], nil, @"key, definition: definition is not a valid dictionary.");
453 return JS_EXCEPTION;
454 }
455
456 value = GetParam(context, params, "guiScreen");
457 if (JS_IsUndefined(value)) {
458 JS_FreeValue(context, params);
459 OOJSReportBadArguments(context, @"global", @"setExtraGuiScreenKeys", defArgc, &OOJS_ARGV[1], nil, @"key, definition: must have a 'guiScreen' property.");
460 return JS_EXCEPTION;
461 }
462
463 gui = OOGUIScreenIDFromJSValue(context, value);
464 JS_FreeValue(context, value);
465 // gui will be 0 for invalid screen id's as well as GUI_SCREEN_MAIN
466 if (gui == 0 || gui == GUI_SCREEN_LOAD || gui == GUI_SCREEN_SAVE || gui == GUI_SCREEN_STICKMAPPER || gui == GUI_SCREEN_OXZMANAGER || gui == GUI_SCREEN_NEWGAME || gui == GUI_SCREEN_SAVE_OVERWRITE || gui == GUI_SCREEN_KEYBOARD || gui == GUI_SCREEN_STICKPROFILE || gui == GUI_SCREEN_KEYBOARD_CONFIRMCLEAR || gui == GUI_SCREEN_KEYBOARD_CONFIG || gui == GUI_SCREEN_KEYBOARD_ENTRY || gui == GUI_SCREEN_KEYBOARD_LAYOUT) {
467 JS_FreeValue(context, params);
468 OOJSReportBadArguments(context, @"global", @"setExtraGuiScreenKeys", defArgc, &OOJS_ARGV[1], nil, @"key, definition: 'guiScreen' property must be a permitted and valid GUI_SCREEN idenfifier.");
469 return JS_EXCEPTION;
470 }
471
472 value = GetParam(context, params, "registerKeys");
473 if (JS_IsUndefined(value)) {
474 JS_FreeValue(context, params);
475 OOJSReportBadArguments(context, @"global", @"setExtraGuiScreenKeys", defArgc, &OOJS_ARGV[1], nil, @"key, definition: must have a 'registerKeys' property.");
476 return JS_EXCEPTION;
477 }
478 if (!JS_IsNull(value)) {
479 if (JS_IsObject(value)) {
480 keydefs = OOJSNativeObjectFromJSObject(context, value);
481 } else {
482 JS_FreeValue(context, value);
483 JS_FreeValue(context, params);
484 OOJSReportBadArguments(context, @"global", @"setExtraGuiScreenKeys", defArgc, &OOJS_ARGV[1], nil, @"key, definition: registerKeys is not a valid dictionary.");
485 return JS_EXCEPTION;
486 }
487 }
488 JS_FreeValue(context, value);
489
490 callback = GetParam(context, params, "callback");
491 if (JS_IsUndefined(callback)) {
492 JS_FreeValue(context, params);
493 OOJSReportBadArguments(context, @"global", @"setExtraGuiScreenKeys", defArgc, &OOJS_ARGV[1], NULL, @"key, definition; must have a 'callback' property.");
494 return JS_EXCEPTION;
495 }
496 if (!OOJSValueIsFunction(context, callback)) {
497 JS_FreeValue(context, callback);
498 JS_FreeValue(context, params);
499 OOJSReportBadArguments(context, @"global", @"setExtraGuiScreenKeys", defArgc, &OOJS_ARGV[1], NULL, @"key, definition; 'callback' property must be a function.");
500 return JS_EXCEPTION;
501 }
502
503 OOJSGuiScreenKeyDefinition* definition = [[OOJSGuiScreenKeyDefinition alloc] init];
504 [definition setName:key];
505 [definition setRegisterKeys:keydefs];
506 [definition setCallback:callback]; // Takes its own reference.
507 JS_FreeValue(context, callback);
508
509 // get callback 'this'
510 value = GetParam(context, params, "cbThis");
511 if (!JS_IsUndefined(value)) {
512 // As with SpiderMonkey's JS_ValueToObject(), null gives no object; primitives are boxed.
513 if (!JS_IsNull(value)) {
514 JSValue callbackThis = JS_ToObject(context, value);
515 if (JS_IsException(callbackThis)) {
516 JS_FreeValue(context, JS_GetException(context));
517 } else {
518 [definition setCallbackThis:callbackThis];
519 }
520 JS_FreeValue(context, callbackThis);
521 }
522 // can do .bind(this) for callback instead
523 }
524 JS_FreeValue(context, value);
525 JS_FreeValue(context, params);
526
527 result = [player setExtraGuiScreenKeys:gui definition:definition];
528 [definition release];
529
530 OOJS_RETURN_BOOL(result);
531
533}
id OOJSNativeObjectFromJSObject(JSContext *context, JSObject *object)
OOINLINE BOOL OOJSValueIsFunction(JSContext *context, jsval value)
static JSValue GetParam(JSContext *context, JSValueConst object, const char *key)
Definition OOJSGlobal.m:411
void setRegisterKeys:(NSDictionary *registerKeys)
void setCallbackThis:(JSObject *callbackthis)
BOOL setExtraGuiScreenKeys:definition:(OOGUIScreenID gui,[definition] OOJSGuiScreenKeyDefinition *definition)

References EXPECT_NOT, GetParam(), MIN, nil, OOGUIScreenIDFromJSValue(), OOJS_ARGV, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_BOOL, OOJSNativeObjectFromJSObject(), OOJSReportBadArguments(), OOJSValueIsFunction(), OOPlayerForScripting(), OOStringFromJSValue(), OOJSGuiScreenKeyDefinition::setCallback:, OOJSGuiScreenKeyDefinition::setCallbackThis:, PlayerEntity::setExtraGuiScreenKeys:definition:, OOJSGuiScreenKeyDefinition::setName:, and OOJSGuiScreenKeyDefinition::setRegisterKeys:.

Here is the call graph for this function:

◆ GlobalSetGuiColorSettingForKey()

JSValue GlobalSetGuiColorSettingForKey ( OOJS_NATIVE_ARGS )
static

Definition at line 670 of file OOJSGlobal.m.

671{
672 OOJS_NATIVE_ENTER(context)
673
674 BOOL result = NO;
675 OOColor* col = nil;
676
677 if (EXPECT_NOT(argc != 2)) {
678 OOJSReportBadArguments(context, nil, @"setGuiColorForKey", 0, OOJS_ARGV, nil, @"missing arguments");
679 return JS_EXCEPTION;
680 }
681
682 NSString* key = OOStringFromJSValue(context, OOJS_ARGV[0]);
683 JSValueConst value = OOJS_ARGV[1];
684 if (EXPECT_NOT(key == nil || [key isEqualToString:@""])) {
685 OOJSReportBadArguments(context, nil, @"setGuiColorForKey", 0, OOJS_ARGV, nil, @"key");
686 return JS_EXCEPTION;
687 }
688 if ([key rangeOfString:@"color"].location == NSNotFound) {
689 OOJSReportBadArguments(context, nil, @"setGuiColorForKey", 0, OOJS_ARGV, nil, @"valid color key setting");
690 return JS_EXCEPTION;
691 }
692
693 if (!JS_IsNull(value)) {
694 col = [OOColor colorWithDescription:OOJSNativeObjectFromJSValue(context, value)];
695 if (col == nil) {
696 OOJSReportBadArguments(context, nil, @"setGuiColorForKey", 1, OOJS_ARGV, nil, @"color descriptor");
697 return JS_EXCEPTION;
698 }
699 }
700
701 GuiDisplayGen* gui = [UNIVERSE gui];
702 [gui setGuiColorSettingFromKey:key color:col];
703 result = YES;
704
705 OOJS_RETURN_BOOL(result);
706
708}
void setGuiColorSettingFromKey:color:(NSString *key,[color] OOColor *col)
OOColor * colorWithDescription:(id description)
Definition OOColor.m:135

References OOColor::colorWithDescription:, EXPECT_NOT, nil, OOJS_ARGV, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_BOOL, OOJSReportBadArguments(), OOStringFromJSValue(), and GuiDisplayGen::setGuiColorSettingFromKey:color:.

Here is the call graph for this function:

◆ GlobalSetScreenBackground()

JSValue GlobalSetScreenBackground ( OOJS_NATIVE_ARGS )
static

Definition at line 536 of file OOJSGlobal.m.

537{
538 OOJS_NATIVE_ENTER(context)
539
540 BOOL result = NO;
541 JSValueConst value = (argc > 0) ? OOJS_ARGV[0] : JS_NULL;
542
543 if (EXPECT_NOT(argc == 0)) {
544 OOJSReportWarning(context, @"Usage error: %@() called with no arguments. Treating as %@(null). This call may fail in a future version of Oolite.", @"setScreenBackground", @"setScreenBackground");
545 } else if (EXPECT_NOT(JS_IsUndefined(value))) {
546 OOJSReportBadArguments(context, nil, @"setScreenBackground", 1, &value, nil, @"GUI texture descriptor");
547 return JS_EXCEPTION;
548 }
549
550 if ([UNIVERSE viewDirection] == VIEW_GUI_DISPLAY) {
551 GuiDisplayGen* gui = [UNIVERSE gui];
552 NSDictionary* descriptor = [gui textureDescriptorFromJSValue:value inContext:context callerDescription:@"setScreenBackground()"];
553
554 result = [gui setBackgroundTextureDescriptor:descriptor];
555
556 // add some permanence to the override if we're in the equip ship screen
557 if (result && [PLAYER guiScreen] == GUI_SCREEN_EQUIP_SHIP)
558 [PLAYER setEquipScreenBackgroundDescriptor:descriptor];
559 }
560
561 OOJS_RETURN_BOOL(result);
562
564}
void OOJSReportWarning(JSContext *context, NSString *format,...)
NSDictionary * textureDescriptorFromJSValue:inContext:callerDescription:(jsval value,[inContext] JSContext *context,[callerDescription] NSString *callerDescription)
BOOL setBackgroundTextureDescriptor:(NSDictionary *descriptor)

References EXPECT_NOT, nil, OOJS_ARGV, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_BOOL, OOJSReportBadArguments(), OOJSReportWarning(), PLAYER, GuiDisplayGen::setBackgroundTextureDescriptor:, GuiDisplayGen::textureDescriptorFromJSValue:inContext:callerDescription:, and UNIVERSE.

Here is the call graph for this function:

◆ GlobalSetScreenBackgroundForKey()

JSValue GlobalSetScreenBackgroundForKey ( OOJS_NATIVE_ARGS )
static

Definition at line 587 of file OOJSGlobal.m.

588{
589 OOJS_NATIVE_ENTER(context)
590
591 BOOL result = NO;
592
593 if (EXPECT_NOT(argc < 2)) {
594 OOJSReportBadArguments(context, nil, @"setScreenBackgroundDefault", 0, OOJS_ARGV, nil, @"missing arguments");
595 return JS_EXCEPTION;
596 }
597
598 NSString* key = OOStringFromJSValue(context, OOJS_ARGV[0]);
599 JSValueConst value = OOJS_ARGV[1];
600 if (EXPECT_NOT(key == nil || [key isEqualToString:@""])) {
601 OOJSReportBadArguments(context, nil, @"setScreenBackgroundDefault", 0, OOJS_ARGV, nil, @"key");
602 return JS_EXCEPTION;
603 }
604
605 GuiDisplayGen* gui = [UNIVERSE gui];
606 NSDictionary* descriptor = [gui textureDescriptorFromJSValue:value inContext:context callerDescription:@"setScreenBackgroundDefault()"];
607
608 [UNIVERSE setScreenTextureDescriptorForKey:key descriptor:descriptor];
609 result = YES;
610
611 OOJS_RETURN_BOOL(result);
612
614}

References EXPECT_NOT, nil, OOJS_ARGV, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_BOOL, OOJSReportBadArguments(), OOStringFromJSValue(), and GuiDisplayGen::textureDescriptorFromJSValue:inContext:callerDescription:.

Here is the call graph for this function:

◆ GlobalSetScreenOverlay()

JSValue GlobalSetScreenOverlay ( OOJS_NATIVE_ARGS )
static

Definition at line 617 of file OOJSGlobal.m.

618{
619 OOJS_NATIVE_ENTER(context)
620
621 BOOL result = NO;
622 JSValueConst value = (argc > 0) ? OOJS_ARGV[0] : JS_NULL;
623
624 if (EXPECT_NOT(argc == 0)) {
625 OOJSReportWarning(context, @"Usage error: %@() called with no arguments. Treating as %@(null). This call may fail in a future version of Oolite.", @"setScreenOverlay", @"setScreenOverlay");
626 } else if (EXPECT_NOT(JS_IsUndefined(value))) {
627 OOJSReportBadArguments(context, nil, @"setScreenOverlay", 1, &value, nil, @"GUI texture descriptor");
628 return JS_EXCEPTION;
629 }
630
631 if ([UNIVERSE viewDirection] == VIEW_GUI_DISPLAY) {
632 GuiDisplayGen* gui = [UNIVERSE gui];
633 NSDictionary* descriptor = [gui textureDescriptorFromJSValue:value inContext:context callerDescription:@"setScreenOverlay()"];
634
635 result = [gui setForegroundTextureDescriptor:descriptor];
636 }
637
638 OOJS_RETURN_BOOL(result);
639
641}
BOOL setForegroundTextureDescriptor:(NSDictionary *descriptor)

References EXPECT_NOT, nil, OOJS_ARGV, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_BOOL, OOJSReportBadArguments(), OOJSReportWarning(), GuiDisplayGen::setForegroundTextureDescriptor:, GuiDisplayGen::textureDescriptorFromJSValue:inContext:callerDescription:, and UNIVERSE.

Here is the call graph for this function:

◆ SetUpOOJSGlobal()

void SetUpOOJSGlobal ( JSContext * context,
JSValueConst global )

Definition at line 135 of file OOJSGlobal.m.

136{
137 JS_SetPropertyFunctionList(context, global, sGlobalProperties, OOJS_COUNT(sGlobalProperties));
138 JS_SetPropertyFunctionList(context, global, sGlobalMethods, OOJS_COUNT(sGlobalMethods));
139}
static JSFunctionSpec sGlobalMethods[]
Definition OOJSGlobal.m:124

References OOJS_COUNT, sGlobalMethods, and sGlobalProperties.

Variable Documentation

◆ kOOLogDebugMessage

NSString* const kOOLogDebugMessage = @"script.debug.message"
static

Definition at line 55 of file OOJSGlobal.m.

◆ sGlobalMethods

const JSCFunctionListEntry sGlobalMethods[]
static
Initial value:
= {
JS_CFUNC_DEF("log", 1, GlobalLog),
JS_CFUNC_DEF("autoAIForRole", 1, GlobalAutoAIForRole),
JS_CFUNC_DEF("expandDescription", 1, GlobalExpandDescription),
JS_CFUNC_DEF("expandMissionText", 1, GlobalExpandMissionText),
JS_CFUNC_DEF("displayNameForCommodity", 1, GlobalDisplayNameForCommodity),
JS_CFUNC_DEF("randomName", 0, GlobalRandomName),
JS_CFUNC_DEF("randomInhabitantsDescription", 1, GlobalRandomInhabitantsDescription),
JS_CFUNC_DEF("setScreenBackground", 1, GlobalSetScreenBackground),
JS_CFUNC_DEF("getScreenBackgroundForKey", 1, GlobalGetScreenBackgroundForKey),
JS_CFUNC_DEF("setScreenBackgroundForKey", 2, GlobalSetScreenBackgroundForKey),
JS_CFUNC_DEF("setScreenOverlay", 1, GlobalSetScreenOverlay),
JS_CFUNC_DEF("getGuiColorSettingForKey", 1, GlobalGetGuiColorSettingForKey),
JS_CFUNC_DEF("setGuiColorSettingForKey", 2, GlobalSetGuiColorSettingForKey),
JS_CFUNC_DEF("keyBindingDescription", 1, GlobalKeyBindingDescription),
JS_CFUNC_DEF("setExtraGuiScreenKeys", 2, GlobalSetExtraGuiScreenKeys),
JS_CFUNC_DEF("clearExtraGuiScreenKeys", 2, GlobalClearExtraGuiScreenKeys),
JS_CFUNC_DEF("pauseGame", 0, GlobalPauseGame),
}
static JSBool GlobalSetScreenBackground(JSContext *context, uintN argc, jsval *vp)
Definition OOJSGlobal.m:517
static JSBool GlobalExpandDescription(JSContext *context, uintN argc, jsval *vp)
Definition OOJSGlobal.m:269
static JSBool GlobalPauseGame(JSContext *context, uintN argc, jsval *vp)
Definition OOJSGlobal.m:756
static JSBool GlobalSetScreenOverlay(JSContext *context, uintN argc, jsval *vp)
Definition OOJSGlobal.m:598
static JSBool GlobalGetScreenBackgroundForKey(JSContext *context, uintN argc, jsval *vp)
Definition OOJSGlobal.m:547
static JSBool GlobalLog(JSContext *context, uintN argc, jsval *vp)
Definition OOJSGlobal.m:230
static JSBool GlobalGetGuiColorSettingForKey(JSContext *context, uintN argc, jsval *vp)
Definition OOJSGlobal.m:624
static JSBool GlobalExpandMissionText(JSContext *context, uintN argc, jsval *vp)
Definition OOJSGlobal.m:319
static JSBool GlobalSetScreenBackgroundForKey(JSContext *context, uintN argc, jsval *vp)
Definition OOJSGlobal.m:568
static JSBool GlobalKeyBindingDescription(JSContext *context, uintN argc, jsval *vp)
Definition OOJSGlobal.m:295
static JSBool GlobalSetExtraGuiScreenKeys(JSContext *context, uintN argc, jsval *vp)
Definition OOJSGlobal.m:436
static JSBool GlobalDisplayNameForCommodity(JSContext *context, uintN argc, jsval *vp)
Definition OOJSGlobal.m:345
static JSBool GlobalRandomInhabitantsDescription(JSContext *context, uintN argc, jsval *vp)
Definition OOJSGlobal.m:384
static JSBool GlobalClearExtraGuiScreenKeys(JSContext *context, uintN argc, jsval *vp)
Definition OOJSGlobal.m:404
static JSBool GlobalSetGuiColorSettingForKey(JSContext *context, uintN argc, jsval *vp)
Definition OOJSGlobal.m:651
static JSBool GlobalAutoAIForRole(JSContext *context, uintN argc, jsval *vp)
Definition OOJSGlobal.m:734
static JSBool GlobalRandomName(JSContext *context, uintN argc, jsval *vp)
Definition OOJSGlobal.m:363

Definition at line 109 of file OOJSGlobal.m.

109 {
110 // JS name Function min args
111 JS_CFUNC_DEF("log", 1, GlobalLog),
112 JS_CFUNC_DEF("autoAIForRole", 1, GlobalAutoAIForRole),
113 JS_CFUNC_DEF("expandDescription", 1, GlobalExpandDescription),
114 JS_CFUNC_DEF("expandMissionText", 1, GlobalExpandMissionText),
115 JS_CFUNC_DEF("displayNameForCommodity", 1, GlobalDisplayNameForCommodity),
116 JS_CFUNC_DEF("randomName", 0, GlobalRandomName),
117 JS_CFUNC_DEF("randomInhabitantsDescription", 1, GlobalRandomInhabitantsDescription),
118 JS_CFUNC_DEF("setScreenBackground", 1, GlobalSetScreenBackground),
119 JS_CFUNC_DEF("getScreenBackgroundForKey", 1, GlobalGetScreenBackgroundForKey),
120 JS_CFUNC_DEF("setScreenBackgroundForKey", 2, GlobalSetScreenBackgroundForKey),
121 JS_CFUNC_DEF("setScreenOverlay", 1, GlobalSetScreenOverlay),
122 JS_CFUNC_DEF("getGuiColorSettingForKey", 1, GlobalGetGuiColorSettingForKey),
123 JS_CFUNC_DEF("setGuiColorSettingForKey", 2, GlobalSetGuiColorSettingForKey),
124 JS_CFUNC_DEF("keyBindingDescription", 1, GlobalKeyBindingDescription),
125 JS_CFUNC_DEF("setExtraGuiScreenKeys", 2, GlobalSetExtraGuiScreenKeys),
126 JS_CFUNC_DEF("clearExtraGuiScreenKeys", 2, GlobalClearExtraGuiScreenKeys),
127
128#ifdef OO_DEBUG_MONITOR_ENABLED
129 JS_CFUNC_DEF("takeSnapShot", 1, GlobalTakeSnapShot),
130 JS_CFUNC_DEF("quitGame", 0, GlobalQuitGame),
131#endif
132 JS_CFUNC_DEF("pauseGame", 0, GlobalPauseGame),
133};
static JSBool GlobalQuitGame(JSContext *context, uintN argc, jsval *vp)
Definition OOJSGlobal.m:778

◆ sGlobalProperties

const JSCFunctionListEntry sGlobalProperties[]
static
Initial value:
= {
}
static JSBool GlobalGetProperty(JSContext *context, JSObject *this, jsid propID, jsval *value)
Definition OOJSGlobal.m:167
#define OOJS_PROPERTY_RO(name, getter, magic)

Definition at line 100 of file OOJSGlobal.m.

100 {
101 // JS name Getter Setter ID
104#ifdef OO_DEBUG_MONITOR_ENABLED
105 OOJS_PROPERTY_RW("timeAccelerationFactor", GlobalGetProperty, GlobalSetProperty, kGlobal_timeAccelerationFactor),
106#endif
107};
#define OOJS_PROPERTY_RW(name, getter, setter, magic)