Oolite 1.91.0.7699-250829-cea269d
Loading...
Searching...
No Matches
OOJSGlobal.m File Reference
Include dependency graph for OOJSGlobal.m:

Go to the source code of this file.

Classes

category  OOJavaScriptEngine(OOMonitorSupportInternal)

Enumerations

enum  { kGlobal_galaxyNumber , kGlobal_global , kGlobal_guiScreen , kGlobal_timeAccelerationFactor }

Functions

static JSBool GlobalGetProperty (JSContext *context, JSObject *this, jsid propID, jsval *value)
static JSBool GlobalSetProperty (JSContext *context, JSObject *this, jsid propID, JSBool strict, jsval *value)
static JSBool GlobalLog (JSContext *context, uintN argc, jsval *vp)
static JSBool GlobalExpandDescription (JSContext *context, uintN argc, jsval *vp)
static JSBool GlobalKeyBindingDescription (JSContext *context, uintN argc, jsval *vp)
static JSBool GlobalExpandMissionText (JSContext *context, uintN argc, jsval *vp)
static JSBool GlobalDisplayNameForCommodity (JSContext *context, uintN argc, jsval *vp)
static JSBool GlobalRandomName (JSContext *context, uintN argc, jsval *vp)
static JSBool GlobalRandomInhabitantsDescription (JSContext *context, uintN argc, jsval *vp)
static JSBool GlobalSetScreenBackground (JSContext *context, uintN argc, jsval *vp)
static JSBool GlobalSetScreenOverlay (JSContext *context, uintN argc, jsval *vp)
static JSBool GlobalGetScreenBackgroundForKey (JSContext *context, uintN argc, jsval *vp)
static JSBool GlobalSetScreenBackgroundForKey (JSContext *context, uintN argc, jsval *vp)
static JSBool GlobalAutoAIForRole (JSContext *context, uintN argc, jsval *vp)
static JSBool GlobalPauseGame (JSContext *context, uintN argc, jsval *vp)
static JSBool GlobalGetGuiColorSettingForKey (JSContext *context, uintN argc, jsval *vp)
static JSBool GlobalSetGuiColorSettingForKey (JSContext *context, uintN argc, jsval *vp)
static JSBool GlobalSetExtraGuiScreenKeys (JSContext *context, uintN argc, jsval *vp)
static JSBool GlobalClearExtraGuiScreenKeys (JSContext *context, uintN argc, jsval *vp)
static JSBool GlobalTakeSnapShot (JSContext *context, uintN argc, jsval *vp)
void CreateOOJSGlobal (JSContext *context, JSObject **outGlobal)
void SetUpOOJSGlobal (JSContext *context, JSObject *global)

Variables

static NSString *const kOOLogDebugMessage = @"@"script.debug.message"
static JSClass sGlobalClass
static JSPropertySpec sGlobalProperties []
static JSFunctionSpec sGlobalMethods []

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
kGlobal_galaxyNumber 
kGlobal_global 
kGlobal_guiScreen 
kGlobal_timeAccelerationFactor 

Definition at line 108 of file OOJSGlobal.m.

109{
110 // Property IDs
111 kGlobal_galaxyNumber, // galaxy number, integer, read-only
112 kGlobal_global, // global.global.global.global, integer, read-only
113 kGlobal_guiScreen, // current GUI screen, string, read-only
114#ifndef NDEBUG
115 kGlobal_timeAccelerationFactor // time acceleration, float, read/write
116#endif
117};
@ kGlobal_guiScreen
Definition OOJSGlobal.m:113
@ kGlobal_timeAccelerationFactor
Definition OOJSGlobal.m:115
@ kGlobal_global
Definition OOJSGlobal.m:112
@ kGlobal_galaxyNumber
Definition OOJSGlobal.m:111

Function Documentation

◆ CreateOOJSGlobal()

void CreateOOJSGlobal ( JSContext * context,
JSObject ** outGlobal )

Definition at line 160 of file OOJSGlobal.m.

161{
162 assert(outGlobal != NULL);
163
164 *outGlobal = JS_NewCompartmentAndGlobalObject(context, &sGlobalClass, NULL);
165
166 JS_SetGlobalObject(context, *outGlobal);
167 JS_DefineProperty(context, *outGlobal, "global", OBJECT_TO_JSVAL(*outGlobal), NULL, NULL, OOJS_PROP_READONLY);
168}
static JSClass sGlobalClass
Definition OOJSGlobal.m:87
#define OOJS_PROP_READONLY

References OOJS_PROP_READONLY, and sGlobalClass.

Referenced by OOJavaScriptEngine(Private)::createMainThreadContext.

Here is the caller graph for this function:

◆ GlobalAutoAIForRole()

JSBool GlobalAutoAIForRole ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 808 of file OOJSGlobal.m.

809{
810 OOJS_NATIVE_ENTER(context)
811
812 NSString *string = nil;
813
814 if (argc > 0) string = OOStringFromJSValue(context,OOJS_ARGV[0]);
815 if (string == nil)
816 {
817 OOJSReportBadArguments(context, nil, @"autoAIForRole", MIN(argc, 1U), OOJS_ARGV, nil, @"string");
818 return NO;
819 }
820
821 NSDictionary *autoAIMap = [ResourceManager dictionaryFromFilesNamed:@"autoAImap.plist" inFolder:@"Config" andMerge:YES];
822 NSString *autoAI = [autoAIMap oo_stringForKey:string];
823
824 OOJS_RETURN_OBJECT(autoAI);
825
827}
#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:111
return nil

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

