43#if OOJSENGINE_MONITOR_SUPPORT
45@interface OOJavaScriptEngine (OOMonitorSupportInternal)
47- (void)sendMonitorLogMessage:(NSString*)message
48 withMessageClass:(NSString*)messageClass
49 inContext:(JSContext*)context;
58#ifdef OO_DEBUG_MONITOR_ENABLED
80#ifdef OO_DEBUG_MONITOR_ENABLED
95#ifdef OO_DEBUG_MONITOR_ENABLED
96 kGlobal_timeAccelerationFactor
104#ifdef OO_DEBUG_MONITOR_ENABLED
128#ifdef OO_DEBUG_MONITOR_ENABLED
129 JS_CFUNC_DEF(
"takeSnapShot", 1, GlobalTakeSnapShot),
149 return JS_NewInt32(context, [player currentGalaxyID]);
154#ifdef OO_DEBUG_MONITOR_ENABLED
155 case kGlobal_timeAccelerationFactor:
156 return JS_NewNumber(context, [
UNIVERSE timeAccelerationFactor]);
167#ifdef OO_DEBUG_MONITOR_ENABLED
175 case kGlobal_timeAccelerationFactor:
176 if (JS_ToFloat64(context, &fValue, value) == 0) {
177 [UNIVERSE setTimeAccelerationFactor:fValue];
180 JS_FreeValue(context, JS_GetException(context));
202 NSString* message =
nil;
203 NSString* messageClass =
nil;
218 message = [NSString concatenationOfStringsFromJavaScriptValues:OOJS_ARGV + 1 count:argc - 1 separator:@", " inContext:context];
222 OOLog(messageClass,
@"%@", message);
224#if OOJSENGINE_MONITOR_SUPPORT
241 NSString*
string =
nil;
242 NSDictionary* overrides =
nil;
267 NSString*
string =
nil;
291 NSString*
string =
nil;
292 NSDictionary* overrides =
nil;
304 string = [[UNIVERSE missiontext] oo_stringForKey:string];
317 NSString*
string =
nil;
356 NSString*
string =
nil;
360 if (argc > 0 && (isPlural = JS_ToBool(context,
OOJS_ARGV[0])) < 0) {
361 JS_FreeValue(context, JS_GetException(context));
367 string = [UNIVERSE getSystemInhabitants:Ranrot() % OO_SYSTEMS_PER_GALAXY plural:isPlural];
411static JSValue
GetParam(JSContext* context, JSValueConst
object,
const char* key)
413 JSValue value = JS_GetPropertyStr(context,
object, key);
414 if (JS_IsException(value)) {
426 JSValue callback = JS_UNDEFINED;
427 JSValue value = JS_UNDEFINED;
430 NSDictionary* keydefs = NULL;
431 JSValue params = JS_UNDEFINED;
434 int defArgc =
MIN(argc - 1, 2);
445 params = JS_ToObject(context,
OOJS_ARGV[1]);
446 if (JS_IsException(params)) {
447 JS_FreeValue(context, JS_GetException(context));
448 params = JS_UNDEFINED;
451 if (!JS_IsObject(params)) {
456 value =
GetParam(context, params,
"guiScreen");
457 if (JS_IsUndefined(value)) {
458 JS_FreeValue(context, params);
464 JS_FreeValue(context, value);
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.");
472 value =
GetParam(context, params,
"registerKeys");
473 if (JS_IsUndefined(value)) {
474 JS_FreeValue(context, params);
478 if (!JS_IsNull(value)) {
479 if (JS_IsObject(value)) {
482 JS_FreeValue(context, value);
483 JS_FreeValue(context, params);
488 JS_FreeValue(context, value);
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.");
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.");
507 JS_FreeValue(context, callback);
510 value =
GetParam(context, params,
"cbThis");
511 if (!JS_IsUndefined(value)) {
513 if (!JS_IsNull(value)) {
514 JSValue callbackThis = JS_ToObject(context, value);
515 if (JS_IsException(callbackThis)) {
516 JS_FreeValue(context, JS_GetException(context));
520 JS_FreeValue(context, callbackThis);
524 JS_FreeValue(context, value);
525 JS_FreeValue(context, params);
528 [definition release];
541 JSValueConst value = (argc > 0) ?
OOJS_ARGV[0] : JS_NULL;
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))) {
550 if ([
UNIVERSE viewDirection] == VIEW_GUI_DISPLAY) {
557 if (result && [
PLAYER guiScreen] == GUI_SCREEN_EQUIP_SHIP)
558 [PLAYER setEquipScreenBackgroundDescriptor:descriptor];
579 NSDictionary* descriptor = [UNIVERSE screenTextureDescriptorForKey:key];
608 [UNIVERSE setScreenTextureDescriptorForKey:key descriptor:descriptor];
622 JSValueConst value = (argc > 0) ?
OOJS_ARGV[0] : JS_NULL;
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))) {
631 if ([
UNIVERSE viewDirection] == VIEW_GUI_DISPLAY) {
656 if ([key rangeOfString:
@"color"].location == NSNotFound) {
688 if ([key rangeOfString:
@"color"].location == NSNotFound) {
693 if (!JS_IsNull(value)) {
710#ifdef OO_DEBUG_MONITOR_ENABLED
716 NSString* value =
nil;
717 NSMutableCharacterSet* allowedChars = (NSMutableCharacterSet*)[NSMutableCharacterSet alphanumericCharacterSet];
720 [allowedChars addCharactersInString:@"_-"];
724 if (
EXPECT_NOT(value ==
nil || [value rangeOfCharacterFromSet:[allowedChars invertedSet]].location != NSNotFound)) {
730 NSString* playerFileDirectory = [[NSFileManager defaultManager] defaultCommanderPath];
731 NSDictionary* attr = [[NSFileManager defaultManager] oo_fileSystemAttributesAtPath:playerFileDirectory];
734 double freeSpace = [attr oo_doubleForKey:NSFileSystemFreeSize];
735 if (freeSpace < 1073741824)
737 OOJSReportWarning(context,
@"takeSnapShot: function disabled when free disk space is less than 1GB.");
743 result = [[UNIVERSE gameView] snapShot:value];
757 NSString*
string =
nil;
767 NSString* autoAI = [autoAIMap oo_stringForKey:string];
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];
796#ifdef OO_DEBUG_MONITOR_ENABLED
802 OOLog(
@"script.debug.quit",
@"%@",
@"Quit requested via JavaScript global.quitGame()");
807 [UNIVERSE performSelector:@selector(quitGame) withObject:nil afterDelay:0.0];
OOINLINE OOGUIScreenID OOGUIScreenIDFromJSValue(JSContext *context, jsval value)
OOINLINE jsval OOJSValueFromGUIScreenID(JSContext *context, OOGUIScreenID value)
NSString * CommodityDisplayNameForSymbolicName(NSString *symbolicName)
#define OOJS_END_FULL_NATIVE
#define OOJS_BEGIN_FULL_NATIVE(context)
#define OOJS_NATIVE_ENTER(cx)
void SetUpOOJSGlobal(JSContext *context, JSObject *global)
static JSBool GlobalSetScreenBackground(JSContext *context, uintN argc, jsval *vp)
static JSBool GlobalExpandDescription(JSContext *context, uintN argc, jsval *vp)
static JSBool GlobalPauseGame(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 GlobalLog(JSContext *context, uintN argc, jsval *vp)
static JSBool GlobalGetGuiColorSettingForKey(JSContext *context, uintN argc, jsval *vp)
static JSBool GlobalGetProperty(JSContext *context, JSObject *this, jsid propID, jsval *value)
static JSFunctionSpec sGlobalMethods[]
static JSPropertySpec sGlobalProperties[]
static JSBool GlobalExpandMissionText(JSContext *context, uintN argc, jsval *vp)
static JSBool GlobalSetScreenBackgroundForKey(JSContext *context, uintN argc, jsval *vp)
static JSBool GlobalKeyBindingDescription(JSContext *context, uintN argc, jsval *vp)
static JSBool GlobalSetExtraGuiScreenKeys(JSContext *context, uintN argc, jsval *vp)
static JSBool GlobalDisplayNameForCommodity(JSContext *context, uintN argc, jsval *vp)
static JSBool GlobalRandomInhabitantsDescription(JSContext *context, uintN argc, jsval *vp)
static JSBool GlobalClearExtraGuiScreenKeys(JSContext *context, uintN argc, jsval *vp)
static JSBool GlobalQuitGame(JSContext *context, uintN argc, jsval *vp)
static JSBool GlobalSetGuiColorSettingForKey(JSContext *context, uintN argc, jsval *vp)
static JSBool GlobalAutoAIForRole(JSContext *context, uintN argc, jsval *vp)
static JSBool GlobalRandomName(JSContext *context, uintN argc, jsval *vp)
PlayerEntity * OOPlayerForScripting(void)
void OOJSReportWarning(JSContext *context, NSString *format,...)
id OOJSNativeObjectFromJSObject(JSContext *context, JSObject *object)
#define OOJS_RETURN_OBJECT(o)
void OOJSReportBadPropertySelector(JSContext *context, JSObject *thisObj, jsid propID, JSPropertySpec *propertySpec)
#define OOJS_RETURN_BOOL(v)
NSString * OOStringFromJSValue(JSContext *context, jsval value)
OOINLINE BOOL OOJSValueIsFunction(JSContext *context, jsval value)
OOINLINE void OOJSReportPendingException(JSContext *context)
NSString * OOStringFromJSValueEvenIfNull(JSContext *context, jsval value)
void OOJSReportBadPropertyValue(JSContext *context, JSObject *thisObj, jsid propID, JSPropertySpec *propertySpec, jsval value)
void OOJSReportBadArguments(JSContext *context, NSString *scriptClass, NSString *function, uintN argc, jsval *argv, NSString *message, NSString *expectedArgsDescription)
NSDictionary * OOJSDictionaryFromStringTable(JSContext *context, jsval value)
BOOL OOLogWillDisplayMessagesInClass(NSString *inMessageClass)
#define OOLog(class, format,...)
@ kOOExpandForJavaScript
Report warnings through JavaScript runtime system instead of normal logging.
@ kOOExpandBackslashN
Convert literal "\\n"s to line breaks (used for missiontext.plist for historical reasons).
@ 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)
#define OOExpand(string,...)
static NSString *const kOOLogDebugMessage
static JSValue GetParam(JSContext *context, JSValueConst object, const char *key)
#define OOJS_PROPERTY_RW(name, getter, setter, magic)
#define OOJS_PROPERTY_RO(name, getter, magic)
#define OOJS_COUNT(array)
OOColor * colorFromSetting:defaultValue:(NSString *setting,[defaultValue] OOColor *def)
BOOL setForegroundTextureDescriptor:(NSDictionary *descriptor)
void setGuiColorSettingFromKey:color:(NSString *key,[color] OOColor *col)
NSDictionary * textureDescriptorFromJSValue:inContext:callerDescription:(jsval value,[inContext] JSContext *context,[callerDescription] NSString *callerDescription)
BOOL setBackgroundTextureDescriptor:(NSDictionary *descriptor)
OOColor * colorWithDescription:(id description)
void setRegisterKeys:(NSDictionary *registerKeys)
void setCallbackThis:(JSObject *callbackthis)
void setCallback:(jsval callback)
void setName:(NSString *name)
OOJavaScriptEngine * sharedEngine()
BOOL setExtraGuiScreenKeys:definition:(OOGUIScreenID gui,[definition] OOJSGuiScreenKeyDefinition *definition)
NSString * keyBindingDescription2:(NSString *binding)
void clearExtraGuiScreenKeys:key:(OOGUIScreenID gui,[key] NSString *key)
OOGUIScreenID guiScreen()
NSDictionary * dictionaryFromFilesNamed:inFolder:andMerge:(NSString *fileName,[inFolder] NSString *folderName,[andMerge] BOOL mergeFiles)
const Random_Seed kNilRandomSeed
void make_pseudo_random_seed(Random_Seed *seed_ptr)
void setRandomSeed(RNG_Seed a_seed)
RNG_Seed currentRandomSeed(void)