37#import "MyOpenGLView.h"
43#if OOJSENGINE_MONITOR_SUPPORT
45@interface OOJavaScriptEngine (OOMonitorSupportInternal)
47- (void)sendMonitorLogMessage:(NSString *)message
48 withMessageClass:(NSString *)messageClass
49 inContext:(JSContext *)context;
59static JSBool
GlobalGetProperty(JSContext *context, JSObject *
this, jsid propID, jsval *value);
61static JSBool
GlobalSetProperty(JSContext *context, JSObject *
this, jsid propID, JSBool strict, jsval *value);
64static JSBool
GlobalLog(JSContext *context, uintN argc, jsval *vp);
76static JSBool
GlobalPauseGame(JSContext *context, uintN argc, jsval *vp);
101 JS_StrictPropertyStub,
168 assert(outGlobal != NULL);
170 *outGlobal = JS_NewCompartmentAndGlobalObject(context, &
sGlobalClass, NULL);
172 JS_SetGlobalObject(context, *outGlobal);
173 JS_DefineProperty(context, *outGlobal,
"global", OBJECT_TO_JSVAL(*outGlobal), NULL, NULL,
OOJS_PROP_READONLY);
186 if (!JSID_IS_INT(propID))
return YES;
192 switch (JSID_TO_INT(propID))
195 *value = INT_TO_JSVAL([player currentGalaxyID]);
203 *value = INT_TO_JSVAL([
UNIVERSE currentPostFX]);
208 return JS_NewNumberValue(context, [
UNIVERSE timeAccelerationFactor], value);
221static JSBool
GlobalSetProperty(JSContext *context, JSObject *
this, jsid propID, JSBool strict, jsval *value)
223 if (!JSID_IS_INT(propID))
return YES;
230 switch (JSID_TO_INT(propID))
233 if (JS_ValueToInt32(context, *value, &iValue))
235 iValue =
MAX(iValue, 0);
236 [UNIVERSE setCurrentPostFX:iValue];
242 if (JS_ValueToNumber(context, *value, &fValue))
244 [UNIVERSE setTimeAccelerationFactor:fValue];
264static JSBool
GlobalLog(JSContext *context, uintN argc, jsval *vp)
268 NSString *message =
nil;
269 NSString *messageClass =
nil;
289 message = [NSString concatenationOfStringsFromJavaScriptValues:OOJS_ARGV + 1 count:argc - 1 separator:@", " inContext:context];
293 OOLog(messageClass,
@"%@", message);
295#if OOJSENGINE_MONITOR_SUPPORT
313 NSString *
string =
nil;
314 NSDictionary *overrides =
nil;
340 NSString *
string =
nil;
365 NSString *
string =
nil;
366 NSDictionary *overrides =
nil;
379 string = [[UNIVERSE missiontext] oo_stringForKey:string];
393 NSString *
string =
nil;
434 NSString *
string =
nil;
436 JSBool isPlural = YES;
438 if (argc > 0 && !JS_ValueToBoolean(context,
OOJS_ARGV[0], &isPlural))
445 string = [UNIVERSE getSystemInhabitants:Ranrot()%OO_SYSTEMS_PER_GALAXY plural:isPlural];
492 jsval callback = JSVAL_NULL;
493 JSObject *callbackThis = NULL;
494 jsval value = JSVAL_NULL;
497 NSDictionary *keydefs = NULL;
498 JSObject *params = NULL;
509 if (argc < 2 || !JS_ValueToObject(context,
OOJS_ARGV[1], ¶ms))
515 if (JS_GetProperty(context, params,
"guiScreen", &value) == JS_FALSE || JSVAL_IS_VOID(value))
523 if (gui == 0 || gui == GUI_SCREEN_LOAD || gui == GUI_SCREEN_SAVE || gui == GUI_SCREEN_STICKMAPPER || gui == GUI_SCREEN_OXZMANAGER ||
524 gui == GUI_SCREEN_NEWGAME || gui == GUI_SCREEN_SAVE_OVERWRITE || gui == GUI_SCREEN_KEYBOARD || gui == GUI_SCREEN_STICKPROFILE || gui == GUI_SCREEN_KEYBOARD_CONFIRMCLEAR ||
525 gui == GUI_SCREEN_KEYBOARD_CONFIG || gui == GUI_SCREEN_KEYBOARD_ENTRY || gui == GUI_SCREEN_KEYBOARD_LAYOUT)
527 OOJSReportBadArguments(context,
@"global",
@"setExtraGuiScreenKeys", 2, &
OOJS_ARGV[1],
nil,
@"key, definition: 'guiScreen' property must be a permitted and valid GUI_SCREEN idenfifier.");
531 if (JS_GetProperty(context, params,
"registerKeys", &value) == JS_FALSE || JSVAL_IS_VOID(value))
536 if (!JSVAL_IS_NULL(value))
538 if (JSVAL_IS_OBJECT(value))
549 if (JS_GetProperty(context, params,
"callback", &callback) == JS_FALSE || JSVAL_IS_VOID(callback))
556 OOJSReportBadArguments(context,
@"global",
@"setExtraGuiScreenKeys", 2, &
OOJS_ARGV[1], NULL,
@"key, definition; 'callback' property must be a function.");
566 if (JS_GetProperty(context, params,
"cbThis", &value) == JS_TRUE && !JSVAL_IS_VOID(value))
568 JS_ValueToObject(context, value, &callbackThis);
574 [definition release];
588 jsval value = (argc > 0) ?
OOJS_ARGV[0] : JSVAL_NULL;
592 OOJSReportWarning(context,
@"Usage error: %@() called with no arguments. Treating as %@(null). This call may fail in a future version of Oolite.",
@"setScreenBackground",
@"setScreenBackground");
600 if ([
UNIVERSE viewDirection] == VIEW_GUI_DISPLAY)
608 if (result && [
PLAYER guiScreen] == GUI_SCREEN_EQUIP_SHIP) [PLAYER setEquipScreenBackgroundDescriptor:descriptor];
632 NSDictionary *descriptor = [UNIVERSE screenTextureDescriptorForKey:key];
663 [UNIVERSE setScreenTextureDescriptorForKey:key descriptor:descriptor];
678 jsval value = (argc > 0) ?
OOJS_ARGV[0] : JSVAL_NULL;
682 OOJSReportWarning(context,
@"Usage error: %@() called with no arguments. Treating as %@(null). This call may fail in a future version of Oolite.",
@"setScreenOverlay",
@"setScreenOverlay");
690 if ([
UNIVERSE viewDirection] == VIEW_GUI_DISPLAY)
719 if ([key rangeOfString:
@"color"].location == NSNotFound)
755 if ([key rangeOfString:
@"color"].location == NSNotFound)
761 if (!JSVAL_IS_NULL(value))
797 jsdouble desiredColorSaturation = 0;
799 if (argc < 1 ||
EXPECT_NOT(!JS_ValueToNumber(context,
OOJS_ARGV[0], &desiredColorSaturation)))
return NO;
817 NSString *value =
nil;
818 NSMutableCharacterSet *allowedChars = (NSMutableCharacterSet *)[NSMutableCharacterSet alphanumericCharacterSet];
821 [allowedChars addCharactersInString:@"_-"];
826 if (
EXPECT_NOT(value ==
nil || [value rangeOfCharacterFromSet:[allowedChars invertedSet]].location != NSNotFound))
833 NSString *playerFileDirectory = [[NSFileManager defaultManager] defaultCommanderPath];
834 NSDictionary *attr = [[NSFileManager defaultManager] oo_fileSystemAttributesAtPath:playerFileDirectory];
838 double freeSpace = [attr oo_doubleForKey:NSFileSystemFreeSize];
839 if (freeSpace < 1073741824)
841 OOJSReportWarning(context,
@"takeSnapShot: function disabled when free disk space is less than 1GB.");
848 result = [[UNIVERSE gameView] snapShot:value];
862 NSString *
string =
nil;
872 NSString *autoAI = [autoAIMap oo_stringForKey:string];
891 if (guiScreen != GUI_SCREEN_LONG_RANGE_CHART &&
892 guiScreen != GUI_SCREEN_MISSION &&
893 guiScreen != GUI_SCREEN_REPORT &&
894 guiScreen != GUI_SCREEN_KEYBOARD_ENTRY &&
895 guiScreen != GUI_SCREEN_SAVE)
897 [UNIVERSE pauseGame];
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)
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)
@ kGlobal_timeAccelerationFactor
static JSBool GlobalGetProperty(JSContext *context, JSObject *this, jsid propID, jsval *value)
void CreateOOJSGlobal(JSContext *context, JSObject **outGlobal)
static JSFunctionSpec sGlobalMethods[]
static JSPropertySpec sGlobalProperties[]
static JSBool GlobalExpandMissionText(JSContext *context, uintN argc, jsval *vp)
static JSBool GlobalSetColorSaturation(JSContext *context, uintN argc, jsval *vp)
static JSClass sGlobalClass
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 GlobalSetProperty(JSContext *context, JSObject *this, jsid propID, JSBool strict, jsval *value)
static JSBool GlobalRandomInhabitantsDescription(JSContext *context, uintN argc, jsval *vp)
static NSString *const kOOLogDebugMessage
static JSBool GlobalTakeSnapShot(JSContext *context, uintN argc, jsval *vp)
void SetUpOOJSGlobal(JSContext *context, JSObject *global)
static JSBool GlobalClearExtraGuiScreenKeys(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 GlobalGetColorSaturation(JSContext *context, uintN argc, jsval *vp)
static JSBool GlobalRandomName(JSContext *context, uintN argc, jsval *vp)
PlayerEntity * OOPlayerForScripting(void)
void OOJSReportWarning(JSContext *context, NSString *format,...)
#define OOJS_PROP_READWRITE_CB
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)
#define OOJS_PROP_READONLY
OOINLINE BOOL OOJSValueIsFunction(JSContext *context, jsval value)
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)
#define OOJS_PROP_READONLY_CB
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,...)
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)
void adjustColorSaturation:(float colorSaturationAdjustment)
OOColor * colorWithDescription:(id description)
void setRegisterKeys:(NSDictionary *registerKeys)
void setCallbackThis:(JSObject *callbackthis)
void setCallback:(jsval callback)
void setName:(NSString *name)
void sendMonitorLogMessage:withMessageClass:inContext:(NSString *message,[withMessageClass] NSString *messageClass,[inContext] JSContext *context)
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)