Here is the call graph for this function:

◆ GlobalClearExtraGuiScreenKeys()

JSBool GlobalClearExtraGuiScreenKeys ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 432 of file OOJSGlobal.m.

433{
434 OOJS_NATIVE_ENTER(context)
435
436 BOOL result = NO;
438
439 if (EXPECT_NOT(argc < 2))
440 {
441 OOJSReportBadArguments(context, nil, @"setExtraGuiScreenKeys", 0, OOJS_ARGV, nil, @"missing arguments");
442 return NO;
443 }
444
445 NSString *key = OOStringFromJSValue(context, OOJS_ARGV[0]);
446 if (EXPECT_NOT(key == nil || [key isEqualToString:@""]))
447 {
448 OOJSReportBadArguments(context, nil, @"clearExtraGuiScreenKeys", 1, OOJS_ARGV, nil, @"key");
449 return NO;
450 }
451
453 if (!gui)
454 {
455 OOJSReportBadArguments(context, nil, @"clearExtraGuiScreenKeys", 0, OOJS_ARGV, nil, @"guiScreen invalid entry");
456 return NO;
457 }
458
459 [player clearExtraGuiScreenKeys:gui key:key];
460
461 result = YES;
462 OOJS_RETURN_BOOL(result);
463
465}
OOINLINE OOGUIScreenID OOGUIScreenIDFromJSValue(JSContext *context, jsval value)
#define EXPECT_NOT(x)
PlayerEntity * OOPlayerForScripting(void)
Definition OOJSPlayer.m:191
#define OOJS_RETURN_BOOL(v)
OOGUIScreenID

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

Here is the call graph for this function:

◆ GlobalDisplayNameForCommodity()

JSBool GlobalDisplayNameForCommodity ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 369 of file OOJSGlobal.m.

370{
371 OOJS_NATIVE_ENTER(context)
372
373 NSString *string = nil;
374
375 if (argc > 0) string = OOStringFromJSValue(context,OOJS_ARGV[0]);
376 if (string == nil)
377 {
378 OOJSReportBadArguments(context, nil, @"displayNameForCommodity", MIN(argc, 1U), OOJS_ARGV, nil, @"string");
379 return NO;
380 }
382
384}
NSString * CommodityDisplayNameForSymbolicName(NSString *symbolicName)

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

Here is the call graph for this function:

◆ GlobalExpandDescription()

JSBool GlobalExpandDescription ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 289 of file OOJSGlobal.m.

290{
291 OOJS_NATIVE_ENTER(context)
292
293 NSString *string = nil;
294 NSDictionary *overrides = nil;
295
296 if (argc > 0) string = OOStringFromJSValue(context, OOJS_ARGV[0]);
297 if (string == nil)
298 {
299 OOJSReportBadArguments(context, nil, @"expandDescription", MIN(argc, 1U), OOJS_ARGV, nil, @"string");
300 return NO;
301 }
302 if (argc > 1)
303 {
304 overrides = OOJSDictionaryFromStringTable(context, OOJS_ARGV[1]);
305 }
306
310
311 OOJS_RETURN_OBJECT(string);
312
314}
#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_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_OBJECT, OOJSDictionaryFromStringTable(), OOJSReportBadArguments(), and OOStringFromJSValue().

Here is the call graph for this function:

◆ GlobalExpandMissionText()

JSBool GlobalExpandMissionText ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 341 of file OOJSGlobal.m.

342{
343 OOJS_NATIVE_ENTER(context)
344
345 NSString *string = nil;
346 NSDictionary *overrides = nil;
347
348 if (argc > 0) string = OOStringFromJSValue(context, OOJS_ARGV[0]);
349 if (string == nil)
350 {
351 OOJSReportBadArguments(context, nil, @"expandMissionText", MIN(argc, 1U), OOJS_ARGV, nil, @"string");
352 return NO;
353 }
354 if (argc > 1)
355 {
356 overrides = OOJSDictionaryFromStringTable(context, OOJS_ARGV[1]);
357 }
358
359 string = [[UNIVERSE missiontext] oo_stringForKey:string];
361
362 OOJS_RETURN_OBJECT(string);
363
365}
@ kOOExpandBackslashN
Convert literal "\\n"s to line breaks (used for missiontext.plist for historical reasons).
#define UNIVERSE
Definition Universe.h:840

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

Here is the call graph for this function:

◆ GlobalGetGuiColorSettingForKey()

JSBool GlobalGetGuiColorSettingForKey ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 684 of file OOJSGlobal.m.

685{
686 OOJS_NATIVE_ENTER(context)
687
688 if (EXPECT_NOT(argc == 0))
689 {
690 OOJSReportBadArguments(context, nil, @"getGuiColorForKey", 0, OOJS_ARGV, nil, @"missing arguments");
691 return NO;
692 }
693 NSString *key = OOStringFromJSValue(context, OOJS_ARGV[0]);
694 if (EXPECT_NOT(key == nil || [key isEqualToString:@""]))
695 {
696 OOJSReportBadArguments(context, nil, @"getGuiColorForKey", 0, OOJS_ARGV, nil, @"key");
697 return NO;
698 }
699 if ([key rangeOfString:@"color"].location == NSNotFound)
700 {
701 OOJSReportBadArguments(context, nil, @"getGuiColorForKey", 0, OOJS_ARGV, nil, @"valid color key setting");
702 return NO;
703 }
704
705 GuiDisplayGen *gui = [UNIVERSE gui];
706 OOColor *col = [gui colorFromSetting:key defaultValue:nil];
707
708 OOJS_RETURN_OBJECT([col normalizedArray]);
709
711}

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

Here is the call graph for this function:

◆ GlobalGetProperty()

JSBool GlobalGetProperty ( JSContext * context,
JSObject * this,
jsid propID,
jsval * value )
static

Definition at line 178 of file OOJSGlobal.m.

179{
180 if (!JSID_IS_INT(propID)) return YES;
181
182 OOJS_NATIVE_ENTER(context)
183
185
186 switch (JSID_TO_INT(propID))
187 {
189 *value = INT_TO_JSVAL([player currentGalaxyID]);
190 return YES;
191
193 *value = OOJSValueFromGUIScreenID(context, [player guiScreen]);
194 return YES;
195
196#ifndef NDEBUG
198 return JS_NewNumberValue(context, [UNIVERSE timeAccelerationFactor], value);
199#endif
200
201 default:
202 OOJSReportBadPropertySelector(context, this, propID, sGlobalProperties);
203 return NO;
204 }
205
207}
OOINLINE jsval OOJSValueFromGUIScreenID(JSContext *context, OOGUIScreenID value)
static JSPropertySpec sGlobalProperties[]
Definition OOJSGlobal.m:120
void OOJSReportBadPropertySelector(JSContext *context, JSObject *thisObj, jsid propID, JSPropertySpec *propertySpec)

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

Here is the call graph for this function:

◆ GlobalGetScreenBackgroundForKey()

JSBool GlobalGetScreenBackgroundForKey ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 597 of file OOJSGlobal.m.

598{
599 OOJS_NATIVE_ENTER(context)
600
601 if (EXPECT_NOT(argc == 0))
602 {
603 OOJSReportBadArguments(context, nil, @"getScreenBackgroundDefault", 0, OOJS_ARGV, nil, @"missing arguments");
604 return NO;
605 }
606 NSString *key = OOStringFromJSValue(context, OOJS_ARGV[0]);
607 if (EXPECT_NOT(key == nil || [key isEqualToString:@""]))
608 {
609 OOJSReportBadArguments(context, nil, @"getScreenBackgroundDefault", 0, OOJS_ARGV, nil, @"key");
610 return NO;
611 }
612 NSDictionary *descriptor = [UNIVERSE screenTextureDescriptorForKey:key];
613
614 OOJS_RETURN_OBJECT(descriptor);
615
617}

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

Here is the call graph for this function:

◆ GlobalKeyBindingDescription()

JSBool GlobalKeyBindingDescription ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 316 of file OOJSGlobal.m.

317{
318 OOJS_NATIVE_ENTER(context)
319
320 NSString *string = nil;
322
323 if (argc > 0) string = OOStringFromJSValue(context, OOJS_ARGV[0]);
324 if (string == nil)
325 {
326 OOJSReportBadArguments(context, nil, @"keyBindingDescription", MIN(argc, 1U), OOJS_ARGV, nil, @"string");
327 return NO;
328 }
329
331 string = [player keyBindingDescription2:string];
333
334 OOJS_RETURN_OBJECT(string);
335
337}

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

Here is the call graph for this function:

◆ GlobalLog()

JSBool GlobalLog ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 244 of file OOJSGlobal.m.

245{
246 OOJS_NATIVE_ENTER(context)
247
248 NSString *message = nil;
249 NSString *messageClass = nil;
250
251 if (EXPECT_NOT(argc < 1))
252 {
254 }
255 if (argc < 2)
256 {
257 messageClass = kOOLogDebugMessage;
258 message = OOStringFromJSValue(context, OOJS_ARGV[0]);
259 }
260 else
261 {
262 messageClass = OOStringFromJSValueEvenIfNull(context, OOJS_ARGV[0]);
263 if (!OOLogWillDisplayMessagesInClass(messageClass))
264 {
265 // Do nothing (and short-circuit) if message class is filtered out.
267 }
268
269 message = [NSString concatenationOfStringsFromJavaScriptValues:OOJS_ARGV + 1 count:argc - 1 separator:@", " inContext:context];
270 }
271
273 OOLog(messageClass, @"%@", message);
274
275#if OOJSENGINE_MONITOR_SUPPORT
276 [[OOJavaScriptEngine sharedEngine] sendMonitorLogMessage:message
277 withMessageClass:nil
278 inContext:context];
279#endif
281
283
285}
NSString * OOStringFromJSValueEvenIfNull(JSContext *context, jsval value)
#define OOJS_RETURN_VOID
BOOL OOLogWillDisplayMessagesInClass(NSString *inMessageClass)
Definition OOLogging.m:144
#define OOLog(class, format,...)
Definition OOLogging.h:88
unsigned count
static NSString *const kOOLogDebugMessage

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

Here is the call graph for this function:

◆ GlobalPauseGame()

JSBool GlobalPauseGame ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 830 of file OOJSGlobal.m.

831{
832 OOJS_NATIVE_ENTER(context)
833
834 BOOL result = NO;
835 PlayerEntity *player = PLAYER;
836
837 if (player)
838 {
839 OOGUIScreenID guiScreen = [player guiScreen];
840
841 if (guiScreen != GUI_SCREEN_LONG_RANGE_CHART &&
842 guiScreen != GUI_SCREEN_MISSION &&
843 guiScreen != GUI_SCREEN_REPORT &&
844 guiScreen != GUI_SCREEN_KEYBOARD_ENTRY &&
845 guiScreen != GUI_SCREEN_SAVE)
846 {
847 [UNIVERSE pauseGame];
848 result = YES;
849 }
850 }
851
852 OOJS_RETURN_BOOL(result);
853
855}
#define PLAYER

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

Here is the call graph for this function:

◆ GlobalRandomInhabitantsDescription()

JSBool GlobalRandomInhabitantsDescription ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 410 of file OOJSGlobal.m.

411{
412 OOJS_NATIVE_ENTER(context)
413
414 NSString *string = nil;
415 Random_Seed aSeed;
416 JSBool isPlural = YES;
417
418 if (argc > 0 && !JS_ValueToBoolean(context, OOJS_ARGV[0], &isPlural))
419 {
420 OOJSReportBadArguments(context, nil, @"randomInhabitantsDescription", 1, OOJS_ARGV, nil, @"boolean");
421 return NO;
422 }
423
425 string = [UNIVERSE getSystemInhabitants:Ranrot()%OO_SYSTEMS_PER_GALAXY plural:isPlural];
426 OOJS_RETURN_OBJECT(string);
427
429}
#define OO_SYSTEMS_PER_GALAXY
void make_pseudo_random_seed(Random_Seed *seed_ptr)
unsigned Ranrot(void)

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

Here is the call graph for this function:

◆ GlobalRandomName()

JSBool GlobalRandomName ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 388 of file OOJSGlobal.m.

389{
390 OOJS_NATIVE_ENTER(context)
391
392 /* Temporarily set the system generation seed to a "really random" seed,
393 so randomName() isn't repeatable.
394 */
395 RNG_Seed savedSeed = currentRandomSeed();
397
398 NSString *result = OOExpand(@"%N");
399
400 // Restore seed.
401 setRandomSeed(savedSeed);
402
403 OOJS_RETURN_OBJECT(result);
404
406}
#define OOExpand(string,...)
void setRandomSeed(RNG_Seed a_seed)
RNG_Seed currentRandomSeed(void)

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

Here is the call graph for this function:

◆ GlobalSetExtraGuiScreenKeys()

JSBool GlobalSetExtraGuiScreenKeys ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 467 of file OOJSGlobal.m.

468{
469 OOJS_NATIVE_ENTER(context)
470
471 BOOL result = NO;
472 jsval callback = JSVAL_NULL;
473 JSObject *callbackThis = NULL;
474 jsval value = JSVAL_NULL;
475 NSString *key = nil;
476 OOGUIScreenID gui;
477 NSDictionary *keydefs = NULL;
478 JSObject *params = NULL;
480
481 if (EXPECT_NOT(argc < 1))
482 {
483 OOJSReportBadArguments(context, nil, @"setExtraGuiScreenKeys", 0, OOJS_ARGV, nil, @"key, definition");
484 return NO;
485 }
486 key = OOStringFromJSValue(context, OOJS_ARGV[0]);
487
488 // Validate arguments.
489 if (argc < 2 || !JS_ValueToObject(context, OOJS_ARGV[1], &params))
490 {
491 OOJSReportBadArguments(context, @"global", @"setExtraGuiScreenKeys", 2, &OOJS_ARGV[1], nil, @"key, definition: definition is not a valid dictionary.");
492 return NO;
493 }
494
495 if (JS_GetProperty(context, params, "guiScreen", &value) == JS_FALSE || JSVAL_IS_VOID(value))
496 {
497 OOJSReportBadArguments(context, @"global", @"setExtraGuiScreenKeys", 2, &OOJS_ARGV[1], nil, @"key, definition: must have a 'guiScreen' property.");
498 return NO;
499 }
500
501 gui = OOGUIScreenIDFromJSValue(context, value);
502 // gui will be 0 for invalid screen id's as well as GUI_SCREEN_MAIN
503 if (gui == 0 || gui == GUI_SCREEN_LOAD || gui == GUI_SCREEN_SAVE || gui == GUI_SCREEN_STICKMAPPER || gui == GUI_SCREEN_OXZMANAGER ||
504 gui == GUI_SCREEN_NEWGAME || gui == GUI_SCREEN_SAVE_OVERWRITE || gui == GUI_SCREEN_KEYBOARD || gui == GUI_SCREEN_STICKPROFILE || gui == GUI_SCREEN_KEYBOARD_CONFIRMCLEAR ||
505 gui == GUI_SCREEN_KEYBOARD_CONFIG || gui == GUI_SCREEN_KEYBOARD_ENTRY || gui == GUI_SCREEN_KEYBOARD_LAYOUT)
506 {
507 OOJSReportBadArguments(context, @"global", @"setExtraGuiScreenKeys", 2, &OOJS_ARGV[1], nil, @"key, definition: 'guiScreen' property must be a permitted and valid GUI_SCREEN idenfifier.");
508 return NO;
509 }
510
511 if (JS_GetProperty(context, params, "registerKeys", &value) == JS_FALSE || JSVAL_IS_VOID(value))
512 {
513 OOJSReportBadArguments(context, @"global", @"setExtraGuiScreenKeys", 2, &OOJS_ARGV[1], nil, @"key, definition: must have a 'registerKeys' property.");
514 return NO;
515 }
516 if (!JSVAL_IS_NULL(value))
517 {
518 if (JSVAL_IS_OBJECT(value))
519 {
520 keydefs = OOJSNativeObjectFromJSObject(context, JSVAL_TO_OBJECT(value));
521 }
522 else
523 {
524 OOJSReportBadArguments(context, @"global", @"setExtraGuiScreenKeys", 2, &OOJS_ARGV[1], nil, @"key, definition: registerKeys is not a valid dictionary.");
525 return NO;
526 }
527 }
528
529 if (JS_GetProperty(context, params, "callback", &callback) == JS_FALSE || JSVAL_IS_VOID(callback))
530 {
531 OOJSReportBadArguments(context, @"global", @"setExtraGuiScreenKeys", 2, &OOJS_ARGV[1], NULL, @"key, definition; must have a 'callback' property.");
532 return NO;
533 }
534 if (!OOJSValueIsFunction(context,callback))
535 {
536 OOJSReportBadArguments(context, @"global", @"setExtraGuiScreenKeys", 2, &OOJS_ARGV[1], NULL, @"key, definition; 'callback' property must be a function.");
537 return NO;
538 }
539
540 OOJSGuiScreenKeyDefinition* definition = [[OOJSGuiScreenKeyDefinition alloc] init];
541 [definition setName:key];
542 [definition setRegisterKeys:keydefs];
543 [definition setCallback:callback];
544
545 // get callback 'this'
546 if (JS_GetProperty(context, params, "cbThis", &value) == JS_TRUE && !JSVAL_IS_VOID(value))
547 {
548 JS_ValueToObject(context, value, &callbackThis);
549 [definition setCallbackThis:callbackThis];
550 // can do .bind(this) for callback instead
551 }
552
553 result = [player setExtraGuiScreenKeys:gui definition:definition];
554 [definition release];
555
556 OOJS_RETURN_BOOL(result);
557
559}
id OOJSNativeObjectFromJSObject(JSContext *context, JSObject *object)
OOINLINE BOOL OOJSValueIsFunction(JSContext *context, jsval value)

References EXPECT_NOT, nil, OOGUIScreenIDFromJSValue(), OOJS_ARGV, 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()

JSBool GlobalSetGuiColorSettingForKey ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 715 of file OOJSGlobal.m.

716{
717 OOJS_NATIVE_ENTER(context)
718
719 BOOL result = NO;
720 OOColor *col = nil;
721
722 if (EXPECT_NOT(argc != 2))
723 {
724 OOJSReportBadArguments(context, nil, @"setGuiColorForKey", 0, OOJS_ARGV, nil, @"missing arguments");
725 return NO;
726 }
727
728 NSString *key = OOStringFromJSValue(context, OOJS_ARGV[0]);
729 jsval value = OOJS_ARGV[1];
730 if (EXPECT_NOT(key == nil || [key isEqualToString:@""]))
731 {
732 OOJSReportBadArguments(context, nil, @"setGuiColorForKey", 0, OOJS_ARGV, nil, @"key");
733 return NO;
734 }
735 if ([key rangeOfString:@"color"].location == NSNotFound)
736 {
737 OOJSReportBadArguments(context, nil, @"setGuiColorForKey", 0, OOJS_ARGV, nil, @"valid color key setting");
738 return NO;
739 }
740
741 if (!JSVAL_IS_NULL(value))
742 {
743 col = [OOColor colorWithDescription:OOJSNativeObjectFromJSValue(context, value)];
744 if (col == nil)
745 {
746 OOJSReportBadArguments(context, nil, @"setGuiColorForKey", 1, OOJS_ARGV, nil, @"color descriptor");
747 return NO;
748 }
749 }
750
751 GuiDisplayGen *gui = [UNIVERSE gui];
752 [gui setGuiColorSettingFromKey:key color:col];
753 result = YES;
754
755 OOJS_RETURN_BOOL(result);
756
758}
id OOJSNativeObjectFromJSValue(JSContext *context, jsval value)

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

Here is the call graph for this function:

◆ GlobalSetProperty()

JSBool GlobalSetProperty ( JSContext * context,
JSObject * this,
jsid propID,
JSBool strict,
jsval * value )
static

Definition at line 211 of file OOJSGlobal.m.

212{
213 if (!JSID_IS_INT(propID)) return YES;
214
215 OOJS_NATIVE_ENTER(context)
216
217 jsdouble fValue;
218
219 switch (JSID_TO_INT(propID))
220 {
222 if (JS_ValueToNumber(context, *value, &fValue))
223 {
224 [UNIVERSE setTimeAccelerationFactor:fValue];
225 return YES;
226 }
227 break;
228
229 default:
230 OOJSReportBadPropertySelector(context, this, propID, sGlobalProperties);
231 }
232
233 OOJSReportBadPropertyValue(context, this, propID, sGlobalProperties, *value);
234 return NO;
235
237}
void OOJSReportBadPropertyValue(JSContext *context, JSObject *thisObj, jsid propID, JSPropertySpec *propertySpec, jsval value)

References kGlobal_timeAccelerationFactor, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJSReportBadPropertySelector(), OOJSReportBadPropertyValue(), and sGlobalProperties.

Here is the call graph for this function:

◆ GlobalSetScreenBackground()

JSBool GlobalSetScreenBackground ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 563 of file OOJSGlobal.m.

564{
565 OOJS_NATIVE_ENTER(context)
566
567 BOOL result = NO;
568 jsval value = (argc > 0) ? OOJS_ARGV[0] : JSVAL_NULL;
569
570 if (EXPECT_NOT(argc == 0))
571 {
572 OOJSReportWarning(context, @"Usage error: %@() called with no arguments. Treating as %@(null). This call may fail in a future version of Oolite.", @"setScreenBackground", @"setScreenBackground");
573 }
574 else if (EXPECT_NOT(JSVAL_IS_VOID(value)))
575 {
576 OOJSReportBadArguments(context, nil, @"setScreenBackground", 1, &value, nil, @"GUI texture descriptor");
577 return NO;
578 }
579
580 if ([UNIVERSE viewDirection] == VIEW_GUI_DISPLAY)
581 {
582 GuiDisplayGen *gui = [UNIVERSE gui];
583 NSDictionary *descriptor = [gui textureDescriptorFromJSValue:value inContext:context callerDescription:@"setScreenBackground()"];
584
585 result = [gui setBackgroundTextureDescriptor:descriptor];
586
587 // add some permanence to the override if we're in the equip ship screen
588 if (result && [PLAYER guiScreen] == GUI_SCREEN_EQUIP_SHIP) [PLAYER setEquipScreenBackgroundDescriptor:descriptor];
589 }
590
591 OOJS_RETURN_BOOL(result);
592
594}
void OOJSReportWarning(JSContext *context, NSString *format,...)

References EXPECT_NOT, nil, OOJS_ARGV, 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()

JSBool GlobalSetScreenBackgroundForKey ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 620 of file OOJSGlobal.m.

621{
622 OOJS_NATIVE_ENTER(context)
623
624 BOOL result = NO;
625
626 if (EXPECT_NOT(argc < 2))
627 {
628 OOJSReportBadArguments(context, nil, @"setScreenBackgroundDefault", 0, OOJS_ARGV, nil, @"missing arguments");
629 return NO;
630 }
631
632 NSString *key = OOStringFromJSValue(context, OOJS_ARGV[0]);
633 jsval value = OOJS_ARGV[1];
634 if (EXPECT_NOT(key == nil || [key isEqualToString:@""]))
635 {
636 OOJSReportBadArguments(context, nil, @"setScreenBackgroundDefault", 0, OOJS_ARGV, nil, @"key");
637 return NO;
638 }
639
640 GuiDisplayGen *gui = [UNIVERSE gui];
641 NSDictionary *descriptor = [gui textureDescriptorFromJSValue:value inContext:context callerDescription:@"setScreenBackgroundDefault()"];
642
643 [UNIVERSE setScreenTextureDescriptorForKey:key descriptor:descriptor];
644 result = YES;
645
646 OOJS_RETURN_BOOL(result);
647
649}

References EXPECT_NOT, nil, OOJS_ARGV, 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()

JSBool GlobalSetScreenOverlay ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 653 of file OOJSGlobal.m.

654{
655 OOJS_NATIVE_ENTER(context)
656
657 BOOL result = NO;
658 jsval value = (argc > 0) ? OOJS_ARGV[0] : JSVAL_NULL;
659
660 if (EXPECT_NOT(argc == 0))
661 {
662 OOJSReportWarning(context, @"Usage error: %@() called with no arguments. Treating as %@(null). This call may fail in a future version of Oolite.", @"setScreenOverlay", @"setScreenOverlay");
663 }
664 else if (EXPECT_NOT(JSVAL_IS_VOID(value)))
665 {
666 OOJSReportBadArguments(context, nil, @"setScreenOverlay", 1, &value, nil, @"GUI texture descriptor");
667 return NO;
668 }
669
670 if ([UNIVERSE viewDirection] == VIEW_GUI_DISPLAY)
671 {
672 GuiDisplayGen *gui = [UNIVERSE gui];
673 NSDictionary *descriptor = [gui textureDescriptorFromJSValue:value inContext:context callerDescription:@"setScreenOverlay()"];
674
675 result = [gui setForegroundTextureDescriptor:descriptor];
676 }
677
678 OOJS_RETURN_BOOL(result);
679
681}

References EXPECT_NOT, nil, OOJS_ARGV, 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:

◆ GlobalTakeSnapShot()

JSBool GlobalTakeSnapShot ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 763 of file OOJSGlobal.m.

764{
765 OOJS_NATIVE_ENTER(context)
766
767 NSString *value = nil;
768 NSMutableCharacterSet *allowedChars = (NSMutableCharacterSet *)[NSMutableCharacterSet alphanumericCharacterSet];
769 BOOL result = NO;
770
771 [allowedChars addCharactersInString:@"_-"];
772
773 if (argc > 0)
774 {
775 value = OOStringFromJSValue(context, OOJS_ARGV[0]);
776 if (EXPECT_NOT(value == nil || [value rangeOfCharacterFromSet:[allowedChars invertedSet]].location != NSNotFound))
777 {
778 OOJSReportBadArguments(context, nil, @"takeSnapShot", argc, OOJS_ARGV, nil, @"alphanumeric string");
779 return NO;
780 }
781 }
782
783 NSString *playerFileDirectory = [[NSFileManager defaultManager] defaultCommanderPath];
784 NSDictionary *attr = [[NSFileManager defaultManager] oo_fileSystemAttributesAtPath:playerFileDirectory];
785
786 if (attr != nil)
787 {
788 double freeSpace = [attr oo_doubleForKey:NSFileSystemFreeSize];
789 if (freeSpace < 1073741824) // less than 1 GB free on disk?
790 {
791 OOJSReportWarning(context, @"takeSnapShot: function disabled when free disk space is less than 1GB.");
793 }
794 }
795
796
798 result = [[UNIVERSE gameView] snapShot:value];
800
801 OOJS_RETURN_BOOL(result);
802
804}

References EXPECT_NOT, nil, OOJS_ARGV, OOJS_BEGIN_FULL_NATIVE, OOJS_END_FULL_NATIVE, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_BOOL, OOJSReportBadArguments(), OOJSReportWarning(), and OOStringFromJSValue().

Here is the call graph for this function:

◆ SetUpOOJSGlobal()

void SetUpOOJSGlobal ( JSContext * context,
JSObject * global )

Definition at line 171 of file OOJSGlobal.m.

172{
173 JS_DefineProperties(context, global, sGlobalProperties);
174 JS_DefineFunctions(context, global, sGlobalMethods);
175}
static JSFunctionSpec sGlobalMethods[]
Definition OOJSGlobal.m:132

References sGlobalMethods, and sGlobalProperties.

Referenced by OOJavaScriptEngine(Private)::createMainThreadContext.

Here is the caller graph for this function:

Variable Documentation

◆ kOOLogDebugMessage

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

Definition at line 56 of file OOJSGlobal.m.

◆ sGlobalClass

JSClass sGlobalClass
static
Initial value:
=
{
"Global",
JSCLASS_GLOBAL_FLAGS,
JS_PropertyStub,
JS_PropertyStub,
JS_EnumerateStub,
JS_ResolveStub,
JS_ConvertStub,
JS_FinalizeStub
}
static JSBool GlobalGetProperty(JSContext *context, JSObject *this, jsid propID, jsval *value)
Definition OOJSGlobal.m:178
static JSBool GlobalSetProperty(JSContext *context, JSObject *this, jsid propID, JSBool strict, jsval *value)
Definition OOJSGlobal.m:211

Definition at line 87 of file OOJSGlobal.m.

88{
89 "Global",
90 JSCLASS_GLOBAL_FLAGS,
91
92 JS_PropertyStub,
93 JS_PropertyStub,
95#ifndef NDEBUG
97#else
98 // No writeable properties in non-debug builds
99 JS_StrictPropertyStub,
100#endif
101 JS_EnumerateStub,
102 JS_ResolveStub,
103 JS_ConvertStub,
104 JS_FinalizeStub
105};

Referenced by CreateOOJSGlobal().

◆ sGlobalMethods

JSFunctionSpec sGlobalMethods[]
static
Initial value:
=
{
{ "log", GlobalLog, 1 },
{ "autoAIForRole", GlobalAutoAIForRole, 1 },
{ "expandDescription", GlobalExpandDescription, 1 },
{ "expandMissionText", GlobalExpandMissionText, 1 },
{ "displayNameForCommodity", GlobalDisplayNameForCommodity, 1 },
{ "randomName", GlobalRandomName, 0 },
{ "randomInhabitantsDescription", GlobalRandomInhabitantsDescription, 1 },
{ "setScreenBackground", GlobalSetScreenBackground, 1 },
{ "getScreenBackgroundForKey", GlobalGetScreenBackgroundForKey, 1 },
{ "setScreenBackgroundForKey", GlobalSetScreenBackgroundForKey, 2 },
{ "setScreenOverlay", GlobalSetScreenOverlay, 1 },
{ "getGuiColorSettingForKey", GlobalGetGuiColorSettingForKey, 1 },
{ "setGuiColorSettingForKey", GlobalSetGuiColorSettingForKey, 2 },
{ "keyBindingDescription", GlobalKeyBindingDescription, 1 },
{ "setExtraGuiScreenKeys", GlobalSetExtraGuiScreenKeys, 2 },
{ "clearExtraGuiScreenKeys", GlobalClearExtraGuiScreenKeys, 2 },
{ "takeSnapShot", GlobalTakeSnapShot, 1 },
{ "pauseGame", GlobalPauseGame, 0 },
{ 0 }
}
static JSBool GlobalSetScreenBackground(JSContext *context, uintN argc, jsval *vp)
Definition OOJSGlobal.m:563
static JSBool GlobalExpandDescription(JSContext *context, uintN argc, jsval *vp)
Definition OOJSGlobal.m:289
static JSBool GlobalPauseGame(JSContext *context, uintN argc, jsval *vp)
Definition OOJSGlobal.m:830
static JSBool GlobalSetScreenOverlay(JSContext *context, uintN argc, jsval *vp)
Definition OOJSGlobal.m:653
static JSBool GlobalGetScreenBackgroundForKey(JSContext *context, uintN argc, jsval *vp)
Definition OOJSGlobal.m:597
static JSBool GlobalLog(JSContext *context, uintN argc, jsval *vp)
Definition OOJSGlobal.m:244
static JSBool GlobalGetGuiColorSettingForKey(JSContext *context, uintN argc, jsval *vp)
Definition OOJSGlobal.m:684
static JSBool GlobalExpandMissionText(JSContext *context, uintN argc, jsval *vp)
Definition OOJSGlobal.m:341
static JSBool GlobalSetScreenBackgroundForKey(JSContext *context, uintN argc, jsval *vp)
Definition OOJSGlobal.m:620
static JSBool GlobalKeyBindingDescription(JSContext *context, uintN argc, jsval *vp)
Definition OOJSGlobal.m:316
static JSBool GlobalSetExtraGuiScreenKeys(JSContext *context, uintN argc, jsval *vp)
Definition OOJSGlobal.m:467
static JSBool GlobalDisplayNameForCommodity(JSContext *context, uintN argc, jsval *vp)
Definition OOJSGlobal.m:369
static JSBool GlobalRandomInhabitantsDescription(JSContext *context, uintN argc, jsval *vp)
Definition OOJSGlobal.m:410
static JSBool GlobalTakeSnapShot(JSContext *context, uintN argc, jsval *vp)
Definition OOJSGlobal.m:763
static JSBool GlobalClearExtraGuiScreenKeys(JSContext *context, uintN argc, jsval *vp)
Definition OOJSGlobal.m:432
static JSBool GlobalSetGuiColorSettingForKey(JSContext *context, uintN argc, jsval *vp)
Definition OOJSGlobal.m:715
static JSBool GlobalAutoAIForRole(JSContext *context, uintN argc, jsval *vp)
Definition OOJSGlobal.m:808
static JSBool GlobalRandomName(JSContext *context, uintN argc, jsval *vp)
Definition OOJSGlobal.m:388

Definition at line 132 of file OOJSGlobal.m.

133{
134 // JS name Function min args
135 { "log", GlobalLog, 1 },
136 { "autoAIForRole", GlobalAutoAIForRole, 1 },
137 { "expandDescription", GlobalExpandDescription, 1 },
138 { "expandMissionText", GlobalExpandMissionText, 1 },
139 { "displayNameForCommodity", GlobalDisplayNameForCommodity, 1 },
140 { "randomName", GlobalRandomName, 0 },
141 { "randomInhabitantsDescription", GlobalRandomInhabitantsDescription, 1 },
142 { "setScreenBackground", GlobalSetScreenBackground, 1 },
143 { "getScreenBackgroundForKey", GlobalGetScreenBackgroundForKey, 1 },
144 { "setScreenBackgroundForKey", GlobalSetScreenBackgroundForKey, 2 },
145 { "setScreenOverlay", GlobalSetScreenOverlay, 1 },
146 { "getGuiColorSettingForKey", GlobalGetGuiColorSettingForKey, 1 },
147 { "setGuiColorSettingForKey", GlobalSetGuiColorSettingForKey, 2 },
148 { "keyBindingDescription", GlobalKeyBindingDescription, 1 },
149 { "setExtraGuiScreenKeys", GlobalSetExtraGuiScreenKeys, 2 },
150 { "clearExtraGuiScreenKeys", GlobalClearExtraGuiScreenKeys, 2 },
151
152#ifndef NDEBUG
153 { "takeSnapShot", GlobalTakeSnapShot, 1 },
154#endif
155 { "pauseGame", GlobalPauseGame, 0 },
156 { 0 }
157};

Referenced by SetUpOOJSGlobal().

◆ sGlobalProperties

JSPropertySpec sGlobalProperties[]
static
Initial value:
=
{
{ 0 }
}
#define OOJS_PROP_READWRITE_CB
#define OOJS_PROP_READONLY_CB

Definition at line 120 of file OOJSGlobal.m.

121{
122 // JS name ID flags
123 { "galaxyNumber", kGlobal_galaxyNumber, OOJS_PROP_READONLY_CB },
125#ifndef NDEBUG
126 { "timeAccelerationFactor", kGlobal_timeAccelerationFactor, OOJS_PROP_READWRITE_CB },
127#endif
128 { 0 }
129};

Referenced by GlobalGetProperty(), GlobalSetProperty(), and SetUpOOJSGlobal().