Work on JavaScript API update: updated all property callbacks.
git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@3850 127b21dd-08f5-0310-b4b7-95ae10353056
This commit is contained in:
parent
75381a4f59
commit
a655c81d87
@ -61,8 +61,8 @@ static JSObject *sConsolePrototype = NULL;
|
||||
static JSObject *sConsoleSettingsPrototype = NULL;
|
||||
|
||||
|
||||
static JSBool ConsoleGetProperty(JSContext *context, JSObject *this, jsval name, jsval *outValue);
|
||||
static JSBool ConsoleSetProperty(JSContext *context, JSObject *this, jsval name, jsval *value);
|
||||
static JSBool ConsoleGetProperty(OOJS_PROP_ARGS);
|
||||
static JSBool ConsoleSetProperty(OOJS_PROP_ARGS);
|
||||
static void ConsoleFinalize(JSContext *context, JSObject *this);
|
||||
|
||||
// Methods
|
||||
@ -83,8 +83,8 @@ static JSBool ConsoleGetProfile(JSContext *context, JSObject *this, uintN argc,
|
||||
#endif
|
||||
|
||||
static JSBool ConsoleSettingsDeleteProperty(JSContext *context, JSObject *this, jsval name, jsval *outValue);
|
||||
static JSBool ConsoleSettingsGetProperty(JSContext *context, JSObject *this, jsval name, jsval *outValue);
|
||||
static JSBool ConsoleSettingsSetProperty(JSContext *context, JSObject *this, jsval name, jsval *value);
|
||||
static JSBool ConsoleSettingsGetProperty(OOJS_PROP_ARGS);
|
||||
static JSBool ConsoleSettingsSetProperty(OOJS_PROP_ARGS);
|
||||
|
||||
#if OOJS_PROFILE
|
||||
static JSBool PerformProfiling(JSContext *context, NSString *nominalFunction, uintN argc, jsval *argv, OOTimeProfile **profile);
|
||||
@ -273,57 +273,57 @@ JSObject *DebugMonitorToJSConsole(JSContext *context, OODebugMonitor *monitor)
|
||||
}
|
||||
|
||||
|
||||
static JSBool ConsoleGetProperty(JSContext *context, JSObject *this, jsval name, jsval *outValue)
|
||||
static JSBool ConsoleGetProperty(OOJS_PROP_ARGS)
|
||||
{
|
||||
if (!JSVAL_IS_INT(name)) return YES;
|
||||
if (!OOJS_PROPID_IS_INT) return YES;
|
||||
|
||||
OOJS_NATIVE_ENTER(context)
|
||||
|
||||
switch (JSVAL_TO_INT(name))
|
||||
switch (OOJS_PROPID_INT)
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
case kConsole_debugFlags:
|
||||
*outValue = INT_TO_JSVAL(gDebugFlags);
|
||||
*value = INT_TO_JSVAL(gDebugFlags);
|
||||
break;
|
||||
#endif
|
||||
|
||||
case kConsole_shaderMode:
|
||||
*outValue = [ShaderSettingToString([UNIVERSE shaderEffectsLevel]) javaScriptValueInContext:context];
|
||||
*value = [ShaderSettingToString([UNIVERSE shaderEffectsLevel]) javaScriptValueInContext:context];
|
||||
break;
|
||||
|
||||
case kConsole_maximumShaderMode:
|
||||
*outValue = [ShaderSettingToString([[OOOpenGLExtensionManager sharedManager] maximumShaderSetting]) javaScriptValueInContext:context];
|
||||
*value = [ShaderSettingToString([[OOOpenGLExtensionManager sharedManager] maximumShaderSetting]) javaScriptValueInContext:context];
|
||||
break;
|
||||
|
||||
case kConsole_reducedDetailMode:
|
||||
*outValue = BOOLToJSVal([UNIVERSE reducedDetail]);
|
||||
*value = BOOLToJSVal([UNIVERSE reducedDetail]);
|
||||
break;
|
||||
|
||||
case kConsole_displayFPS:
|
||||
*outValue = BOOLToJSVal([UNIVERSE displayFPS]);
|
||||
*value = BOOLToJSVal([UNIVERSE displayFPS]);
|
||||
break;
|
||||
|
||||
case kConsole_platformDescription:
|
||||
*outValue = [OOPlatformDescription() javaScriptValueInContext:context];
|
||||
*value = [OOPlatformDescription() javaScriptValueInContext:context];
|
||||
break;
|
||||
|
||||
case kConsole_glVendorString:
|
||||
*outValue = [[[OOOpenGLExtensionManager sharedManager] vendorString] javaScriptValueInContext:context];
|
||||
*value = [[[OOOpenGLExtensionManager sharedManager] vendorString] javaScriptValueInContext:context];
|
||||
break;
|
||||
|
||||
case kConsole_glRendererString:
|
||||
*outValue = [[[OOOpenGLExtensionManager sharedManager] rendererString] javaScriptValueInContext:context];
|
||||
*value = [[[OOOpenGLExtensionManager sharedManager] rendererString] javaScriptValueInContext:context];
|
||||
break;
|
||||
|
||||
case kConsole_glFixedFunctionTextureUnitCount:
|
||||
*outValue = INT_TO_JSVAL([[OOOpenGLExtensionManager sharedManager] textureUnitCount]);
|
||||
*value = INT_TO_JSVAL([[OOOpenGLExtensionManager sharedManager] textureUnitCount]);
|
||||
break;
|
||||
|
||||
case kConsole_glFragmentShaderTextureUnitCount:
|
||||
*outValue = INT_TO_JSVAL([[OOOpenGLExtensionManager sharedManager] textureImageUnitCount]);
|
||||
*value = INT_TO_JSVAL([[OOOpenGLExtensionManager sharedManager] textureImageUnitCount]);
|
||||
break;
|
||||
|
||||
#define DEBUG_FLAG_CASE(x) case kConsole_##x: *outValue = INT_TO_JSVAL(x); break;
|
||||
#define DEBUG_FLAG_CASE(x) case kConsole_##x: *value = INT_TO_JSVAL(x); break;
|
||||
DEBUG_FLAG_CASE(DEBUG_LINKED_LISTS);
|
||||
DEBUG_FLAG_CASE(DEBUG_COLLISIONS);
|
||||
DEBUG_FLAG_CASE(DEBUG_DOCKING);
|
||||
@ -339,7 +339,7 @@ static JSBool ConsoleGetProperty(JSContext *context, JSObject *this, jsval name,
|
||||
#undef DEBUG_FLAG_CASE
|
||||
|
||||
default:
|
||||
OOReportJSBadPropertySelector(context, @"Console", JSVAL_TO_INT(name));
|
||||
OOReportJSBadPropertySelector(context, @"Console", OOJS_PROPID_INT);
|
||||
return NO;
|
||||
}
|
||||
|
||||
@ -349,9 +349,9 @@ static JSBool ConsoleGetProperty(JSContext *context, JSObject *this, jsval name,
|
||||
}
|
||||
|
||||
|
||||
static JSBool ConsoleSetProperty(JSContext *context, JSObject *this, jsval name, jsval *value)
|
||||
static JSBool ConsoleSetProperty(OOJS_PROP_ARGS)
|
||||
{
|
||||
if (!JSVAL_IS_INT(name)) return YES;
|
||||
if (!OOJS_PROPID_IS_INT) return YES;
|
||||
|
||||
OOJS_NATIVE_ENTER(context)
|
||||
|
||||
@ -359,7 +359,7 @@ static JSBool ConsoleSetProperty(JSContext *context, JSObject *this, jsval name,
|
||||
NSString *sValue = nil;
|
||||
JSBool bValue = NO;
|
||||
|
||||
switch (JSVAL_TO_INT(name))
|
||||
switch (OOJS_PROPID_INT)
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
case kConsole_debugFlags:
|
||||
@ -397,7 +397,7 @@ static JSBool ConsoleSetProperty(JSContext *context, JSObject *this, jsval name,
|
||||
break;
|
||||
|
||||
default:
|
||||
OOReportJSBadPropertySelector(context, @"Console", JSVAL_TO_INT(name));
|
||||
OOReportJSBadPropertySelector(context, @"Console", OOJS_PROPID_INT);
|
||||
return NO;
|
||||
}
|
||||
|
||||
@ -450,16 +450,15 @@ static void ConsoleFinalize(JSContext *context, JSObject *this)
|
||||
}
|
||||
|
||||
|
||||
static JSBool ConsoleSettingsDeleteProperty(JSContext *context, JSObject *this, jsval name, jsval *outValue)
|
||||
static JSBool ConsoleSettingsDeleteProperty(OOJS_PROP_ARGS)
|
||||
{
|
||||
OOJS_NATIVE_ENTER(context)
|
||||
|
||||
NSString *key = nil;
|
||||
id monitor = nil;
|
||||
|
||||
if (!JSVAL_IS_STRING(name)) return NO;
|
||||
|
||||
key = [NSString stringWithJavaScriptValue:name inContext:context];
|
||||
if (!OOJS_PROPID_IS_STRING) return NO;
|
||||
key = [NSString stringWithJavaScriptString:OOJS_PROPID_STRING];
|
||||
|
||||
monitor = JSObjectToObject(context, this);
|
||||
if (![monitor isKindOfClass:[OODebugMonitor class]])
|
||||
@ -469,23 +468,23 @@ static JSBool ConsoleSettingsDeleteProperty(JSContext *context, JSObject *this,
|
||||
}
|
||||
|
||||
[monitor setConfigurationValue:nil forKey:key];
|
||||
*outValue = JSVAL_TRUE;
|
||||
*value = JSVAL_TRUE;
|
||||
return YES;
|
||||
|
||||
OOJS_NATIVE_EXIT
|
||||
}
|
||||
|
||||
|
||||
static JSBool ConsoleSettingsGetProperty(JSContext *context, JSObject *this, jsval name, jsval *outValue)
|
||||
static JSBool ConsoleSettingsGetProperty(OOJS_PROP_ARGS)
|
||||
{
|
||||
OOJS_NATIVE_ENTER(context)
|
||||
|
||||
NSString *key = nil;
|
||||
id value = nil;
|
||||
id settingValue = nil;
|
||||
id monitor = nil;
|
||||
|
||||
if (!JSVAL_IS_STRING(name)) return YES;
|
||||
key = [NSString stringWithJavaScriptValue:name inContext:context];
|
||||
if (!OOJS_PROPID_IS_STRING) return YES;
|
||||
key = [NSString stringWithJavaScriptString:OOJS_PROPID_STRING];
|
||||
|
||||
monitor = JSObjectToObject(context, this);
|
||||
if (![monitor isKindOfClass:[OODebugMonitor class]])
|
||||
@ -494,8 +493,8 @@ static JSBool ConsoleSettingsGetProperty(JSContext *context, JSObject *this, jsv
|
||||
return NO;
|
||||
}
|
||||
|
||||
value = [monitor configurationValueForKey:key];
|
||||
*outValue = [value javaScriptValueInContext:context];
|
||||
settingValue = [monitor configurationValueForKey:key];
|
||||
*value = [settingValue javaScriptValueInContext:context];
|
||||
|
||||
return YES;
|
||||
|
||||
@ -503,16 +502,16 @@ static JSBool ConsoleSettingsGetProperty(JSContext *context, JSObject *this, jsv
|
||||
}
|
||||
|
||||
|
||||
static JSBool ConsoleSettingsSetProperty(JSContext *context, JSObject *this, jsval name, jsval *inValue)
|
||||
static JSBool ConsoleSettingsSetProperty(OOJS_PROP_ARGS)
|
||||
{
|
||||
OOJS_NATIVE_ENTER(context)
|
||||
|
||||
NSString *key = nil;
|
||||
id value = nil;
|
||||
id settingValue = nil;
|
||||
id monitor = nil;
|
||||
|
||||
if (!JSVAL_IS_STRING(name)) return YES;
|
||||
key = [NSString stringWithJavaScriptValue:name inContext:context];
|
||||
if (!OOJS_PROPID_IS_STRING) return YES;
|
||||
key = [NSString stringWithJavaScriptString:OOJS_PROPID_STRING];
|
||||
|
||||
monitor = JSObjectToObject(context, this);
|
||||
if (![monitor isKindOfClass:[OODebugMonitor class]])
|
||||
@ -522,20 +521,20 @@ static JSBool ConsoleSettingsSetProperty(JSContext *context, JSObject *this, jsv
|
||||
}
|
||||
|
||||
OOJSPauseTimeLimiter();
|
||||
if (JSVAL_IS_NULL(*inValue) || JSVAL_IS_VOID(*inValue))
|
||||
if (JSVAL_IS_NULL(*value) || JSVAL_IS_VOID(*value))
|
||||
{
|
||||
[monitor setConfigurationValue:nil forKey:key];
|
||||
}
|
||||
else
|
||||
{
|
||||
value = JSValueToObject(context, *inValue);
|
||||
if (value != nil)
|
||||
settingValue = JSValueToObject(context, *value);
|
||||
if (settingValue != nil)
|
||||
{
|
||||
[monitor setConfigurationValue:value forKey:key];
|
||||
[monitor setConfigurationValue:settingValue forKey:key];
|
||||
}
|
||||
else
|
||||
{
|
||||
OOReportJSWarning(context, @"debugConsole.settings: could not convert %@ to native object.", [NSString stringWithJavaScriptValue:*inValue inContext:context]);
|
||||
OOReportJSWarning(context, @"debugConsole.settings: could not convert %@ to native object.", [NSString stringWithJavaScriptValue:*value inContext:context]);
|
||||
}
|
||||
}
|
||||
OOJSResumeTimeLimiter();
|
||||
|
@ -32,7 +32,7 @@ MA 02110-1301, USA.
|
||||
#import "OOStringParsing.h"
|
||||
|
||||
|
||||
static JSBool ClockGetProperty(JSContext *context, JSObject *this, jsval name, jsval *outValue);
|
||||
static JSBool ClockGetProperty(OOJS_PROP_ARGS);
|
||||
|
||||
// Methods
|
||||
static JSBool JSClockToString(JSContext *context, JSObject *this, uintN argc, jsval *argv, jsval *outResult);
|
||||
@ -111,9 +111,9 @@ void InitOOJSClock(JSContext *context, JSObject *global)
|
||||
}
|
||||
|
||||
|
||||
static JSBool ClockGetProperty(JSContext *context, JSObject *this, jsval name, jsval *outValue)
|
||||
static JSBool ClockGetProperty(OOJS_PROP_ARGS)
|
||||
{
|
||||
if (!JSVAL_IS_INT(name)) return YES;
|
||||
if (!OOJS_PROPID_IS_INT) return YES;
|
||||
|
||||
OOJS_NATIVE_ENTER(context)
|
||||
|
||||
@ -124,61 +124,61 @@ static JSBool ClockGetProperty(JSContext *context, JSObject *this, jsval name, j
|
||||
player = OOPlayerForScripting();
|
||||
clockTime = [player clockTime];
|
||||
|
||||
switch (JSVAL_TO_INT(name))
|
||||
switch (OOJS_PROPID_INT)
|
||||
{
|
||||
case kClock_absoluteSeconds:
|
||||
OK = JS_NewDoubleValue(context, [UNIVERSE getTime], outValue);
|
||||
OK = JS_NewDoubleValue(context, [UNIVERSE getTime], value);
|
||||
break;
|
||||
|
||||
case kClock_seconds:
|
||||
OK = JS_NewDoubleValue(context, clockTime, outValue);
|
||||
OK = JS_NewDoubleValue(context, clockTime, value);
|
||||
break;
|
||||
|
||||
case kClock_minutes:
|
||||
OK = JS_NewDoubleValue(context, floor(clockTime / 60.0), outValue);
|
||||
OK = JS_NewDoubleValue(context, floor(clockTime / 60.0), value);
|
||||
break;
|
||||
|
||||
case kClock_hours:
|
||||
OK = JS_NewDoubleValue(context, floor(clockTime / 3600.0), outValue);
|
||||
OK = JS_NewDoubleValue(context, floor(clockTime / 3600.0), value);
|
||||
break;
|
||||
|
||||
case kClock_secondsComponent:
|
||||
*outValue = INT_TO_JSVAL(fmod(clockTime, 60.0));
|
||||
*value = INT_TO_JSVAL(fmod(clockTime, 60.0));
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kClock_minutesComponent:
|
||||
*outValue = INT_TO_JSVAL(fmod(floor(clockTime / 60.0), 60.0));
|
||||
*value = INT_TO_JSVAL(fmod(floor(clockTime / 60.0), 60.0));
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kClock_hoursComponent:
|
||||
*outValue = INT_TO_JSVAL(fmod(floor(clockTime / 3600.0), 24.0));
|
||||
*value = INT_TO_JSVAL(fmod(floor(clockTime / 3600.0), 24.0));
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kClock_days:
|
||||
case kClock_daysComponent:
|
||||
*outValue = INT_TO_JSVAL(floor(clockTime / 86400.0));
|
||||
*value = INT_TO_JSVAL(floor(clockTime / 86400.0));
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kClock_clockString:
|
||||
*outValue = [[player dial_clock] javaScriptValueInContext:context];
|
||||
*value = [[player dial_clock] javaScriptValueInContext:context];
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kClock_isAdjusting:
|
||||
*outValue = BOOLToJSVal([player clockAdjusting]);
|
||||
*value = BOOLToJSVal([player clockAdjusting]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kClock_legacy_scriptTimer:
|
||||
OK = JS_NewDoubleValue(context, [OOPlayerForScripting() scriptTimer], outValue);
|
||||
OK = JS_NewDoubleValue(context, [OOPlayerForScripting() scriptTimer], value);
|
||||
break;
|
||||
|
||||
default:
|
||||
OOReportJSBadPropertySelector(context, @"Clock", JSVAL_TO_INT(name));
|
||||
OOReportJSBadPropertySelector(context, @"Clock", OOJS_PROPID_INT);
|
||||
}
|
||||
|
||||
return OK;
|
||||
|
@ -38,8 +38,8 @@ MA 02110-1301, USA.
|
||||
static JSObject *sEntityPrototype;
|
||||
|
||||
|
||||
static JSBool EntityGetProperty(JSContext *context, JSObject *this, jsval name, jsval *outValue);
|
||||
static JSBool EntitySetProperty(JSContext *context, JSObject *this, jsval name, jsval *value);
|
||||
static JSBool EntityGetProperty(OOJS_PROP_ARGS);
|
||||
static JSBool EntitySetProperty(OOJS_PROP_ARGS);
|
||||
|
||||
|
||||
static JSClass sEntityClass =
|
||||
@ -179,9 +179,9 @@ BOOL EntityFromArgumentList(JSContext *context, NSString *scriptClass, NSString
|
||||
}
|
||||
|
||||
|
||||
static JSBool EntityGetProperty(JSContext *context, JSObject *this, jsval name, jsval *outValue)
|
||||
static JSBool EntityGetProperty(OOJS_PROP_ARGS)
|
||||
{
|
||||
if (!JSVAL_IS_INT(name)) return YES;
|
||||
if (!OOJS_PROPID_IS_INT) return YES;
|
||||
|
||||
OOJS_NATIVE_ENTER(context)
|
||||
|
||||
@ -192,28 +192,28 @@ static JSBool EntityGetProperty(JSContext *context, JSObject *this, jsval name,
|
||||
JSEntityGetEntity(context, this, &entity);
|
||||
if (entity == nil)
|
||||
{
|
||||
if (JSVAL_TO_INT(name) == kEntity_isValid) *outValue = JSVAL_FALSE;
|
||||
else *outValue = JSVAL_VOID;
|
||||
if (OOJS_PROPID_INT == kEntity_isValid) *value = JSVAL_FALSE;
|
||||
else *value = JSVAL_VOID;
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
switch (JSVAL_TO_INT(name))
|
||||
switch (OOJS_PROPID_INT)
|
||||
{
|
||||
case kEntity_collisionRadius:
|
||||
OK = JS_NewDoubleValue(context, [entity collisionRadius], outValue);
|
||||
OK = JS_NewDoubleValue(context, [entity collisionRadius], value);
|
||||
break;
|
||||
|
||||
case kEntity_position:
|
||||
OK = VectorToJSValue(context, [entity position], outValue);
|
||||
OK = VectorToJSValue(context, [entity position], value);
|
||||
break;
|
||||
|
||||
case kEntity_orientation:
|
||||
OK = QuaternionToJSValue(context, [entity normalOrientation], outValue);
|
||||
OK = QuaternionToJSValue(context, [entity normalOrientation], value);
|
||||
break;
|
||||
|
||||
case kEntity_heading:
|
||||
OK = VectorToJSValue(context, vector_forward_from_quaternion([entity normalOrientation]), outValue);
|
||||
OK = VectorToJSValue(context, vector_forward_from_quaternion([entity normalOrientation]), value);
|
||||
break;
|
||||
|
||||
case kEntity_status:
|
||||
@ -225,7 +225,7 @@ static JSBool EntityGetProperty(JSContext *context, JSObject *this, jsval name,
|
||||
break;
|
||||
|
||||
case kEntity_mass:
|
||||
OK = JS_NewDoubleValue(context, [entity mass], outValue);
|
||||
OK = JS_NewDoubleValue(context, [entity mass], value);
|
||||
break;
|
||||
|
||||
case kEntity_owner:
|
||||
@ -235,63 +235,63 @@ static JSBool EntityGetProperty(JSContext *context, JSObject *this, jsval name,
|
||||
break;
|
||||
|
||||
case kEntity_energy:
|
||||
OK = JS_NewDoubleValue(context, [entity energy], outValue);
|
||||
OK = JS_NewDoubleValue(context, [entity energy], value);
|
||||
break;
|
||||
|
||||
case kEntity_maxEnergy:
|
||||
OK = JS_NewDoubleValue(context, [entity maxEnergy], outValue);
|
||||
OK = JS_NewDoubleValue(context, [entity maxEnergy], value);
|
||||
break;
|
||||
|
||||
case kEntity_isValid:
|
||||
*outValue = JSVAL_TRUE;
|
||||
*value = JSVAL_TRUE;
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kEntity_isShip:
|
||||
*outValue = BOOLToJSVal([entity isShip]);
|
||||
*value = BOOLToJSVal([entity isShip]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kEntity_isStation:
|
||||
*outValue = BOOLToJSVal([entity isStation]);
|
||||
*value = BOOLToJSVal([entity isStation]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kEntity_isSubEntity:
|
||||
*outValue = BOOLToJSVal([entity isSubEntity]);
|
||||
*value = BOOLToJSVal([entity isSubEntity]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kEntity_isPlayer:
|
||||
*outValue = BOOLToJSVal([entity isPlayer]);
|
||||
*value = BOOLToJSVal([entity isPlayer]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kEntity_isPlanet:
|
||||
*outValue = BOOLToJSVal([entity isPlanet] && ![entity isSun]);
|
||||
*value = BOOLToJSVal([entity isPlanet] && ![entity isSun]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kEntity_isSun:
|
||||
*outValue = BOOLToJSVal([entity isSun]);
|
||||
*value = BOOLToJSVal([entity isSun]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kEntity_distanceTravelled:
|
||||
OK = JS_NewDoubleValue(context, [entity distanceTravelled], outValue);
|
||||
OK = JS_NewDoubleValue(context, [entity distanceTravelled], value);
|
||||
break;
|
||||
|
||||
case kEntity_spawnTime:
|
||||
OK = JS_NewDoubleValue(context, [entity spawnTime], outValue);
|
||||
OK = JS_NewDoubleValue(context, [entity spawnTime], value);
|
||||
break;
|
||||
|
||||
default:
|
||||
OOReportJSBadPropertySelector(context, @"Entity", JSVAL_TO_INT(name));
|
||||
OOReportJSBadPropertySelector(context, @"Entity", OOJS_PROPID_INT);
|
||||
}
|
||||
|
||||
if (result != nil)
|
||||
{
|
||||
*outValue = [result javaScriptValueInContext:context];
|
||||
*value = [result javaScriptValueInContext:context];
|
||||
OK = YES;
|
||||
}
|
||||
return OK;
|
||||
@ -300,9 +300,9 @@ static JSBool EntityGetProperty(JSContext *context, JSObject *this, jsval name,
|
||||
}
|
||||
|
||||
|
||||
static JSBool EntitySetProperty(JSContext *context, JSObject *this, jsval name, jsval *value)
|
||||
static JSBool EntitySetProperty(OOJS_PROP_ARGS)
|
||||
{
|
||||
if (!JSVAL_IS_INT(name)) return YES;
|
||||
if (!OOJS_PROPID_IS_INT) return YES;
|
||||
|
||||
OOJS_NATIVE_ENTER(context)
|
||||
|
||||
@ -314,7 +314,7 @@ static JSBool EntitySetProperty(JSContext *context, JSObject *this, jsval name,
|
||||
|
||||
if (EXPECT_NOT(!JSEntityGetEntity(context, this, &entity))) return NO;
|
||||
|
||||
switch (JSVAL_TO_INT(name))
|
||||
switch (OOJS_PROPID_INT)
|
||||
{
|
||||
case kEntity_position:
|
||||
if (JSValueToVector(context, *value, &vValue))
|
||||
@ -343,7 +343,7 @@ static JSBool EntitySetProperty(JSContext *context, JSObject *this, jsval name,
|
||||
break;
|
||||
|
||||
default:
|
||||
OOReportJSBadPropertySelector(context, @"Entity", JSVAL_TO_INT(name));
|
||||
OOReportJSBadPropertySelector(context, @"Entity", OOJS_PROPID_INT);
|
||||
}
|
||||
|
||||
return OK;
|
||||
|
@ -32,7 +32,7 @@ MA 02110-1301, USA.
|
||||
static JSObject *sEquipmentInfoPrototype;
|
||||
|
||||
|
||||
static JSBool EquipmentInfoGetProperty(JSContext *context, JSObject *this, jsval name, jsval *outValue);
|
||||
static JSBool EquipmentInfoGetProperty(OOJS_PROP_ARGS);
|
||||
static JSBool EquipmentInfoSetProperty(JSContext *context, JSObject *this, jsval name, jsval *outValue);
|
||||
|
||||
static JSBool EquipmentInfoGetAllEqipment(JSContext *context, JSObject *this, jsval name, jsval *outValue);
|
||||
@ -200,9 +200,9 @@ NSString *JSValueToEquipmentKeyRelaxed(JSContext *context, jsval value, BOOL *ou
|
||||
|
||||
// *** Implementation stuff ***
|
||||
|
||||
static JSBool EquipmentInfoGetProperty(JSContext *context, JSObject *this, jsval name, jsval *outValue)
|
||||
static JSBool EquipmentInfoGetProperty(OOJS_PROP_ARGS)
|
||||
{
|
||||
if (!JSVAL_IS_INT(name)) return YES;
|
||||
if (!OOJS_PROPID_IS_INT) return YES;
|
||||
|
||||
OOJS_NATIVE_ENTER(context)
|
||||
|
||||
@ -212,7 +212,7 @@ static JSBool EquipmentInfoGetProperty(JSContext *context, JSObject *this, jsval
|
||||
eqType = JSObjectToObjectOfClass(context, this, [OOEquipmentType class]);
|
||||
if (EXPECT_NOT(eqType == nil)) return NO;
|
||||
|
||||
switch (JSVAL_TO_INT(name))
|
||||
switch (OOJS_PROPID_INT)
|
||||
{
|
||||
case kEquipmentInfo_equipmentKey:
|
||||
result = [eqType identifier];
|
||||
@ -223,11 +223,11 @@ static JSBool EquipmentInfoGetProperty(JSContext *context, JSObject *this, jsval
|
||||
break;
|
||||
|
||||
case kEquipmentInfo_canCarryMultiple:
|
||||
*outValue = BOOLToJSVal([eqType canCarryMultiple]);
|
||||
*value = BOOLToJSVal([eqType canCarryMultiple]);
|
||||
break;
|
||||
|
||||
case kEquipmentInfo_canBeDamaged:
|
||||
*outValue = BOOLToJSVal([eqType canBeDamaged]);
|
||||
*value = BOOLToJSVal([eqType canBeDamaged]);
|
||||
break;
|
||||
|
||||
case kEquipmentInfo_description:
|
||||
@ -235,71 +235,71 @@ static JSBool EquipmentInfoGetProperty(JSContext *context, JSObject *this, jsval
|
||||
break;
|
||||
|
||||
case kEquipmentInfo_techLevel:
|
||||
*outValue = INT_TO_JSVAL([eqType techLevel]);
|
||||
*value = INT_TO_JSVAL([eqType techLevel]);
|
||||
break;
|
||||
|
||||
case kEquipmentInfo_effectiveTechLevel:
|
||||
*outValue = INT_TO_JSVAL([eqType effectiveTechLevel]);
|
||||
*value = INT_TO_JSVAL([eqType effectiveTechLevel]);
|
||||
break;
|
||||
|
||||
case kEquipmentInfo_price:
|
||||
*outValue = INT_TO_JSVAL([eqType price]);
|
||||
*value = INT_TO_JSVAL([eqType price]);
|
||||
break;
|
||||
|
||||
case kEquipmentInfo_isAvailableToAll:
|
||||
*outValue = BOOLToJSVal([eqType isAvailableToAll]);
|
||||
*value = BOOLToJSVal([eqType isAvailableToAll]);
|
||||
break;
|
||||
|
||||
case kEquipmentInfo_isAvailableToNPCs:
|
||||
*outValue = BOOLToJSVal([eqType isAvailableToNPCs]);
|
||||
*value = BOOLToJSVal([eqType isAvailableToNPCs]);
|
||||
break;
|
||||
|
||||
case kEquipmentInfo_isAvailableToPlayer:
|
||||
*outValue = BOOLToJSVal([eqType isAvailableToPlayer]);
|
||||
*value = BOOLToJSVal([eqType isAvailableToPlayer]);
|
||||
break;
|
||||
|
||||
case kEquipmentInfo_requiresEmptyPylon:
|
||||
*outValue = BOOLToJSVal([eqType requiresEmptyPylon]);
|
||||
*value = BOOLToJSVal([eqType requiresEmptyPylon]);
|
||||
break;
|
||||
|
||||
case kEquipmentInfo_requiresMountedPylon:
|
||||
*outValue = BOOLToJSVal([eqType requiresMountedPylon]);
|
||||
*value = BOOLToJSVal([eqType requiresMountedPylon]);
|
||||
break;
|
||||
|
||||
case kEquipmentInfo_requiresCleanLegalRecord:
|
||||
*outValue = BOOLToJSVal([eqType requiresCleanLegalRecord]);
|
||||
*value = BOOLToJSVal([eqType requiresCleanLegalRecord]);
|
||||
break;
|
||||
|
||||
case kEquipmentInfo_requiresNonCleanLegalRecord:
|
||||
*outValue = BOOLToJSVal([eqType requiresNonCleanLegalRecord]);
|
||||
*value = BOOLToJSVal([eqType requiresNonCleanLegalRecord]);
|
||||
break;
|
||||
|
||||
case kEquipmentInfo_requiresFreePassengerBerth:
|
||||
*outValue = BOOLToJSVal([eqType requiresFreePassengerBerth]);
|
||||
*value = BOOLToJSVal([eqType requiresFreePassengerBerth]);
|
||||
break;
|
||||
|
||||
case kEquipmentInfo_requiresFullFuel:
|
||||
*outValue = BOOLToJSVal([eqType requiresFullFuel]);
|
||||
*value = BOOLToJSVal([eqType requiresFullFuel]);
|
||||
break;
|
||||
|
||||
case kEquipmentInfo_requiresNonFullFuel:
|
||||
*outValue = BOOLToJSVal([eqType requiresNonFullFuel]);
|
||||
*value = BOOLToJSVal([eqType requiresNonFullFuel]);
|
||||
break;
|
||||
|
||||
case kEquipmentInfo_isExternalStore:
|
||||
*outValue = BOOLToJSVal([eqType isMissileOrMine]);
|
||||
*value = BOOLToJSVal([eqType isMissileOrMine]);
|
||||
break;
|
||||
|
||||
case kEquipmentInfo_isPortableBetweenShips:
|
||||
*outValue = BOOLToJSVal([eqType isPortableBetweenShips]);
|
||||
*value = BOOLToJSVal([eqType isPortableBetweenShips]);
|
||||
break;
|
||||
|
||||
case kEquipmentInfo_isVisible:
|
||||
*outValue = BOOLToJSVal([eqType isVisible]);
|
||||
*value = BOOLToJSVal([eqType isVisible]);
|
||||
break;
|
||||
|
||||
case kEquipmentInfo_requiredCargoSpace:
|
||||
*outValue = BOOLToJSVal([eqType requiredCargoSpace]);
|
||||
*value = BOOLToJSVal([eqType requiredCargoSpace]);
|
||||
break;
|
||||
|
||||
case kEquipmentInfo_requiresEquipment:
|
||||
@ -325,13 +325,13 @@ static JSBool EquipmentInfoGetProperty(JSContext *context, JSObject *this, jsval
|
||||
break;
|
||||
|
||||
default:
|
||||
OOReportJSBadPropertySelector(context, @"EquipmentInfo", JSVAL_TO_INT(name));
|
||||
OOReportJSBadPropertySelector(context, @"EquipmentInfo", OOJS_PROPID_INT);
|
||||
return NO;
|
||||
}
|
||||
|
||||
if (result != nil)
|
||||
{
|
||||
*outValue = [result javaScriptValueInContext:context];
|
||||
*value = [result javaScriptValueInContext:context];
|
||||
}
|
||||
return YES;
|
||||
|
||||
@ -339,9 +339,9 @@ static JSBool EquipmentInfoGetProperty(JSContext *context, JSObject *this, jsval
|
||||
}
|
||||
|
||||
|
||||
static JSBool EquipmentInfoSetProperty(JSContext *context, JSObject *this, jsval name, jsval *value)
|
||||
static JSBool EquipmentInfoSetProperty(OOJS_PROP_ARGS)
|
||||
{
|
||||
if (!JSVAL_IS_INT(name)) return YES;
|
||||
if (!OOJS_PROPID_IS_INT) return YES;
|
||||
|
||||
OOJS_NATIVE_ENTER(context)
|
||||
|
||||
@ -352,7 +352,7 @@ static JSBool EquipmentInfoSetProperty(JSContext *context, JSObject *this, jsval
|
||||
eqType = JSObjectToObjectOfClass(context, this, [OOEquipmentType class]);
|
||||
if (EXPECT_NOT(eqType == nil)) return NO;
|
||||
|
||||
switch (JSVAL_TO_INT(name))
|
||||
switch (OOJS_PROPID_INT)
|
||||
{
|
||||
case kEquipmentInfo_effectiveTechLevel:
|
||||
if ([eqType techLevel] != kOOVariableTechLevel) return YES; // Only TL-99 items can be modified in this way
|
||||
@ -375,7 +375,7 @@ static JSBool EquipmentInfoSetProperty(JSContext *context, JSObject *this, jsval
|
||||
break;
|
||||
|
||||
default:
|
||||
OOReportJSBadPropertySelector(context, @"EquipmentInfo", JSVAL_TO_INT(name));
|
||||
OOReportJSBadPropertySelector(context, @"EquipmentInfo", OOJS_PROPID_INT);
|
||||
}
|
||||
|
||||
return OK;
|
||||
|
@ -54,8 +54,8 @@ MA 02110-1301, USA.
|
||||
extern NSString * const kOOLogDebugMessage;
|
||||
|
||||
|
||||
static JSBool GlobalGetProperty(JSContext *context, JSObject *this, jsval name, jsval *outValue);
|
||||
static JSBool GlobalSetProperty(JSContext *context, JSObject *this, jsval name, jsval *value);
|
||||
static JSBool GlobalGetProperty(OOJS_PROP_ARGS);
|
||||
static JSBool GlobalSetProperty(OOJS_PROP_ARGS);
|
||||
|
||||
static JSBool GlobalLog(JSContext *context, JSObject *this, uintN argc, jsval *argv, jsval *outResult);
|
||||
static JSBool GlobalExpandDescription(JSContext *context, JSObject *this, uintN argc, jsval *argv, jsval *outResult);
|
||||
@ -136,19 +136,19 @@ void SetUpOOJSGlobal(JSContext *context, JSObject *global)
|
||||
}
|
||||
|
||||
|
||||
static JSBool GlobalGetProperty(JSContext *context, JSObject *this, jsval name, jsval *outValue)
|
||||
static JSBool GlobalGetProperty(OOJS_PROP_ARGS)
|
||||
{
|
||||
if (!JSVAL_IS_INT(name)) return YES;
|
||||
if (!OOJS_PROPID_IS_INT) return YES;
|
||||
|
||||
OOJS_NATIVE_ENTER(context)
|
||||
|
||||
PlayerEntity *player = OOPlayerForScripting();
|
||||
id result = nil;
|
||||
|
||||
switch (JSVAL_TO_INT(name))
|
||||
switch (OOJS_PROPID_INT)
|
||||
{
|
||||
case kGlobal_galaxyNumber:
|
||||
*outValue = INT_TO_JSVAL([player currentGalaxyID]);
|
||||
*value = INT_TO_JSVAL([player currentGalaxyID]);
|
||||
break;
|
||||
|
||||
case kGlobal_guiScreen:
|
||||
@ -156,31 +156,31 @@ static JSBool GlobalGetProperty(JSContext *context, JSObject *this, jsval name,
|
||||
break;
|
||||
|
||||
case kGlobal_timeAccelerationFactor:
|
||||
JS_NewDoubleValue(context, [UNIVERSE timeAccelerationFactor], outValue);
|
||||
JS_NewDoubleValue(context, [UNIVERSE timeAccelerationFactor], value);
|
||||
break;
|
||||
|
||||
default:
|
||||
OOReportJSBadPropertySelector(context, @"Global", JSVAL_TO_INT(name));
|
||||
OOReportJSBadPropertySelector(context, @"Global", OOJS_PROPID_INT);
|
||||
return NO;
|
||||
}
|
||||
|
||||
if (result != nil) *outValue = [result javaScriptValueInContext:context];
|
||||
if (result != nil) *value = [result javaScriptValueInContext:context];
|
||||
return YES;
|
||||
|
||||
OOJS_NATIVE_EXIT
|
||||
}
|
||||
|
||||
|
||||
static JSBool GlobalSetProperty(JSContext *context, JSObject *this, jsval name, jsval *value)
|
||||
static JSBool GlobalSetProperty(OOJS_PROP_ARGS)
|
||||
{
|
||||
if (!JSVAL_IS_INT(name)) return YES;
|
||||
if (!OOJS_PROPID_IS_INT) return YES;
|
||||
|
||||
OOJS_NATIVE_ENTER(context)
|
||||
|
||||
BOOL OK = NO;
|
||||
jsdouble fValue;
|
||||
|
||||
switch (JSVAL_TO_INT(name))
|
||||
switch (OOJS_PROPID_INT)
|
||||
{
|
||||
case kGlobal_timeAccelerationFactor:
|
||||
if (JS_ValueToNumber(context, *value, &fValue))
|
||||
@ -191,7 +191,7 @@ static JSBool GlobalSetProperty(JSContext *context, JSObject *this, jsval name,
|
||||
break;
|
||||
|
||||
default:
|
||||
OOReportJSBadPropertySelector(context, @"Global", JSVAL_TO_INT(name));
|
||||
OOReportJSBadPropertySelector(context, @"Global", OOJS_PROPID_INT);
|
||||
}
|
||||
|
||||
return OK;
|
||||
|
@ -38,9 +38,9 @@ static JSObject *sManifestObject;
|
||||
|
||||
|
||||
|
||||
static JSBool ManifestDeleteProperty(JSContext *context, JSObject *this, jsval name, jsval *value);
|
||||
static JSBool ManifestGetProperty(JSContext *context, JSObject *this, jsval name, jsval *outValue);
|
||||
static JSBool ManifestSetProperty(JSContext *context, JSObject *this, jsval name, jsval *value);
|
||||
static JSBool ManifestDeleteProperty(OOJS_PROP_ARGS);
|
||||
static JSBool ManifestGetProperty(OOJS_PROP_ARGS);
|
||||
static JSBool ManifestSetProperty(OOJS_PROP_ARGS);
|
||||
|
||||
static JSBool ManifestToString(JSContext *context, JSObject *this, uintN argc, jsval *argv, jsval *outResult);
|
||||
|
||||
@ -134,7 +134,7 @@ static JSPropertySpec sManifestProperties[] =
|
||||
};
|
||||
|
||||
|
||||
static int sManifestCaseInsensitiveLimit = kManifest_gemstones + 1;
|
||||
static const unsigned kManifestCaseInsensitiveLimit = kManifest_gemstones + 1;
|
||||
|
||||
|
||||
static JSFunctionSpec sManifestMethods[] =
|
||||
@ -145,6 +145,9 @@ static JSFunctionSpec sManifestMethods[] =
|
||||
};
|
||||
|
||||
|
||||
static NSDictionary *sManifestNameMap;
|
||||
|
||||
|
||||
// Helper class wrapped by JS Manifest objects
|
||||
@interface OOManifest: NSObject
|
||||
|
||||
@ -197,6 +200,18 @@ void InitOOJSManifest(JSContext *context, JSObject *global)
|
||||
|
||||
// Also define manifest object as a property of the global object.
|
||||
JS_DefineObject(context, global, "manifest", &sManifestClass, sManifestPrototype, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT);
|
||||
|
||||
// Create dictionary mapping commodity names to tinyids.
|
||||
NSMutableDictionary *manifestNameMap = [NSMutableDictionary dictionaryWithCapacity:kManifestCaseInsensitiveLimit];
|
||||
unsigned i;
|
||||
for (i = 0; i < kManifestCaseInsensitiveLimit; i++)
|
||||
{
|
||||
NSString *key = [NSString stringWithUTF8String:sManifestProperties[i].name];
|
||||
NSNumber *value = [NSNumber numberWithInt:sManifestProperties[i].tinyid];
|
||||
[manifestNameMap setObject:value forKey:key];
|
||||
}
|
||||
|
||||
sManifestNameMap = [[NSMutableDictionary alloc] initWithDictionary:manifestNameMap];
|
||||
}
|
||||
|
||||
|
||||
@ -207,34 +222,55 @@ static JSBool ManifestDeleteProperty(JSContext *context, JSObject *this, jsval n
|
||||
}
|
||||
|
||||
|
||||
static JSBool ManifestGetProperty(JSContext *context, JSObject *this, jsval name, jsval *outValue)
|
||||
#if OO_NEW_JS
|
||||
typedef jsid PropertyID;
|
||||
#define PROP_IS_INT JSID_IS_INT
|
||||
#define PROP_TO_INT JSID_TO_INT
|
||||
#define PROP_IS_STRING JSID_IS_STRING
|
||||
#define PROP_TO_STRING JSID_TO_STRING
|
||||
#else
|
||||
typedef jsval PropertyID;
|
||||
#define PROP_IS_INT JSVAL_IS_INT
|
||||
#define PROP_TO_INT JSVAL_TO_INT
|
||||
#define PROP_IS_STRING JSVAL_IS_STRING
|
||||
#define PROP_TO_STRING JSVAL_TO_STRING
|
||||
#endif
|
||||
|
||||
static BOOL GetCommodityID(PropertyID property, unsigned *outCommodity)
|
||||
{
|
||||
NSCParameterAssert(outCommodity != NULL);
|
||||
|
||||
if (PROP_IS_INT(property))
|
||||
{
|
||||
*outCommodity = PROP_TO_INT(property);
|
||||
return *outCommodity < kManifestCaseInsensitiveLimit;
|
||||
}
|
||||
else if (PROP_IS_STRING(property))
|
||||
{
|
||||
NSString *key = [[NSString stringWithJavaScriptString:PROP_TO_STRING(property)] lowercaseString];
|
||||
NSNumber *value = [sManifestNameMap objectForKey:key];
|
||||
if (value == nil) return NO;
|
||||
|
||||
*outCommodity = [value intValue];
|
||||
return YES;
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
|
||||
static JSBool ManifestGetProperty(OOJS_PROP_ARGS)
|
||||
{
|
||||
OOJS_NATIVE_ENTER(context)
|
||||
|
||||
BOOL OK = NO;
|
||||
id result = nil;
|
||||
PlayerEntity *entity = OOPlayerForScripting();
|
||||
unsigned commodity;
|
||||
|
||||
if (JSVAL_IS_STRING(name)) // Is it a case insensitive commodity identifier?
|
||||
{
|
||||
//FIXME: there must be a better way of doing this.
|
||||
const char *str = [[[NSString stringWithJavaScriptValue:name inContext:context] lowercaseString] UTF8String];
|
||||
int i;
|
||||
|
||||
for (i=0; i<sManifestCaseInsensitiveLimit; i++)
|
||||
{
|
||||
if (strcmp(sManifestProperties[i].name, str) == 0)
|
||||
{
|
||||
name = INT_TO_JSVAL(sManifestProperties[i].tinyid);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!JSVAL_IS_INT(name)) return YES;
|
||||
//if (EXPECT_NOT(!JSShipGetShipEntity(context, this, &entity))) return NO; // NOTE: to be added if we get NPCs with manifests.
|
||||
if (!GetCommodityID(propID, &commodity)) return YES;
|
||||
|
||||
switch (JSVAL_TO_INT(name))
|
||||
switch (commodity)
|
||||
{
|
||||
case kManifest_list:
|
||||
result = [entity cargoListForScripting];
|
||||
@ -242,136 +278,118 @@ static JSBool ManifestGetProperty(JSContext *context, JSObject *this, jsval name
|
||||
break;
|
||||
|
||||
case kManifest_food:
|
||||
*outValue = INT_TO_JSVAL([entity cargoQuantityForType:COMMODITY_FOOD]);
|
||||
*value = INT_TO_JSVAL([entity cargoQuantityForType:COMMODITY_FOOD]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kManifest_textiles:
|
||||
*outValue = INT_TO_JSVAL([entity cargoQuantityForType:COMMODITY_TEXTILES]);
|
||||
*value = INT_TO_JSVAL([entity cargoQuantityForType:COMMODITY_TEXTILES]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kManifest_radioactives:
|
||||
*outValue = INT_TO_JSVAL([entity cargoQuantityForType:COMMODITY_RADIOACTIVES]);
|
||||
*value = INT_TO_JSVAL([entity cargoQuantityForType:COMMODITY_RADIOACTIVES]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kManifest_slaves:
|
||||
*outValue = INT_TO_JSVAL([entity cargoQuantityForType:COMMODITY_SLAVES]);
|
||||
*value = INT_TO_JSVAL([entity cargoQuantityForType:COMMODITY_SLAVES]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kManifest_liquor_wines:
|
||||
case kManifest_liquorwines:
|
||||
case kManifest_liquorWines:
|
||||
*outValue = INT_TO_JSVAL([entity cargoQuantityForType:COMMODITY_LIQUOR_WINES]);
|
||||
*value = INT_TO_JSVAL([entity cargoQuantityForType:COMMODITY_LIQUOR_WINES]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kManifest_luxuries:
|
||||
*outValue = INT_TO_JSVAL([entity cargoQuantityForType:COMMODITY_LUXURIES]);
|
||||
*value = INT_TO_JSVAL([entity cargoQuantityForType:COMMODITY_LUXURIES]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kManifest_narcotics:
|
||||
*outValue = INT_TO_JSVAL([entity cargoQuantityForType:COMMODITY_NARCOTICS]);
|
||||
*value = INT_TO_JSVAL([entity cargoQuantityForType:COMMODITY_NARCOTICS]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kManifest_computers:
|
||||
*outValue = INT_TO_JSVAL([entity cargoQuantityForType:COMMODITY_COMPUTERS]);
|
||||
*value = INT_TO_JSVAL([entity cargoQuantityForType:COMMODITY_COMPUTERS]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kManifest_machinery:
|
||||
*outValue = INT_TO_JSVAL([entity cargoQuantityForType:COMMODITY_MACHINERY]);
|
||||
*value = INT_TO_JSVAL([entity cargoQuantityForType:COMMODITY_MACHINERY]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kManifest_alloys:
|
||||
*outValue = INT_TO_JSVAL([entity cargoQuantityForType:COMMODITY_ALLOYS]);
|
||||
*value = INT_TO_JSVAL([entity cargoQuantityForType:COMMODITY_ALLOYS]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kManifest_firearms:
|
||||
*outValue = INT_TO_JSVAL([entity cargoQuantityForType:COMMODITY_FIREARMS]);
|
||||
*value = INT_TO_JSVAL([entity cargoQuantityForType:COMMODITY_FIREARMS]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kManifest_furs:
|
||||
*outValue = INT_TO_JSVAL([entity cargoQuantityForType:COMMODITY_FURS]);
|
||||
*value = INT_TO_JSVAL([entity cargoQuantityForType:COMMODITY_FURS]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kManifest_minerals:
|
||||
*outValue = INT_TO_JSVAL([entity cargoQuantityForType:COMMODITY_MINERALS]);
|
||||
*value = INT_TO_JSVAL([entity cargoQuantityForType:COMMODITY_MINERALS]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kManifest_gold:
|
||||
*outValue = INT_TO_JSVAL([entity cargoQuantityForType:COMMODITY_GOLD]);
|
||||
*value = INT_TO_JSVAL([entity cargoQuantityForType:COMMODITY_GOLD]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kManifest_platinum:
|
||||
*outValue = INT_TO_JSVAL([entity cargoQuantityForType:COMMODITY_PLATINUM]);
|
||||
*value = INT_TO_JSVAL([entity cargoQuantityForType:COMMODITY_PLATINUM]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kManifest_gem_stones:
|
||||
case kManifest_gemstones:
|
||||
case kManifest_gemStones:
|
||||
*outValue = INT_TO_JSVAL([entity cargoQuantityForType:COMMODITY_GEM_STONES]);
|
||||
*value = INT_TO_JSVAL([entity cargoQuantityForType:COMMODITY_GEM_STONES]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kManifest_alien_items:
|
||||
case kManifest_alienitems:
|
||||
case kManifest_alienItems:
|
||||
*outValue = INT_TO_JSVAL([entity cargoQuantityForType:COMMODITY_ALIEN_ITEMS]);
|
||||
*value = INT_TO_JSVAL([entity cargoQuantityForType:COMMODITY_ALIEN_ITEMS]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
default:
|
||||
OOReportJSBadPropertySelector(context, @"Manifest", JSVAL_TO_INT(name));
|
||||
OOReportJSBadPropertySelector(context, @"Manifest", commodity);
|
||||
}
|
||||
|
||||
if (OK && result != nil) *outValue = [result javaScriptValueInContext:context];
|
||||
if (OK && result != nil) *value = [result javaScriptValueInContext:context];
|
||||
return OK;
|
||||
|
||||
OOJS_NATIVE_EXIT
|
||||
}
|
||||
|
||||
|
||||
static JSBool ManifestSetProperty(JSContext *context, JSObject *this, jsval name, jsval *value)
|
||||
static JSBool ManifestSetProperty(OOJS_PROP_ARGS)
|
||||
{
|
||||
OOJS_NATIVE_ENTER(context)
|
||||
|
||||
BOOL OK = NO;
|
||||
PlayerEntity *entity = OOPlayerForScripting();
|
||||
int32 iValue;
|
||||
int commodity;
|
||||
unsigned commodity;
|
||||
|
||||
if (JSVAL_IS_STRING(name)) // Is it a case insensitive commodity identifier?
|
||||
{
|
||||
//FIXME: there must be a better way of doing this.
|
||||
const char *str = [[[NSString stringWithJavaScriptValue:name inContext:context] lowercaseString] UTF8String];
|
||||
int i;
|
||||
|
||||
for (i=0; i<sManifestCaseInsensitiveLimit; i++)
|
||||
{
|
||||
if (strcmp(sManifestProperties[i].name, str) == 0)
|
||||
{
|
||||
name = INT_TO_JSVAL(sManifestProperties[i].tinyid);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!GetCommodityID(propID, &commodity)) return YES;
|
||||
|
||||
if (!JSVAL_IS_INT(name)) return YES;
|
||||
//if (EXPECT_NOT(!JSShipGetShipEntity(context, this, &entity))) return NO;
|
||||
|
||||
commodity = JSVAL_TO_INT(name);
|
||||
// we can always change gold, platinum & gem-stones quantities, even with special cargo
|
||||
if ([entity specialCargo] && (commodity < kManifest_gold || commodity > kManifest_gemStones))
|
||||
{
|
||||
@ -541,7 +559,7 @@ static JSBool ManifestSetProperty(JSContext *context, JSObject *this, jsval name
|
||||
break;
|
||||
|
||||
default:
|
||||
OOReportJSBadPropertySelector(context, @"Manifest", JSVAL_TO_INT(name));
|
||||
OOReportJSBadPropertySelector(context, @"Manifest", commodity);
|
||||
}
|
||||
|
||||
return OK;
|
||||
|
@ -32,19 +32,29 @@ MA 02110-1301, USA.
|
||||
#import "OOJSPlayer.h"
|
||||
|
||||
|
||||
static NSString *KeyForName(JSContext *context, jsval name)
|
||||
#if OO_NEW_JS
|
||||
typedef jsid PropertyID;
|
||||
#define PROP_IS_STRING JSID_IS_STRING
|
||||
#define PROP_TO_STRING JSID_TO_STRING
|
||||
#else
|
||||
typedef jsval PropertyID;
|
||||
#define PROP_IS_STRING JSVAL_IS_STRING
|
||||
#define PROP_TO_STRING JSVAL_TO_STRING
|
||||
#endif
|
||||
|
||||
static NSString *KeyForPropertyID(JSContext *context, PropertyID propID)
|
||||
{
|
||||
NSCParameterAssert(JSVAL_IS_STRING(name));
|
||||
NSCParameterAssert(PROP_IS_STRING(propID));
|
||||
|
||||
NSString *key = [NSString stringWithJavaScriptString:JSVAL_TO_STRING(name)];
|
||||
NSString *key = [NSString stringWithJavaScriptString:PROP_TO_STRING(propID)];
|
||||
if ([key hasPrefix:@"_"]) return nil;
|
||||
return [@"mission_" stringByAppendingString:key];
|
||||
}
|
||||
|
||||
|
||||
static JSBool MissionVariablesDeleteProperty(JSContext *context, JSObject *this, jsval name, jsval *outValue);
|
||||
static JSBool MissionVariablesGetProperty(JSContext *context, JSObject *this, jsval name, jsval *outValue);
|
||||
static JSBool MissionVariablesSetProperty(JSContext *context, JSObject *this, jsval name, jsval *value);
|
||||
static JSBool MissionVariablesGetProperty(OOJS_PROP_ARGS);
|
||||
static JSBool MissionVariablesSetProperty(OOJS_PROP_ARGS);
|
||||
static JSBool MissionVariablesEnumerate(JSContext *cx, JSObject *obj, JSIterateOp enum_op, jsval *statep, jsid *idp);
|
||||
|
||||
|
||||
@ -70,15 +80,15 @@ void InitOOJSMissionVariables(JSContext *context, JSObject *global)
|
||||
}
|
||||
|
||||
|
||||
static JSBool MissionVariablesDeleteProperty(JSContext *context, JSObject *this, jsval name, jsval *value)
|
||||
static JSBool MissionVariablesDeleteProperty(OOJS_PROP_ARGS)
|
||||
{
|
||||
OOJS_NATIVE_ENTER(context)
|
||||
|
||||
PlayerEntity *player = OOPlayerForScripting();
|
||||
|
||||
if (JSVAL_IS_STRING(name))
|
||||
if (OOJS_PROPID_IS_STRING)
|
||||
{
|
||||
NSString *key = KeyForName(context, name);
|
||||
NSString *key = KeyForPropertyID(context, propID);
|
||||
[player setMissionVariable:nil forKey:key];
|
||||
}
|
||||
return YES;
|
||||
@ -87,42 +97,42 @@ static JSBool MissionVariablesDeleteProperty(JSContext *context, JSObject *this,
|
||||
}
|
||||
|
||||
|
||||
static JSBool MissionVariablesGetProperty(JSContext *context, JSObject *this, jsval name, jsval *outValue)
|
||||
static JSBool MissionVariablesGetProperty(OOJS_PROP_ARGS)
|
||||
{
|
||||
OOJS_NATIVE_ENTER(context)
|
||||
|
||||
PlayerEntity *player = OOPlayerForScripting();
|
||||
|
||||
if (JSVAL_IS_STRING(name))
|
||||
if (OOJS_PROPID_IS_STRING)
|
||||
{
|
||||
NSString *key = KeyForName(context, name);
|
||||
NSString *key = KeyForPropertyID(context, propID);
|
||||
if (key == nil) return YES;
|
||||
|
||||
id value = [player missionVariableForKey:key];
|
||||
id mvar = [player missionVariableForKey:key];
|
||||
|
||||
*outValue = JSVAL_VOID;
|
||||
if ([value isKindOfClass:[NSString class]]) // Currently there should only be strings, but we may want to change this.
|
||||
*value = JSVAL_VOID;
|
||||
if ([mvar isKindOfClass:[NSString class]]) // Currently there should only be strings, but we may want to change this.
|
||||
{
|
||||
if (OOIsNumberLiteral(value, YES))
|
||||
if (OOIsNumberLiteral(mvar, YES))
|
||||
{
|
||||
BOOL OK = JS_NewDoubleValue(context, [value doubleValue], outValue);
|
||||
if (!OK) *outValue = JSVAL_VOID;
|
||||
BOOL OK = JS_NewDoubleValue(context, [mvar doubleValue], value);
|
||||
if (!OK) *value = JSVAL_VOID;
|
||||
}
|
||||
}
|
||||
|
||||
if (value != nil && JSVAL_IS_VOID(*outValue))
|
||||
if (mvar != nil && JSVAL_IS_VOID(*value))
|
||||
{
|
||||
*outValue = [value javaScriptValueInContext:context];
|
||||
*value = [mvar javaScriptValueInContext:context];
|
||||
}
|
||||
|
||||
if (JSVAL_IS_VOID(*outValue))
|
||||
if (JSVAL_IS_VOID(*value))
|
||||
{
|
||||
/* "undefined" is the normal JS expectation, but "null" is easier
|
||||
to deal with. For instance, foo = missionVaraibles.undefinedThing
|
||||
is an error if JSVAL_VOID is used, but fine if JSVAL_NULL is
|
||||
used.
|
||||
*/
|
||||
*outValue = JSVAL_NULL;
|
||||
*value = JSVAL_NULL;
|
||||
}
|
||||
}
|
||||
return YES;
|
||||
@ -131,15 +141,15 @@ static JSBool MissionVariablesGetProperty(JSContext *context, JSObject *this, js
|
||||
}
|
||||
|
||||
|
||||
static JSBool MissionVariablesSetProperty(JSContext *context, JSObject *this, jsval name, jsval *value)
|
||||
static JSBool MissionVariablesSetProperty(OOJS_PROP_ARGS)
|
||||
{
|
||||
OOJS_NATIVE_ENTER(context)
|
||||
|
||||
PlayerEntity *player = OOPlayerForScripting();
|
||||
|
||||
if (JSVAL_IS_STRING(name))
|
||||
if (OOJS_PROPID_IS_STRING)
|
||||
{
|
||||
NSString *key = KeyForName(context, name);
|
||||
NSString *key = KeyForPropertyID(context, propID);
|
||||
if (key == nil)
|
||||
{
|
||||
OOReportJSError(context, @"Mission variable names may not begin with an underscore.");
|
||||
|
@ -31,7 +31,7 @@ MA 02110-1301, USA.
|
||||
#import "OOJSPlayer.h"
|
||||
|
||||
|
||||
static JSBool OoliteGetProperty(JSContext *context, JSObject *this, jsval name, jsval *outValue);
|
||||
static JSBool OoliteGetProperty(OOJS_PROP_ARGS);
|
||||
|
||||
static NSString *VersionString(void);
|
||||
static NSArray *VersionComponents(void);
|
||||
@ -93,15 +93,15 @@ void InitOOJSOolite(JSContext *context, JSObject *global)
|
||||
}
|
||||
|
||||
|
||||
static JSBool OoliteGetProperty(JSContext *context, JSObject *this, jsval name, jsval *outValue)
|
||||
static JSBool OoliteGetProperty(OOJS_PROP_ARGS)
|
||||
{
|
||||
if (!JSVAL_IS_INT(name)) return YES;
|
||||
if (!OOJS_PROPID_IS_INT) return YES;
|
||||
|
||||
OOJS_NATIVE_ENTER(context)
|
||||
|
||||
id result = nil;
|
||||
|
||||
switch (JSVAL_TO_INT(name))
|
||||
switch (OOJS_PROPID_INT)
|
||||
{
|
||||
case kOolite_version:
|
||||
result = VersionComponents();
|
||||
@ -114,11 +114,11 @@ static JSBool OoliteGetProperty(JSContext *context, JSObject *this, jsval name,
|
||||
break;
|
||||
|
||||
case kOolite_jsVersion:
|
||||
*outValue = INT_TO_JSVAL(JS_GetVersion(context));
|
||||
*value = INT_TO_JSVAL(JS_GetVersion(context));
|
||||
break;
|
||||
|
||||
case kOolite_jsVersionString:
|
||||
*outValue = STRING_TO_JSVAL(JS_NewStringCopyZ(context, JS_VersionToString(JS_GetVersion(context))));
|
||||
*value = STRING_TO_JSVAL(JS_NewStringCopyZ(context, JS_VersionToString(JS_GetVersion(context))));
|
||||
break;
|
||||
|
||||
case kOolite_gameSettings:
|
||||
@ -127,11 +127,11 @@ static JSBool OoliteGetProperty(JSContext *context, JSObject *this, jsval name,
|
||||
break;
|
||||
|
||||
default:
|
||||
OOReportJSBadPropertySelector(context, @"Oolite", JSVAL_TO_INT(name));
|
||||
OOReportJSBadPropertySelector(context, @"Oolite", OOJS_PROPID_INT);
|
||||
return NO;
|
||||
}
|
||||
|
||||
if (result != nil) *outValue = [result javaScriptValueInContext:context];
|
||||
if (result != nil) *value = [result javaScriptValueInContext:context];
|
||||
return YES;
|
||||
|
||||
OOJS_NATIVE_EXIT
|
||||
|
@ -37,8 +37,8 @@ DEFINE_JS_OBJECT_GETTER(JSPlanetGetPlanetEntity, OOPlanetEntity)
|
||||
static JSObject *sPlanetPrototype;
|
||||
|
||||
|
||||
static JSBool PlanetGetProperty(JSContext *context, JSObject *this, jsval name, jsval *outValue);
|
||||
static JSBool PlanetSetProperty(JSContext *context, JSObject *this, jsval name, jsval *value);
|
||||
static JSBool PlanetGetProperty(OOJS_PROP_ARGS);
|
||||
static JSBool PlanetSetProperty(OOJS_PROP_ARGS);
|
||||
|
||||
|
||||
static JSClass sPlanetClass =
|
||||
@ -121,9 +121,9 @@ void InitOOJSPlanet(JSContext *context, JSObject *global)
|
||||
@end
|
||||
|
||||
|
||||
static JSBool PlanetGetProperty(JSContext *context, JSObject *this, jsval name, jsval *outValue)
|
||||
static JSBool PlanetGetProperty(OOJS_PROP_ARGS)
|
||||
{
|
||||
if (!JSVAL_IS_INT(name)) return YES;
|
||||
if (!OOJS_PROPID_IS_INT) return YES;
|
||||
|
||||
OOJS_NATIVE_ENTER(context)
|
||||
|
||||
@ -131,37 +131,37 @@ static JSBool PlanetGetProperty(JSContext *context, JSObject *this, jsval name,
|
||||
OOPlanetEntity *planet = nil;
|
||||
if (!JSPlanetGetPlanetEntity(context, this, &planet)) return NO;
|
||||
|
||||
switch (JSVAL_TO_INT(name))
|
||||
switch (OOJS_PROPID_INT)
|
||||
{
|
||||
case kPlanet_isMainPlanet:
|
||||
*outValue = BOOLToJSVal(planet == (id)[UNIVERSE planet]);
|
||||
*value = BOOLToJSVal(planet == (id)[UNIVERSE planet]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kPlanet_radius:
|
||||
OK = JS_NewDoubleValue(context, [planet radius], outValue);
|
||||
OK = JS_NewDoubleValue(context, [planet radius], value);
|
||||
break;
|
||||
|
||||
case kPlanet_hasAtmosphere:
|
||||
*outValue = BOOLToJSVal([planet hasAtmosphere]);
|
||||
*value = BOOLToJSVal([planet hasAtmosphere]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kPlanet_texture:
|
||||
*outValue = [[planet textureFileName] javaScriptValueInContext:context];
|
||||
*value = [[planet textureFileName] javaScriptValueInContext:context];
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kPlanet_orientation:
|
||||
OK = QuaternionToJSValue(context, [planet normalOrientation], outValue);
|
||||
OK = QuaternionToJSValue(context, [planet normalOrientation], value);
|
||||
break;
|
||||
|
||||
case kPlanet_rotationalVelocity:
|
||||
OK = JS_NewDoubleValue(context, [planet rotationalVelocity], outValue);
|
||||
OK = JS_NewDoubleValue(context, [planet rotationalVelocity], value);
|
||||
break;
|
||||
|
||||
default:
|
||||
OOReportJSBadPropertySelector(context, @"Planet", JSVAL_TO_INT(name));
|
||||
OOReportJSBadPropertySelector(context, @"Planet", OOJS_PROPID_INT);
|
||||
}
|
||||
return OK;
|
||||
|
||||
@ -169,9 +169,9 @@ static JSBool PlanetGetProperty(JSContext *context, JSObject *this, jsval name,
|
||||
}
|
||||
|
||||
|
||||
static JSBool PlanetSetProperty(JSContext *context, JSObject *this, jsval name, jsval *value)
|
||||
static JSBool PlanetSetProperty(OOJS_PROP_ARGS)
|
||||
{
|
||||
if (!JSVAL_IS_INT(name)) return YES;
|
||||
if (!OOJS_PROPID_IS_INT) return YES;
|
||||
|
||||
OOJS_NATIVE_ENTER(context)
|
||||
|
||||
@ -183,7 +183,7 @@ static JSBool PlanetSetProperty(JSContext *context, JSObject *this, jsval name,
|
||||
|
||||
if (!JSPlanetGetPlanetEntity(context, this, &planet)) return NO;
|
||||
|
||||
switch (JSVAL_TO_INT(name))
|
||||
switch (OOJS_PROPID_INT)
|
||||
{
|
||||
case kPlanet_texture:
|
||||
// all error messages are self contained
|
||||
@ -227,7 +227,7 @@ static JSBool PlanetSetProperty(JSContext *context, JSObject *this, jsval name,
|
||||
break;
|
||||
|
||||
default:
|
||||
OOReportJSBadPropertySelector(context, @"Planet", JSVAL_TO_INT(name));
|
||||
OOReportJSBadPropertySelector(context, @"Planet", OOJS_PROPID_INT);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -44,8 +44,8 @@ static JSObject *sPlayerPrototype;
|
||||
static JSObject *sPlayerObject;
|
||||
|
||||
|
||||
static JSBool PlayerGetProperty(JSContext *context, JSObject *this, jsval name, jsval *outValue);
|
||||
static JSBool PlayerSetProperty(JSContext *context, JSObject *this, jsval name, jsval *value);
|
||||
static JSBool PlayerGetProperty(OOJS_PROP_ARGS);
|
||||
static JSBool PlayerSetProperty(OOJS_PROP_ARGS);
|
||||
|
||||
static JSBool PlayerCommsMessage(JSContext *context, JSObject *this, uintN argc, jsval *argv, jsval *outResult);
|
||||
static JSBool PlayerConsoleMessage(JSContext *context, JSObject *this, uintN argc, jsval *argv, jsval *outResult);
|
||||
@ -175,9 +175,9 @@ PlayerEntity *OOPlayerForScripting(void)
|
||||
}
|
||||
|
||||
|
||||
static JSBool PlayerGetProperty(JSContext *context, JSObject *this, jsval name, jsval *outValue)
|
||||
static JSBool PlayerGetProperty(OOJS_PROP_ARGS)
|
||||
{
|
||||
if (!JSVAL_IS_INT(name)) return YES;
|
||||
if (!OOJS_PROPID_IS_INT) return YES;
|
||||
|
||||
OOJS_NATIVE_ENTER(context)
|
||||
|
||||
@ -185,7 +185,7 @@ static JSBool PlayerGetProperty(JSContext *context, JSObject *this, jsval name,
|
||||
id result = nil;
|
||||
PlayerEntity *player = OOPlayerForScripting();
|
||||
|
||||
switch (JSVAL_TO_INT(name))
|
||||
switch (OOJS_PROPID_INT)
|
||||
{
|
||||
case kPlayer_name:
|
||||
result = [player playerName];
|
||||
@ -193,94 +193,94 @@ static JSBool PlayerGetProperty(JSContext *context, JSObject *this, jsval name,
|
||||
break;
|
||||
|
||||
case kPlayer_score:
|
||||
*outValue = INT_TO_JSVAL([player score]);
|
||||
*value = INT_TO_JSVAL([player score]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kPlayer_credits:
|
||||
OK = JS_NewDoubleValue(context, [player creditBalance], outValue);
|
||||
OK = JS_NewDoubleValue(context, [player creditBalance], value);
|
||||
break;
|
||||
|
||||
case kPlayer_rank:
|
||||
*outValue = [KillCountToRatingString([player score]) javaScriptValueInContext:context];
|
||||
*value = [KillCountToRatingString([player score]) javaScriptValueInContext:context];
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kPlayer_legalStatus:
|
||||
*outValue = [LegalStatusToString([player bounty]) javaScriptValueInContext:context];
|
||||
*value = [LegalStatusToString([player bounty]) javaScriptValueInContext:context];
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kPlayer_alertCondition:
|
||||
*outValue = INT_TO_JSVAL([player alertCondition]);
|
||||
*value = INT_TO_JSVAL([player alertCondition]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kPlayer_alertTemperature:
|
||||
*outValue = BOOLToJSVal([player alertFlags] & ALERT_FLAG_TEMP);
|
||||
*value = BOOLToJSVal([player alertFlags] & ALERT_FLAG_TEMP);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kPlayer_alertMassLocked:
|
||||
*outValue = BOOLToJSVal([player alertFlags] & ALERT_FLAG_MASS_LOCK);
|
||||
*value = BOOLToJSVal([player alertFlags] & ALERT_FLAG_MASS_LOCK);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kPlayer_alertAltitude:
|
||||
*outValue = BOOLToJSVal([player alertFlags] & ALERT_FLAG_ALT);
|
||||
*value = BOOLToJSVal([player alertFlags] & ALERT_FLAG_ALT);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kPlayer_alertEnergy:
|
||||
*outValue = BOOLToJSVal([player alertFlags] & ALERT_FLAG_ENERGY);
|
||||
*value = BOOLToJSVal([player alertFlags] & ALERT_FLAG_ENERGY);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kPlayer_alertHostiles:
|
||||
*outValue = BOOLToJSVal([player alertFlags] & ALERT_FLAG_HOSTILES);
|
||||
*value = BOOLToJSVal([player alertFlags] & ALERT_FLAG_HOSTILES);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kPlayer_trumbleCount:
|
||||
OK = JS_NewNumberValue(context, [player trumbleCount], outValue);
|
||||
OK = JS_NewNumberValue(context, [player trumbleCount], value);
|
||||
break;
|
||||
|
||||
case kPlayer_contractReputation:
|
||||
*outValue = INT_TO_JSVAL([player contractReputation]);
|
||||
*value = INT_TO_JSVAL([player contractReputation]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kPlayer_passengerReputation:
|
||||
*outValue = INT_TO_JSVAL([player passengerReputation]);
|
||||
*value = INT_TO_JSVAL([player passengerReputation]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
#if DOCKING_CLEARANCE_ENABLED
|
||||
case kPlayer_dockingClearanceStatus:
|
||||
*outValue = [DockingClearanceStatusToString([player getDockingClearanceStatus]) javaScriptValueInContext:context];
|
||||
*value = [DockingClearanceStatusToString([player getDockingClearanceStatus]) javaScriptValueInContext:context];
|
||||
OK = YES;
|
||||
break;
|
||||
#endif
|
||||
|
||||
case kPlayer_bounty:
|
||||
*outValue = INT_TO_JSVAL([player legalStatus]);
|
||||
*value = INT_TO_JSVAL([player legalStatus]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
default:
|
||||
OOReportJSBadPropertySelector(context, @"Player", JSVAL_TO_INT(name));
|
||||
OOReportJSBadPropertySelector(context, @"Player", OOJS_PROPID_INT);
|
||||
}
|
||||
|
||||
if (OK && result != nil) *outValue = [result javaScriptValueInContext:context];
|
||||
if (OK && result != nil) *value = [result javaScriptValueInContext:context];
|
||||
return OK;
|
||||
|
||||
OOJS_NATIVE_EXIT
|
||||
}
|
||||
|
||||
|
||||
static JSBool PlayerSetProperty(JSContext *context, JSObject *this, jsval name, jsval *value)
|
||||
static JSBool PlayerSetProperty(OOJS_PROP_ARGS)
|
||||
{
|
||||
if (!JSVAL_IS_INT(name)) return YES;
|
||||
if (!OOJS_PROPID_IS_INT) return YES;
|
||||
|
||||
OOJS_NATIVE_ENTER(context)
|
||||
|
||||
@ -289,7 +289,7 @@ static JSBool PlayerSetProperty(JSContext *context, JSObject *this, jsval name,
|
||||
jsdouble fValue;
|
||||
int32 iValue;
|
||||
|
||||
switch (JSVAL_TO_INT(name))
|
||||
switch (OOJS_PROPID_INT)
|
||||
{
|
||||
case kPlayer_score:
|
||||
if (JS_ValueToInt32(context, *value, &iValue))
|
||||
@ -318,7 +318,7 @@ static JSBool PlayerSetProperty(JSContext *context, JSObject *this, jsval name,
|
||||
break;
|
||||
|
||||
default:
|
||||
OOReportJSBadPropertySelector(context, @"Player", JSVAL_TO_INT(name));
|
||||
OOReportJSBadPropertySelector(context, @"Player", OOJS_PROPID_INT);
|
||||
}
|
||||
|
||||
return OK;
|
||||
|
@ -54,8 +54,8 @@ static JSObject *sPlayerShipPrototype;
|
||||
static JSObject *sPlayerShipObject;
|
||||
|
||||
|
||||
static JSBool PlayerShipGetProperty(JSContext *context, JSObject *this, jsval name, jsval *outValue);
|
||||
static JSBool PlayerShipSetProperty(JSContext *context, JSObject *this, jsval name, jsval *value);
|
||||
static JSBool PlayerShipGetProperty(OOJS_PROP_ARGS);
|
||||
static JSBool PlayerShipSetProperty(OOJS_PROP_ARGS);
|
||||
|
||||
static JSBool PlayerShipLaunch(JSContext *context, JSObject *this, uintN argc, jsval *argv, jsval *outResult);
|
||||
static JSBool PlayerShipRemoveAllCargo(JSContext *context, JSObject *this, uintN argc, jsval *argv, jsval *outResult);
|
||||
@ -205,25 +205,25 @@ JSObject *JSPlayerShipObject(void)
|
||||
@end
|
||||
|
||||
|
||||
static JSBool PlayerShipGetProperty(JSContext *context, JSObject *this, jsval name, jsval *outValue)
|
||||
static JSBool PlayerShipGetProperty(OOJS_PROP_ARGS)
|
||||
{
|
||||
OOJS_NATIVE_ENTER(context)
|
||||
|
||||
if (EXPECT_NOT([UNIVERSE blockJSPlayerShipProps])) {*outValue = JSVAL_VOID; return YES;}
|
||||
if (EXPECT_NOT(!JSVAL_IS_INT(name))) return YES;
|
||||
if (EXPECT_NOT([UNIVERSE blockJSPlayerShipProps])) {*value = JSVAL_VOID; return YES;}
|
||||
if (EXPECT_NOT(!OOJS_PROPID_IS_INT)) return YES;
|
||||
|
||||
BOOL OK = NO;
|
||||
id result = nil;
|
||||
PlayerEntity *player = OOPlayerShipForScripting();
|
||||
|
||||
switch (JSVAL_TO_INT(name))
|
||||
switch (OOJS_PROPID_INT)
|
||||
{
|
||||
case kPlayerShip_fuelLeakRate:
|
||||
OK = JS_NewDoubleValue(context, [player fuelLeakRate], outValue);
|
||||
OK = JS_NewDoubleValue(context, [player fuelLeakRate], value);
|
||||
break;
|
||||
|
||||
case kPlayerShip_docked:
|
||||
*outValue = BOOLToJSVal([player isDocked]);
|
||||
*value = BOOLToJSVal([player isDocked]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
@ -239,7 +239,7 @@ static JSBool PlayerShipGetProperty(JSContext *context, JSObject *this, jsval na
|
||||
break;
|
||||
|
||||
case kPlayerShip_reticleTargetSensitive:
|
||||
*outValue = BOOLToJSVal([[player hud] reticleTargetSensitive]);
|
||||
*value = BOOLToJSVal([[player hud] reticleTargetSensitive]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
@ -249,51 +249,51 @@ static JSBool PlayerShipGetProperty(JSContext *context, JSObject *this, jsval na
|
||||
break;
|
||||
|
||||
case kPlayerShip_galacticHyperspaceFixedCoords:
|
||||
OK = NSPointToVectorJSValue(context, [player galacticHyperspaceFixedCoords], outValue);
|
||||
OK = NSPointToVectorJSValue(context, [player galacticHyperspaceFixedCoords], value);
|
||||
break;
|
||||
|
||||
case kPlayerShip_forwardShield:
|
||||
OK = JS_NewDoubleValue(context, [player forwardShieldLevel], outValue);
|
||||
OK = JS_NewDoubleValue(context, [player forwardShieldLevel], value);
|
||||
break;
|
||||
|
||||
case kPlayerShip_aftShield:
|
||||
OK = JS_NewDoubleValue(context, [player aftShieldLevel], outValue);
|
||||
OK = JS_NewDoubleValue(context, [player aftShieldLevel], value);
|
||||
break;
|
||||
|
||||
case kPlayerShip_maxForwardShield:
|
||||
OK = JS_NewDoubleValue(context, [player maxForwardShieldLevel], outValue);
|
||||
OK = JS_NewDoubleValue(context, [player maxForwardShieldLevel], value);
|
||||
break;
|
||||
|
||||
case kPlayerShip_maxAftShield:
|
||||
OK = JS_NewDoubleValue(context, [player maxAftShieldLevel], outValue);
|
||||
OK = JS_NewDoubleValue(context, [player maxAftShieldLevel], value);
|
||||
break;
|
||||
|
||||
case kPlayerShip_forwardShieldRechargeRate:
|
||||
case kPlayerShip_aftShieldRechargeRate:
|
||||
// No distinction made internally
|
||||
OK = JS_NewDoubleValue(context, [player shieldRechargeRate], outValue);
|
||||
OK = JS_NewDoubleValue(context, [player shieldRechargeRate], value);
|
||||
break;
|
||||
|
||||
case kPlayerShip_galaxyCoordinates:
|
||||
OK = NSPointToVectorJSValue(context, [player galaxy_coordinates], outValue);
|
||||
OK = NSPointToVectorJSValue(context, [player galaxy_coordinates], value);
|
||||
break;
|
||||
|
||||
case kPlayerShip_cursorCoordinates:
|
||||
OK = NSPointToVectorJSValue(context, [player cursor_coordinates], outValue);
|
||||
OK = NSPointToVectorJSValue(context, [player cursor_coordinates], value);
|
||||
break;
|
||||
|
||||
case kPlayerShip_targetSystem:
|
||||
*outValue = INT_TO_JSVAL([UNIVERSE findSystemNumberAtCoords:[player cursor_coordinates] withGalaxySeed:[player galaxy_seed]]);
|
||||
*value = INT_TO_JSVAL([UNIVERSE findSystemNumberAtCoords:[player cursor_coordinates] withGalaxySeed:[player galaxy_seed]]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kPlayerShip_scriptedMisjump:
|
||||
*outValue = BOOLToJSVal([player scriptedMisjump]);
|
||||
*value = BOOLToJSVal([player scriptedMisjump]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kPlayerShip_scoopOverride:
|
||||
*outValue = BOOLToJSVal([player scoopOverride]);
|
||||
*value = BOOLToJSVal([player scoopOverride]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
@ -313,12 +313,12 @@ static JSBool PlayerShipGetProperty(JSContext *context, JSObject *this, jsval na
|
||||
break;
|
||||
|
||||
case kPlayerShip_hudHidden:
|
||||
*outValue = BOOLToJSVal([[player hud] isHidden]);
|
||||
*value = BOOLToJSVal([[player hud] isHidden]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kPlayerShip_weaponsOnline:
|
||||
*outValue = BOOLToJSVal([player weaponsOnline]);
|
||||
*value = BOOLToJSVal([player weaponsOnline]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
@ -328,22 +328,22 @@ static JSBool PlayerShipGetProperty(JSContext *context, JSObject *this, jsval na
|
||||
break;
|
||||
|
||||
default:
|
||||
OOReportJSBadPropertySelector(context, @"PlayerShip", JSVAL_TO_INT(name));
|
||||
OOReportJSBadPropertySelector(context, @"PlayerShip", OOJS_PROPID_INT);
|
||||
}
|
||||
|
||||
if (OK && result != nil) *outValue = [result javaScriptValueInContext:context];
|
||||
if (OK && result != nil) *value = [result javaScriptValueInContext:context];
|
||||
return OK;
|
||||
|
||||
OOJS_NATIVE_EXIT
|
||||
}
|
||||
|
||||
|
||||
static JSBool PlayerShipSetProperty(JSContext *context, JSObject *this, jsval name, jsval *value)
|
||||
static JSBool PlayerShipSetProperty(OOJS_PROP_ARGS)
|
||||
{
|
||||
OOJS_NATIVE_ENTER(context)
|
||||
|
||||
if (EXPECT_NOT([UNIVERSE blockJSPlayerShipProps])) return YES;
|
||||
if (EXPECT_NOT(!JSVAL_IS_INT(name))) return YES;
|
||||
if (EXPECT_NOT(!OOJS_PROPID_IS_INT)) return YES;
|
||||
|
||||
BOOL OK = NO;
|
||||
PlayerEntity *player = OOPlayerShipForScripting();
|
||||
@ -353,7 +353,7 @@ static JSBool PlayerShipSetProperty(JSContext *context, JSObject *this, jsval na
|
||||
OOGalacticHyperspaceBehaviour ghBehaviour;
|
||||
Vector vValue;
|
||||
|
||||
switch (JSVAL_TO_INT(name))
|
||||
switch (OOJS_PROPID_INT)
|
||||
{
|
||||
case kPlayerShip_fuelLeakRate:
|
||||
if (JS_ValueToNumber(context, *value, &fValue))
|
||||
@ -453,7 +453,7 @@ static JSBool PlayerShipSetProperty(JSContext *context, JSObject *this, jsval na
|
||||
break;
|
||||
|
||||
default:
|
||||
OOReportJSBadPropertySelector(context, @"PlayerShip", JSVAL_TO_INT(name));
|
||||
OOReportJSBadPropertySelector(context, @"PlayerShip", OOJS_PROPID_INT);
|
||||
}
|
||||
|
||||
return OK;
|
||||
|
@ -42,8 +42,8 @@ static JSObject *sQuaternionPrototype;
|
||||
static BOOL GetThisQuaternion(JSContext *context, JSObject *quaternionObj, Quaternion *outQuaternion, NSString *method) NONNULL_FUNC;
|
||||
|
||||
|
||||
static JSBool QuaternionGetProperty(JSContext *context, JSObject *this, jsval name, jsval *outValue);
|
||||
static JSBool QuaternionSetProperty(JSContext *context, JSObject *this, jsval name, jsval *value);
|
||||
static JSBool QuaternionGetProperty(OOJS_PROP_ARGS);
|
||||
static JSBool QuaternionSetProperty(OOJS_PROP_ARGS);
|
||||
static void QuaternionFinalize(JSContext *context, JSObject *this);
|
||||
static JSBool QuaternionConstruct(JSContext *context, JSObject *this, uintN argc, jsval *argv, jsval *outResult);
|
||||
|
||||
@ -365,53 +365,53 @@ BOOL QuaternionFromArgumentListNoError(JSContext *context, uintN argc, jsval *ar
|
||||
|
||||
// *** Implementation stuff ***
|
||||
|
||||
static JSBool QuaternionGetProperty(JSContext *context, JSObject *this, jsval name, jsval *outValue)
|
||||
static JSBool QuaternionGetProperty(OOJS_PROP_ARGS)
|
||||
{
|
||||
OOJS_PROFILE_ENTER
|
||||
|
||||
Quaternion quaternion;
|
||||
GLfloat value;
|
||||
GLfloat fValue;
|
||||
|
||||
if (!JSVAL_IS_INT(name)) return YES;
|
||||
if (!OOJS_PROPID_IS_INT) return YES;
|
||||
if (EXPECT_NOT(!JSObjectGetQuaternion(context, this, &quaternion))) return NO;
|
||||
|
||||
switch (JSVAL_TO_INT(name))
|
||||
switch (OOJS_PROPID_INT)
|
||||
{
|
||||
case kQuaternion_w:
|
||||
value = quaternion.w;
|
||||
fValue = quaternion.w;
|
||||
break;
|
||||
|
||||
case kQuaternion_x:
|
||||
value = quaternion.x;
|
||||
fValue = quaternion.x;
|
||||
break;
|
||||
|
||||
case kQuaternion_y:
|
||||
value = quaternion.y;
|
||||
fValue = quaternion.y;
|
||||
break;
|
||||
|
||||
case kQuaternion_z:
|
||||
value = quaternion.z;
|
||||
fValue = quaternion.z;
|
||||
break;
|
||||
|
||||
default:
|
||||
OOReportJSBadPropertySelector(context, @"Quaternion", JSVAL_TO_INT(name));
|
||||
OOReportJSBadPropertySelector(context, @"Quaternion", OOJS_PROPID_INT);
|
||||
return NO;
|
||||
}
|
||||
|
||||
return JS_NewDoubleValue(context, value, outValue);
|
||||
return JS_NewDoubleValue(context, fValue, value);
|
||||
|
||||
OOJS_PROFILE_EXIT
|
||||
}
|
||||
|
||||
|
||||
static JSBool QuaternionSetProperty(JSContext *context, JSObject *this, jsval name, jsval *value)
|
||||
static JSBool QuaternionSetProperty(OOJS_PROP_ARGS)
|
||||
{
|
||||
OOJS_PROFILE_ENTER
|
||||
|
||||
Quaternion quaternion;
|
||||
jsdouble dval;
|
||||
|
||||
if (!JSVAL_IS_INT(name)) return YES;
|
||||
if (!OOJS_PROPID_IS_INT) return YES;
|
||||
if (EXPECT_NOT(!JSObjectGetQuaternion(context, this, &quaternion))) return NO;
|
||||
if (EXPECT_NOT(!JS_ValueToNumber(context, *value, &dval)))
|
||||
{
|
||||
@ -419,7 +419,7 @@ static JSBool QuaternionSetProperty(JSContext *context, JSObject *this, jsval na
|
||||
return NO;
|
||||
}
|
||||
|
||||
switch (JSVAL_TO_INT(name))
|
||||
switch (OOJS_PROPID_INT)
|
||||
{
|
||||
case kQuaternion_w:
|
||||
quaternion.w = dval;
|
||||
@ -438,7 +438,7 @@ static JSBool QuaternionSetProperty(JSContext *context, JSObject *this, jsval na
|
||||
break;
|
||||
|
||||
default:
|
||||
OOReportJSBadPropertySelector(context, @"Quaternion", JSVAL_TO_INT(name));
|
||||
OOReportJSBadPropertySelector(context, @"Quaternion", OOJS_PROPID_INT);
|
||||
return NO;
|
||||
}
|
||||
|
||||
|
@ -50,8 +50,8 @@ DEFINE_JS_OBJECT_GETTER(JSShipGetShipEntity, ShipEntity)
|
||||
static JSObject *sShipPrototype;
|
||||
|
||||
|
||||
static JSBool ShipGetProperty(JSContext *context, JSObject *this, jsval name, jsval *outValue);
|
||||
static JSBool ShipSetProperty(JSContext *context, JSObject *this, jsval name, jsval *value);
|
||||
static JSBool ShipGetProperty(OOJS_PROP_ARGS);
|
||||
static JSBool ShipSetProperty(OOJS_PROP_ARGS);
|
||||
|
||||
static JSBool ShipSetScript(JSContext *context, JSObject *this, uintN argc, jsval *argv, jsval *outResult);
|
||||
static JSBool ShipSetAI(JSContext *context, JSObject *this, uintN argc, jsval *argv, jsval *outResult);
|
||||
@ -342,9 +342,9 @@ JSObject *JSShipPrototype(void)
|
||||
}
|
||||
|
||||
|
||||
static JSBool ShipGetProperty(JSContext *context, JSObject *this, jsval name, jsval *outValue)
|
||||
static JSBool ShipGetProperty(OOJS_PROP_ARGS)
|
||||
{
|
||||
if (!JSVAL_IS_INT(name)) return YES;
|
||||
if (!OOJS_PROPID_IS_INT) return YES;
|
||||
|
||||
OOJS_NATIVE_ENTER(context)
|
||||
|
||||
@ -353,10 +353,10 @@ static JSBool ShipGetProperty(JSContext *context, JSObject *this, jsval name, js
|
||||
id result = nil;
|
||||
|
||||
if (EXPECT_NOT(!JSShipGetShipEntity(context, this, &entity))) return NO; // NOTE: entity may be nil.
|
||||
if (EXPECT_NOT([entity isPlayer] && [UNIVERSE blockJSPlayerShipProps])) {*outValue = JSVAL_VOID; return YES;}
|
||||
if (EXPECT_NOT([entity isPlayer] && [UNIVERSE blockJSPlayerShipProps])) {*value = JSVAL_VOID; return YES;}
|
||||
if (EXPECT_NOT(!JS_EnterLocalRootScope(context))) return NO;
|
||||
|
||||
switch (JSVAL_TO_INT(name))
|
||||
switch (OOJS_PROPID_INT)
|
||||
{
|
||||
case kShip_name:
|
||||
result = [entity name];
|
||||
@ -387,15 +387,15 @@ static JSBool ShipGetProperty(JSContext *context, JSObject *this, jsval name, js
|
||||
break;
|
||||
|
||||
case kShip_fuel:
|
||||
OK = JS_NewDoubleValue(context, [entity fuel] * 0.1, outValue);
|
||||
OK = JS_NewDoubleValue(context, [entity fuel] * 0.1, value);
|
||||
break;
|
||||
|
||||
case kShip_fuelChargeRate:
|
||||
OK = JS_NewDoubleValue(context, [entity fuelChargeRate], outValue);
|
||||
OK = JS_NewDoubleValue(context, [entity fuelChargeRate], value);
|
||||
break;
|
||||
|
||||
case kShip_bounty:
|
||||
*outValue = INT_TO_JSVAL([entity bounty]);
|
||||
*value = INT_TO_JSVAL([entity bounty]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
@ -405,12 +405,12 @@ static JSBool ShipGetProperty(JSContext *context, JSObject *this, jsval name, js
|
||||
break;
|
||||
|
||||
case kShip_subEntityCapacity:
|
||||
*outValue = INT_TO_JSVAL([entity maxShipSubEntities]);
|
||||
*value = INT_TO_JSVAL([entity maxShipSubEntities]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kShip_hasSuspendedAI:
|
||||
*outValue = BOOLToJSVal([[entity getAI] hasSuspendedStateMachines]);
|
||||
*value = BOOLToJSVal([[entity getAI] hasSuspendedStateMachines]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
@ -436,24 +436,24 @@ static JSBool ShipGetProperty(JSContext *context, JSObject *this, jsval name, js
|
||||
break;
|
||||
|
||||
case kShip_temperature:
|
||||
OK = JS_NewDoubleValue(context, [entity temperature] / SHIP_MAX_CABIN_TEMP, outValue);
|
||||
OK = JS_NewDoubleValue(context, [entity temperature] / SHIP_MAX_CABIN_TEMP, value);
|
||||
break;
|
||||
|
||||
case kShip_heatInsulation:
|
||||
OK = JS_NewDoubleValue(context, [entity heatInsulation], outValue);
|
||||
OK = JS_NewDoubleValue(context, [entity heatInsulation], value);
|
||||
break;
|
||||
|
||||
case kShip_heading:
|
||||
OK = VectorToJSValue(context, [entity forwardVector], outValue);
|
||||
OK = VectorToJSValue(context, [entity forwardVector], value);
|
||||
break;
|
||||
|
||||
case kShip_entityPersonality:
|
||||
*outValue = INT_TO_JSVAL([entity entityPersonalityInt]);
|
||||
*value = INT_TO_JSVAL([entity entityPersonalityInt]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kShip_isBeacon:
|
||||
*outValue = BOOLToJSVal([entity isBeacon]);
|
||||
*value = BOOLToJSVal([entity isBeacon]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
@ -463,17 +463,17 @@ static JSBool ShipGetProperty(JSContext *context, JSObject *this, jsval name, js
|
||||
break;
|
||||
|
||||
case kShip_isFrangible:
|
||||
*outValue = BOOLToJSVal([entity isFrangible]);
|
||||
*value = BOOLToJSVal([entity isFrangible]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kShip_isCloaked:
|
||||
*outValue = BOOLToJSVal([entity isCloaked]);
|
||||
*value = BOOLToJSVal([entity isCloaked]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kShip_isJamming:
|
||||
*outValue = BOOLToJSVal([entity isJammingScanning]);
|
||||
*value = BOOLToJSVal([entity isJammingScanning]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
@ -483,58 +483,58 @@ static JSBool ShipGetProperty(JSContext *context, JSObject *this, jsval name, js
|
||||
break;
|
||||
|
||||
case kShip_hasHostileTarget:
|
||||
*outValue = BOOLToJSVal([entity hasHostileTarget]);
|
||||
*value = BOOLToJSVal([entity hasHostileTarget]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kShip_hasHyperspaceMotor:
|
||||
*outValue = BOOLToJSVal([entity hasHyperspaceMotor]);
|
||||
*value = BOOLToJSVal([entity hasHyperspaceMotor]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kShip_weaponRange:
|
||||
OK = JS_NewDoubleValue(context, [entity weaponRange], outValue);
|
||||
OK = JS_NewDoubleValue(context, [entity weaponRange], value);
|
||||
break;
|
||||
|
||||
case kShip_scannerRange:
|
||||
OK = JS_NewDoubleValue(context, [entity scannerRange], outValue);
|
||||
OK = JS_NewDoubleValue(context, [entity scannerRange], value);
|
||||
break;
|
||||
|
||||
case kShip_reportAIMessages:
|
||||
*outValue = BOOLToJSVal([entity reportAIMessages]);
|
||||
*value = BOOLToJSVal([entity reportAIMessages]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kShip_withinStationAegis:
|
||||
*outValue = BOOLToJSVal([entity withinStationAegis]);
|
||||
*value = BOOLToJSVal([entity withinStationAegis]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kShip_cargoSpaceCapacity:
|
||||
*outValue = INT_TO_JSVAL([entity maxCargo]);
|
||||
*value = INT_TO_JSVAL([entity maxCargo]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kShip_cargoSpaceUsed:
|
||||
*outValue = INT_TO_JSVAL([entity maxCargo] - [entity availableCargoSpace]);
|
||||
*value = INT_TO_JSVAL([entity maxCargo] - [entity availableCargoSpace]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kShip_cargoSpaceAvailable:
|
||||
*outValue = INT_TO_JSVAL([entity availableCargoSpace]);
|
||||
*value = INT_TO_JSVAL([entity availableCargoSpace]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kShip_speed:
|
||||
OK = JS_NewDoubleValue(context, [entity flightSpeed], outValue);
|
||||
OK = JS_NewDoubleValue(context, [entity flightSpeed], value);
|
||||
break;
|
||||
|
||||
case kShip_desiredSpeed:
|
||||
OK = JS_NewDoubleValue(context, [entity desiredSpeed], outValue);
|
||||
OK = JS_NewDoubleValue(context, [entity desiredSpeed], value);
|
||||
break;
|
||||
|
||||
case kShip_maxSpeed:
|
||||
OK = JS_NewDoubleValue(context, [entity maxFlightSpeed], outValue);
|
||||
OK = JS_NewDoubleValue(context, [entity maxFlightSpeed], value);
|
||||
break;
|
||||
|
||||
case kShip_script:
|
||||
@ -543,72 +543,72 @@ static JSBool ShipGetProperty(JSContext *context, JSObject *this, jsval name, js
|
||||
break;
|
||||
|
||||
case kShip_isPirate:
|
||||
*outValue = BOOLToJSVal([entity isPirate]);
|
||||
*value = BOOLToJSVal([entity isPirate]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kShip_isPlayer:
|
||||
*outValue = BOOLToJSVal([entity isPlayer]);
|
||||
*value = BOOLToJSVal([entity isPlayer]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kShip_isPolice:
|
||||
*outValue = BOOLToJSVal([entity isPolice]);
|
||||
*value = BOOLToJSVal([entity isPolice]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kShip_isThargoid:
|
||||
*outValue = BOOLToJSVal([entity isThargoid]);
|
||||
*value = BOOLToJSVal([entity isThargoid]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kShip_isTrader:
|
||||
*outValue = BOOLToJSVal([entity isTrader]);
|
||||
*value = BOOLToJSVal([entity isTrader]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kShip_isPirateVictim:
|
||||
*outValue = BOOLToJSVal([entity isPirateVictim]);
|
||||
*value = BOOLToJSVal([entity isPirateVictim]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kShip_isMissile:
|
||||
*outValue = BOOLToJSVal([entity isMissile]);
|
||||
*value = BOOLToJSVal([entity isMissile]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kShip_isMine:
|
||||
*outValue = BOOLToJSVal([entity isMine]);
|
||||
*value = BOOLToJSVal([entity isMine]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kShip_isWeapon:
|
||||
*outValue = BOOLToJSVal([entity isWeapon]);
|
||||
*value = BOOLToJSVal([entity isWeapon]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kShip_isRock:
|
||||
*outValue = BOOLToJSVal([entity scanClass] == CLASS_ROCK); // hermits and asteroids!
|
||||
*value = BOOLToJSVal([entity scanClass] == CLASS_ROCK); // hermits and asteroids!
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kShip_isBoulder:
|
||||
*outValue = BOOLToJSVal([entity isBoulder]);
|
||||
*value = BOOLToJSVal([entity isBoulder]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kShip_isCargo:
|
||||
*outValue = BOOLToJSVal([entity scanClass] == CLASS_CARGO && [entity commodityAmount] > 0);
|
||||
*value = BOOLToJSVal([entity scanClass] == CLASS_CARGO && [entity commodityAmount] > 0);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kShip_isDerelict:
|
||||
*outValue = BOOLToJSVal([entity isHulk]);
|
||||
*value = BOOLToJSVal([entity isHulk]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kShip_isPiloted:
|
||||
*outValue = BOOLToJSVal([entity isPlayer] || [[entity crew] count] > 0);
|
||||
*value = BOOLToJSVal([entity isPlayer] || [[entity crew] count] > 0);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
@ -618,31 +618,31 @@ static JSBool ShipGetProperty(JSContext *context, JSObject *this, jsval name, js
|
||||
break;
|
||||
|
||||
case kShip_trackCloseContacts:
|
||||
*outValue = BOOLToJSVal([entity trackCloseContacts]);
|
||||
*value = BOOLToJSVal([entity trackCloseContacts]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kShip_passengerCount:
|
||||
*outValue = INT_TO_JSVAL([entity passengerCount]);
|
||||
*value = INT_TO_JSVAL([entity passengerCount]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kShip_passengerCapacity:
|
||||
*outValue = INT_TO_JSVAL([entity passengerCapacity]);
|
||||
*value = INT_TO_JSVAL([entity passengerCapacity]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kShip_missileCapacity:
|
||||
*outValue = INT_TO_JSVAL([entity missileCapacity]);
|
||||
*value = INT_TO_JSVAL([entity missileCapacity]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kShip_missileLoadTime:
|
||||
OK = JS_NewDoubleValue(context, [entity missileLoadTime], outValue);
|
||||
OK = JS_NewDoubleValue(context, [entity missileLoadTime], value);
|
||||
break;
|
||||
|
||||
case kShip_savedCoordinates:
|
||||
OK = VectorToJSValue(context, [entity coordinates], outValue);
|
||||
OK = VectorToJSValue(context, [entity coordinates], value);
|
||||
break;
|
||||
|
||||
case kShip_equipment:
|
||||
@ -692,45 +692,45 @@ static JSBool ShipGetProperty(JSContext *context, JSObject *this, jsval name, js
|
||||
break;
|
||||
|
||||
case kShip_maxThrust:
|
||||
OK = JS_NewDoubleValue(context, [entity maxThrust], outValue);
|
||||
OK = JS_NewDoubleValue(context, [entity maxThrust], value);
|
||||
break;
|
||||
|
||||
case kShip_thrust:
|
||||
OK = JS_NewDoubleValue(context, [entity thrust], outValue);
|
||||
OK = JS_NewDoubleValue(context, [entity thrust], value);
|
||||
break;
|
||||
|
||||
case kShip_lightsActive:
|
||||
*outValue = BOOLToJSVal([entity lightsActive]);
|
||||
*value = BOOLToJSVal([entity lightsActive]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kShip_vectorRight:
|
||||
OK = VectorToJSValue(context, [entity rightVector], outValue);
|
||||
OK = VectorToJSValue(context, [entity rightVector], value);
|
||||
break;
|
||||
|
||||
case kShip_vectorForward:
|
||||
OK = VectorToJSValue(context, [entity forwardVector], outValue);
|
||||
OK = VectorToJSValue(context, [entity forwardVector], value);
|
||||
break;
|
||||
|
||||
case kShip_vectorUp:
|
||||
OK = VectorToJSValue(context, [entity upVector], outValue);
|
||||
OK = VectorToJSValue(context, [entity upVector], value);
|
||||
break;
|
||||
|
||||
case kShip_velocity:
|
||||
OK = VectorToJSValue(context, [entity velocity], outValue);
|
||||
OK = VectorToJSValue(context, [entity velocity], value);
|
||||
break;
|
||||
|
||||
case kShip_thrustVector:
|
||||
OK = VectorToJSValue(context, [entity thrustVector], outValue);
|
||||
OK = VectorToJSValue(context, [entity thrustVector], value);
|
||||
break;
|
||||
|
||||
default:
|
||||
OOReportJSBadPropertySelector(context, @"Ship", JSVAL_TO_INT(name));
|
||||
OOReportJSBadPropertySelector(context, @"Ship", OOJS_PROPID_INT);
|
||||
}
|
||||
|
||||
if (result != nil)
|
||||
{
|
||||
*outValue = [result javaScriptValueInContext:context];
|
||||
*value = [result javaScriptValueInContext:context];
|
||||
OK = YES;
|
||||
}
|
||||
JS_LeaveLocalRootScope(context);
|
||||
@ -740,9 +740,9 @@ static JSBool ShipGetProperty(JSContext *context, JSObject *this, jsval name, js
|
||||
}
|
||||
|
||||
|
||||
static JSBool ShipSetProperty(JSContext *context, JSObject *this, jsval name, jsval *value)
|
||||
static JSBool ShipSetProperty(OOJS_PROP_ARGS)
|
||||
{
|
||||
if (!JSVAL_IS_INT(name)) return YES;
|
||||
if (!OOJS_PROPID_IS_INT) return YES;
|
||||
|
||||
OOJS_NATIVE_ENTER(context)
|
||||
|
||||
@ -760,7 +760,7 @@ static JSBool ShipSetProperty(JSContext *context, JSObject *this, jsval name, js
|
||||
if (EXPECT_NOT(!JSShipGetShipEntity(context, this, &entity))) return NO;
|
||||
if (EXPECT_NOT([entity isPlayer] && [UNIVERSE blockJSPlayerShipProps])) { *value = JSVAL_VOID; return YES;}
|
||||
|
||||
switch (JSVAL_TO_INT(name))
|
||||
switch (OOJS_PROPID_INT)
|
||||
{
|
||||
case kShip_name:
|
||||
if ([entity isPlayer])
|
||||
@ -1012,7 +1012,7 @@ static JSBool ShipSetProperty(JSContext *context, JSObject *this, jsval name, js
|
||||
break;
|
||||
|
||||
default:
|
||||
OOReportJSBadPropertySelector(context, @"Ship", JSVAL_TO_INT(name));
|
||||
OOReportJSBadPropertySelector(context, @"Ship", OOJS_PROPID_INT);
|
||||
}
|
||||
if (OK == NO)
|
||||
{
|
||||
|
@ -32,8 +32,8 @@ MA 02110-1301, USA.
|
||||
static JSObject *sShipGroupPrototype;
|
||||
|
||||
|
||||
static JSBool ShipGroupGetProperty(JSContext *context, JSObject *this, jsval name, jsval *outValue);
|
||||
static JSBool ShipGroupSetProperty(JSContext *context, JSObject *this, jsval name, jsval *value);
|
||||
static JSBool ShipGroupGetProperty(OOJS_PROP_ARGS);
|
||||
static JSBool ShipGroupSetProperty(OOJS_PROP_ARGS);
|
||||
static JSBool ShipGroupConstruct(JSContext *context, JSObject *this, uintN argc, jsval *argv, jsval *outResult);
|
||||
|
||||
// Methods
|
||||
@ -112,9 +112,9 @@ static BOOL JSShipGroupGetShipGroup(JSContext *context, JSObject *entityObj, OOS
|
||||
}
|
||||
|
||||
|
||||
static JSBool ShipGroupGetProperty(JSContext *context, JSObject *this, jsval name, jsval *outValue)
|
||||
static JSBool ShipGroupGetProperty(OOJS_PROP_ARGS)
|
||||
{
|
||||
if (!JSVAL_IS_INT(name)) return YES;
|
||||
if (!OOJS_PROPID_IS_INT) return YES;
|
||||
|
||||
OOJS_NATIVE_ENTER(context)
|
||||
|
||||
@ -124,7 +124,7 @@ static JSBool ShipGroupGetProperty(JSContext *context, JSObject *this, jsval nam
|
||||
|
||||
if (EXPECT_NOT(!JSShipGroupGetShipGroup(context, this, &group))) return NO;
|
||||
|
||||
switch (JSVAL_TO_INT(name))
|
||||
switch (OOJS_PROPID_INT)
|
||||
{
|
||||
case kShipGroup_ships:
|
||||
result = [group memberArray];
|
||||
@ -141,17 +141,17 @@ static JSBool ShipGroupGetProperty(JSContext *context, JSObject *this, jsval nam
|
||||
break;
|
||||
|
||||
case kShipGroup_count:
|
||||
*outValue = INT_TO_JSVAL([group count]);
|
||||
*value = INT_TO_JSVAL([group count]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
default:
|
||||
OOReportJSBadPropertySelector(context, @"ShipGroup", JSVAL_TO_INT(name));
|
||||
OOReportJSBadPropertySelector(context, @"ShipGroup", OOJS_PROPID_INT);
|
||||
}
|
||||
|
||||
if (!OK && result != nil)
|
||||
{
|
||||
*outValue = [result javaScriptValueInContext:context];
|
||||
*value = [result javaScriptValueInContext:context];
|
||||
OK = YES;
|
||||
}
|
||||
|
||||
@ -161,9 +161,9 @@ static JSBool ShipGroupGetProperty(JSContext *context, JSObject *this, jsval nam
|
||||
}
|
||||
|
||||
|
||||
static JSBool ShipGroupSetProperty(JSContext *context, JSObject *this, jsval name, jsval *value)
|
||||
static JSBool ShipGroupSetProperty(OOJS_PROP_ARGS)
|
||||
{
|
||||
if (!JSVAL_IS_INT(name)) return YES;
|
||||
if (!OOJS_PROPID_IS_INT) return YES;
|
||||
|
||||
OOJS_NATIVE_ENTER(context)
|
||||
|
||||
@ -173,7 +173,7 @@ static JSBool ShipGroupSetProperty(JSContext *context, JSObject *this, jsval nam
|
||||
|
||||
if (EXPECT_NOT(!JSShipGroupGetShipGroup(context, this, &group))) return NO;
|
||||
|
||||
switch (JSVAL_TO_INT(name))
|
||||
switch (OOJS_PROPID_INT)
|
||||
{
|
||||
case kShipGroup_leader:
|
||||
shipValue = JSValueToObjectOfClass(context, *value, [ShipEntity class]);
|
||||
@ -190,7 +190,7 @@ static JSBool ShipGroupSetProperty(JSContext *context, JSObject *this, jsval nam
|
||||
break;
|
||||
|
||||
default:
|
||||
OOReportJSBadPropertySelector(context, @"ShipGroup", JSVAL_TO_INT(name));
|
||||
OOReportJSBadPropertySelector(context, @"ShipGroup", OOJS_PROPID_INT);
|
||||
}
|
||||
|
||||
return OK;
|
||||
|
@ -39,7 +39,7 @@ DEFINE_JS_OBJECT_GETTER(JSSoundGetSound, OOSound)
|
||||
static OOSound *GetNamedSound(NSString *name);
|
||||
|
||||
|
||||
static JSBool SoundGetProperty(JSContext *context, JSObject *this, jsval name, jsval *outValue);
|
||||
static JSBool SoundGetProperty(OOJS_PROP_ARGS);
|
||||
|
||||
// Static methods
|
||||
static JSBool SoundStaticLoad(JSContext *context, JSObject *this, uintN argc, jsval *argv, jsval *outResult);
|
||||
@ -125,23 +125,23 @@ OOSound *SoundFromJSValue(JSContext *context, jsval value)
|
||||
|
||||
// *** Implementation stuff ***
|
||||
|
||||
static JSBool SoundGetProperty(JSContext *context, JSObject *this, jsval name, jsval *outValue)
|
||||
static JSBool SoundGetProperty(OOJS_PROP_ARGS)
|
||||
{
|
||||
OOJS_NATIVE_ENTER(context)
|
||||
|
||||
OOSound *sound = nil;
|
||||
|
||||
if (!JSVAL_IS_INT(name)) return YES;
|
||||
if (!OOJS_PROPID_IS_INT) return YES;
|
||||
if (EXPECT_NOT(!JSSoundGetSound(context, this, &sound))) return NO;
|
||||
|
||||
switch (JSVAL_TO_INT(name))
|
||||
switch (OOJS_PROPID_INT)
|
||||
{
|
||||
case kSound_name:
|
||||
*outValue = [[sound name] javaScriptValueInContext:context];
|
||||
*value = [[sound name] javaScriptValueInContext:context];
|
||||
break;
|
||||
|
||||
default:
|
||||
OOReportJSBadPropertySelector(context, @"Sound", JSVAL_TO_INT(name));
|
||||
OOReportJSBadPropertySelector(context, @"Sound", OOJS_PROPID_INT);
|
||||
return NO;
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@ static JSObject *sSoundSourcePrototype;
|
||||
DEFINE_JS_OBJECT_GETTER(JSSoundSourceGetSoundSource, OOSoundSource)
|
||||
|
||||
|
||||
static JSBool SoundSourceGetProperty(JSContext *context, JSObject *this, jsval name, jsval *outValue);
|
||||
static JSBool SoundSourceGetProperty(OOJS_PROP_ARGS);
|
||||
static JSBool SoundSourceSetProperty(JSContext *context, JSObject *this, jsval name, jsval *outValue);
|
||||
static JSBool SoundSourceConstruct(JSContext *context, JSObject *this, uintN argc, jsval *argv, jsval *outResult);
|
||||
|
||||
@ -117,9 +117,9 @@ static JSBool SoundSourceConstruct(JSContext *context, JSObject *this, uintN arg
|
||||
|
||||
// *** Implementation stuff ***
|
||||
|
||||
static JSBool SoundSourceGetProperty(JSContext *context, JSObject *this, jsval name, jsval *outValue)
|
||||
static JSBool SoundSourceGetProperty(OOJS_PROP_ARGS)
|
||||
{
|
||||
if (!JSVAL_IS_INT(name)) return YES;
|
||||
if (!OOJS_PROPID_IS_INT) return YES;
|
||||
|
||||
OOJS_NATIVE_ENTER(context)
|
||||
|
||||
@ -127,26 +127,26 @@ static JSBool SoundSourceGetProperty(JSContext *context, JSObject *this, jsval n
|
||||
|
||||
if (!JSSoundSourceGetSoundSource(context, this, &soundSource)) return NO;
|
||||
|
||||
switch (JSVAL_TO_INT(name))
|
||||
switch (OOJS_PROPID_INT)
|
||||
{
|
||||
case kSoundSource_sound:
|
||||
*outValue = [[soundSource sound] javaScriptValueInContext:context];
|
||||
*value = [[soundSource sound] javaScriptValueInContext:context];
|
||||
break;
|
||||
|
||||
case kSoundSource_isPlaying:
|
||||
*outValue = BOOLToJSVal([soundSource isPlaying]);
|
||||
*value = BOOLToJSVal([soundSource isPlaying]);
|
||||
break;
|
||||
|
||||
case kSoundSource_loop:
|
||||
*outValue = BOOLToJSVal([soundSource loop]);
|
||||
*value = BOOLToJSVal([soundSource loop]);
|
||||
break;
|
||||
|
||||
case kSoundSource_repeatCount:
|
||||
*outValue = INT_TO_JSVAL([soundSource repeatCount]);
|
||||
*value = INT_TO_JSVAL([soundSource repeatCount]);
|
||||
break;
|
||||
|
||||
default:
|
||||
OOReportJSBadPropertySelector(context, @"SoundSource", JSVAL_TO_INT(name));
|
||||
OOReportJSBadPropertySelector(context, @"SoundSource", OOJS_PROPID_INT);
|
||||
return NO;
|
||||
}
|
||||
|
||||
@ -156,9 +156,9 @@ static JSBool SoundSourceGetProperty(JSContext *context, JSObject *this, jsval n
|
||||
}
|
||||
|
||||
|
||||
static JSBool SoundSourceSetProperty(JSContext *context, JSObject *this, jsval name, jsval *value)
|
||||
static JSBool SoundSourceSetProperty(OOJS_PROP_ARGS)
|
||||
{
|
||||
if (!JSVAL_IS_INT(name)) return YES;
|
||||
if (!OOJS_PROPID_IS_INT) return YES;
|
||||
|
||||
OOJS_NATIVE_ENTER(context)
|
||||
|
||||
@ -169,7 +169,7 @@ static JSBool SoundSourceSetProperty(JSContext *context, JSObject *this, jsval n
|
||||
|
||||
if (!JSSoundSourceGetSoundSource(context, this, &soundSource)) return NO;
|
||||
|
||||
switch (JSVAL_TO_INT(name))
|
||||
switch (OOJS_PROPID_INT)
|
||||
{
|
||||
case kSoundSource_sound:
|
||||
OOJSPauseTimeLimiter();
|
||||
@ -197,7 +197,7 @@ static JSBool SoundSourceSetProperty(JSContext *context, JSObject *this, jsval n
|
||||
break;
|
||||
|
||||
default:
|
||||
OOReportJSBadPropertySelector(context, @"SoundSource", JSVAL_TO_INT(name));
|
||||
OOReportJSBadPropertySelector(context, @"SoundSource", OOJS_PROPID_INT);
|
||||
}
|
||||
|
||||
return OK;
|
||||
|
@ -35,8 +35,8 @@ static JSObject *sStationPrototype;
|
||||
static BOOL JSStationGetStationEntity(JSContext *context, JSObject *stationObj, StationEntity **outEntity);
|
||||
|
||||
|
||||
static JSBool StationGetProperty(JSContext *context, JSObject *this, jsval name, jsval *outValue);
|
||||
static JSBool StationSetProperty(JSContext *context, JSObject *this, jsval name, jsval *value);
|
||||
static JSBool StationGetProperty(OOJS_PROP_ARGS);
|
||||
static JSBool StationSetProperty(OOJS_PROP_ARGS);
|
||||
|
||||
static JSBool StationDockPlayer(JSContext *context, JSObject *this, uintN argc, jsval *argv, jsval *outResult);
|
||||
static JSBool StationLaunchShipWithRole(JSContext *context, JSObject *this, uintN argc, jsval *argv, jsval *outResult);
|
||||
@ -169,9 +169,9 @@ static BOOL JSStationGetStationEntity(JSContext *context, JSObject *stationObj,
|
||||
@end
|
||||
|
||||
|
||||
static JSBool StationGetProperty(JSContext *context, JSObject *this, jsval name, jsval *outValue)
|
||||
static JSBool StationGetProperty(OOJS_PROP_ARGS)
|
||||
{
|
||||
if (!JSVAL_IS_INT(name)) return YES;
|
||||
if (!OOJS_PROPID_IS_INT) return YES;
|
||||
|
||||
OOJS_NATIVE_ENTER(context)
|
||||
|
||||
@ -179,60 +179,60 @@ static JSBool StationGetProperty(JSContext *context, JSObject *this, jsval name,
|
||||
|
||||
if (!JSStationGetStationEntity(context, this, &entity)) return NO;
|
||||
|
||||
switch (JSVAL_TO_INT(name))
|
||||
switch (OOJS_PROPID_INT)
|
||||
{
|
||||
case kStation_isMainStation:
|
||||
*outValue = BOOLToJSVal(entity == [UNIVERSE station]);
|
||||
*value = BOOLToJSVal(entity == [UNIVERSE station]);
|
||||
break;
|
||||
|
||||
case kStation_hasNPCTraffic:
|
||||
*outValue = BOOLToJSVal([entity hasNPCTraffic]);
|
||||
*value = BOOLToJSVal([entity hasNPCTraffic]);
|
||||
break;
|
||||
|
||||
case kStation_alertCondition:
|
||||
*outValue = INT_TO_JSVAL([entity alertLevel]);
|
||||
*value = INT_TO_JSVAL([entity alertLevel]);
|
||||
break;
|
||||
|
||||
#if DOCKING_CLEARANCE_ENABLED
|
||||
case kStation_requiresDockingClearance:
|
||||
*outValue = BOOLToJSVal([entity requiresDockingClearance]);
|
||||
*value = BOOLToJSVal([entity requiresDockingClearance]);
|
||||
break;
|
||||
#endif
|
||||
|
||||
case kStation_allowsFastDocking:
|
||||
*outValue = BOOLToJSVal([entity allowsFastDocking]);
|
||||
*value = BOOLToJSVal([entity allowsFastDocking]);
|
||||
break;
|
||||
|
||||
case kStation_allowsAutoDocking:
|
||||
*outValue = BOOLToJSVal([entity allowsAutoDocking]);
|
||||
*value = BOOLToJSVal([entity allowsAutoDocking]);
|
||||
break;
|
||||
|
||||
case kStation_dockedContractors:
|
||||
*outValue = INT_TO_JSVAL([entity dockedContractors]);
|
||||
*value = INT_TO_JSVAL([entity dockedContractors]);
|
||||
break;
|
||||
|
||||
case kStation_dockedPolice:
|
||||
*outValue = INT_TO_JSVAL([entity dockedPolice]);
|
||||
*value = INT_TO_JSVAL([entity dockedPolice]);
|
||||
break;
|
||||
|
||||
case kStation_dockedDefenders:
|
||||
*outValue = INT_TO_JSVAL([entity dockedDefenders]);
|
||||
*value = INT_TO_JSVAL([entity dockedDefenders]);
|
||||
break;
|
||||
|
||||
case kStation_equivalentTechLevel:
|
||||
*outValue = INT_TO_JSVAL([entity equivalentTechLevel]);
|
||||
*value = INT_TO_JSVAL([entity equivalentTechLevel]);
|
||||
break;
|
||||
|
||||
case kStation_equipmentPriceFactor:
|
||||
JS_NewDoubleValue(context, [entity equipmentPriceFactor], outValue);
|
||||
JS_NewDoubleValue(context, [entity equipmentPriceFactor], value);
|
||||
break;
|
||||
|
||||
case kStation_suppressArrivalReports:
|
||||
*outValue = BOOLToJSVal([entity suppressArrivalReports]);
|
||||
*value = BOOLToJSVal([entity suppressArrivalReports]);
|
||||
break;
|
||||
|
||||
default:
|
||||
OOReportJSBadPropertySelector(context, @"Station", JSVAL_TO_INT(name));
|
||||
OOReportJSBadPropertySelector(context, @"Station", OOJS_PROPID_INT);
|
||||
return NO;
|
||||
}
|
||||
return YES;
|
||||
@ -241,9 +241,9 @@ static JSBool StationGetProperty(JSContext *context, JSObject *this, jsval name,
|
||||
}
|
||||
|
||||
|
||||
static JSBool StationSetProperty(JSContext *context, JSObject *this, jsval name, jsval *value)
|
||||
static JSBool StationSetProperty(OOJS_PROP_ARGS)
|
||||
{
|
||||
if (!JSVAL_IS_INT(name)) return YES;
|
||||
if (!OOJS_PROPID_IS_INT) return YES;
|
||||
|
||||
OOJS_NATIVE_ENTER(context)
|
||||
|
||||
@ -254,7 +254,7 @@ static JSBool StationSetProperty(JSContext *context, JSObject *this, jsval name,
|
||||
|
||||
if (!JSStationGetStationEntity(context, this, &entity)) return NO;
|
||||
|
||||
switch (JSVAL_TO_INT(name))
|
||||
switch (OOJS_PROPID_INT)
|
||||
{
|
||||
case kStation_hasNPCTraffic:
|
||||
if (JS_ValueToBoolean(context, *value, &bValue))
|
||||
@ -307,7 +307,7 @@ static JSBool StationSetProperty(JSContext *context, JSObject *this, jsval name,
|
||||
break;
|
||||
|
||||
default:
|
||||
OOReportJSBadPropertySelector(context, @"Station", JSVAL_TO_INT(name));
|
||||
OOReportJSBadPropertySelector(context, @"Station", OOJS_PROPID_INT);
|
||||
}
|
||||
|
||||
return OK;
|
||||
|
@ -36,7 +36,7 @@ DEFINE_JS_OBJECT_GETTER(JSSunGetSunEntity, OOSunEntity)
|
||||
static JSObject *sSunPrototype;
|
||||
|
||||
|
||||
static JSBool SunGetProperty(JSContext *context, JSObject *this, jsval name, jsval *outValue);
|
||||
static JSBool SunGetProperty(OOJS_PROP_ARGS);
|
||||
static JSBool SunGoNova(JSContext *context, JSObject *this, uintN argc, jsval *argv, jsval *outResult);
|
||||
static JSBool SunCancelNova(JSContext *context, JSObject *this, uintN argc, jsval *argv, jsval *outResult);
|
||||
|
||||
@ -116,9 +116,9 @@ void InitOOJSSun(JSContext *context, JSObject *global)
|
||||
@end
|
||||
|
||||
|
||||
static JSBool SunGetProperty(JSContext *context, JSObject *this, jsval name, jsval *outValue)
|
||||
static JSBool SunGetProperty(OOJS_PROP_ARGS)
|
||||
{
|
||||
if (!JSVAL_IS_INT(name)) return YES;
|
||||
if (!OOJS_PROPID_IS_INT) return YES;
|
||||
|
||||
OOJS_NATIVE_ENTER(context)
|
||||
|
||||
@ -127,25 +127,25 @@ static JSBool SunGetProperty(JSContext *context, JSObject *this, jsval name, jsv
|
||||
|
||||
if (EXPECT_NOT(!JSSunGetSunEntity(context, this, &sun))) return NO;
|
||||
|
||||
switch (JSVAL_TO_INT(name))
|
||||
switch (OOJS_PROPID_INT)
|
||||
{
|
||||
|
||||
case kSun_radius:
|
||||
OK = JS_NewDoubleValue(context, [sun radius], outValue);
|
||||
OK = JS_NewDoubleValue(context, [sun radius], value);
|
||||
break;
|
||||
|
||||
case kSun_hasGoneNova:
|
||||
*outValue = BOOLToJSVal([sun goneNova]);
|
||||
*value = BOOLToJSVal([sun goneNova]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kSun_isGoingNova:
|
||||
*outValue = BOOLToJSVal([sun willGoNova] && ![sun goneNova]);
|
||||
*value = BOOLToJSVal([sun willGoNova] && ![sun goneNova]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
default:
|
||||
OOReportJSBadPropertySelector(context, @"Sun", JSVAL_TO_INT(name));
|
||||
OOReportJSBadPropertySelector(context, @"Sun", OOJS_PROPID_INT);
|
||||
}
|
||||
return OK;
|
||||
|
||||
|
@ -50,8 +50,8 @@ static NSComparisonResult CompareEntitiesByDistance(id a, id b, void *relativeTo
|
||||
|
||||
static JSBool AddShipsOrGroup(JSContext *context, JSObject *this, uintN argc, jsval *argv, jsval *outResult, BOOL isGroup) NONNULL_FUNC;
|
||||
|
||||
static JSBool SystemGetProperty(JSContext *context, JSObject *this, jsval name, jsval *outValue);
|
||||
static JSBool SystemSetProperty(JSContext *context, JSObject *this, jsval name, jsval *value);
|
||||
static JSBool SystemGetProperty(OOJS_PROP_ARGS);
|
||||
static JSBool SystemSetProperty(OOJS_PROP_ARGS);
|
||||
|
||||
static JSBool SystemToString(JSContext *context, JSObject *this, uintN argc, jsval *argv, jsval *outResult);
|
||||
static JSBool SystemAddPlanet(JSContext *context, JSObject *this, uintN argc, jsval *argv, jsval *outResult);
|
||||
@ -200,9 +200,9 @@ void InitOOJSSystem(JSContext *context, JSObject *global)
|
||||
}
|
||||
|
||||
|
||||
static JSBool SystemGetProperty(JSContext *context, JSObject *this, jsval name, jsval *outValue)
|
||||
static JSBool SystemGetProperty(OOJS_PROP_ARGS)
|
||||
{
|
||||
if (!JSVAL_IS_INT(name)) return YES;
|
||||
if (!OOJS_PROPID_IS_INT) return YES;
|
||||
|
||||
OOJS_NATIVE_ENTER(context)
|
||||
|
||||
@ -220,10 +220,10 @@ static JSBool SystemGetProperty(JSContext *context, JSObject *this, jsval name,
|
||||
|
||||
systemData = [UNIVERSE generateSystemData:sCurrentSystem];
|
||||
|
||||
switch (JSVAL_TO_INT(name))
|
||||
switch (OOJS_PROPID_INT)
|
||||
{
|
||||
case kSystem_ID:
|
||||
*outValue = INT_TO_JSVAL([player currentSystemID]);
|
||||
*value = INT_TO_JSVAL([player currentSystemID]);
|
||||
break;
|
||||
|
||||
case kSystem_name:
|
||||
@ -242,7 +242,7 @@ static JSBool SystemGetProperty(JSContext *context, JSObject *this, jsval name,
|
||||
break;
|
||||
|
||||
case kSystem_government:
|
||||
*outValue = INT_TO_JSVAL([systemData oo_intForKey:KEY_GOVERNMENT]);
|
||||
*value = INT_TO_JSVAL([systemData oo_intForKey:KEY_GOVERNMENT]);
|
||||
break;
|
||||
|
||||
case kSystem_governmentDescription:
|
||||
@ -252,7 +252,7 @@ static JSBool SystemGetProperty(JSContext *context, JSObject *this, jsval name,
|
||||
break;
|
||||
|
||||
case kSystem_economy:
|
||||
*outValue = INT_TO_JSVAL([systemData oo_intForKey:KEY_ECONOMY]);
|
||||
*value = INT_TO_JSVAL([systemData oo_intForKey:KEY_ECONOMY]);
|
||||
break;
|
||||
|
||||
case kSystem_economyDescription:
|
||||
@ -262,19 +262,19 @@ static JSBool SystemGetProperty(JSContext *context, JSObject *this, jsval name,
|
||||
break;
|
||||
|
||||
case kSystem_techLevel:
|
||||
*outValue = INT_TO_JSVAL([systemData oo_intForKey:KEY_TECHLEVEL]);
|
||||
*value = INT_TO_JSVAL([systemData oo_intForKey:KEY_TECHLEVEL]);
|
||||
break;
|
||||
|
||||
case kSystem_population:
|
||||
*outValue = INT_TO_JSVAL([systemData oo_intForKey:KEY_POPULATION]);
|
||||
*value = INT_TO_JSVAL([systemData oo_intForKey:KEY_POPULATION]);
|
||||
break;
|
||||
|
||||
case kSystem_productivity:
|
||||
*outValue = INT_TO_JSVAL([systemData oo_intForKey:KEY_PRODUCTIVITY]);
|
||||
*value = INT_TO_JSVAL([systemData oo_intForKey:KEY_PRODUCTIVITY]);
|
||||
break;
|
||||
|
||||
case kSystem_isInterstellarSpace:
|
||||
*outValue = BOOLToJSVal([UNIVERSE inInterstellarSpace]);
|
||||
*value = BOOLToJSVal([UNIVERSE inInterstellarSpace]);
|
||||
break;
|
||||
|
||||
case kSystem_mainStation:
|
||||
@ -304,36 +304,36 @@ static JSBool SystemGetProperty(JSContext *context, JSObject *this, jsval name,
|
||||
break;
|
||||
|
||||
case kSystem_info:
|
||||
if (!GetJSSystemInfoForCurrentSystem(context, outValue)) return NO;
|
||||
if (!GetJSSystemInfoForCurrentSystem(context, value)) return NO;
|
||||
break;
|
||||
|
||||
case kSystem_pseudoRandomNumber:
|
||||
JS_NewDoubleValue(context, [player systemPseudoRandomFloat], outValue);
|
||||
JS_NewDoubleValue(context, [player systemPseudoRandomFloat], value);
|
||||
break;
|
||||
|
||||
case kSystem_pseudoRandom100:
|
||||
*outValue = INT_TO_JSVAL([player systemPseudoRandom100]);
|
||||
*value = INT_TO_JSVAL([player systemPseudoRandom100]);
|
||||
break;
|
||||
|
||||
case kSystem_pseudoRandom256:
|
||||
*outValue = INT_TO_JSVAL([player systemPseudoRandom256]);
|
||||
*value = INT_TO_JSVAL([player systemPseudoRandom256]);
|
||||
break;
|
||||
|
||||
default:
|
||||
OOReportJSBadPropertySelector(context, @"System", JSVAL_TO_INT(name));
|
||||
OOReportJSBadPropertySelector(context, @"System", OOJS_PROPID_INT);
|
||||
return NO;
|
||||
}
|
||||
|
||||
if (result != nil) *outValue = [result javaScriptValueInContext:context];
|
||||
if (result != nil) *value = [result javaScriptValueInContext:context];
|
||||
return YES;
|
||||
|
||||
OOJS_NATIVE_EXIT
|
||||
}
|
||||
|
||||
|
||||
static JSBool SystemSetProperty(JSContext *context, JSObject *this, jsval name, jsval *value)
|
||||
static JSBool SystemSetProperty(OOJS_PROP_ARGS)
|
||||
{
|
||||
if (!JSVAL_IS_INT(name)) return YES;
|
||||
if (!OOJS_PROPID_IS_INT) return YES;
|
||||
|
||||
OOJS_NATIVE_ENTER(context)
|
||||
|
||||
@ -351,7 +351,7 @@ static JSBool SystemSetProperty(JSContext *context, JSObject *this, jsval name,
|
||||
|
||||
if (system == -1) return YES; // Can't change anything in interstellar space.
|
||||
|
||||
switch (JSVAL_TO_INT(name))
|
||||
switch (OOJS_PROPID_INT)
|
||||
{
|
||||
case kSystem_name:
|
||||
stringValue = JSValToNSString(context, *value);
|
||||
@ -427,7 +427,7 @@ static JSBool SystemSetProperty(JSContext *context, JSObject *this, jsval name,
|
||||
break;
|
||||
|
||||
default:
|
||||
OOReportJSBadPropertySelector(context, @"System", JSVAL_TO_INT(name));
|
||||
OOReportJSBadPropertySelector(context, @"System", OOJS_PROPID_INT);
|
||||
}
|
||||
|
||||
return OK;
|
||||
|
@ -38,8 +38,8 @@ static OOSystemID sCachedSystem;
|
||||
|
||||
|
||||
static JSBool SystemInfoDeleteProperty(JSContext *context, JSObject *this, jsval name, jsval *value);
|
||||
static JSBool SystemInfoGetProperty(JSContext *context, JSObject *this, jsval name, jsval *outValue);
|
||||
static JSBool SystemInfoSetProperty(JSContext *context, JSObject *this, jsval name, jsval *value);
|
||||
static JSBool SystemInfoGetProperty(OOJS_PROP_ARGS);
|
||||
static JSBool SystemInfoSetProperty(OOJS_PROP_ARGS);
|
||||
static void SystemInfoFinalize(JSContext *context, JSObject *this);
|
||||
static JSBool SystemInfoDistanceToSystem(JSContext *context, JSObject *this, uintN argc, jsval *argv, jsval *outResult);
|
||||
static JSBool SystemInfoRouteToSystem(JSContext *context, JSObject *this, uintN argc, jsval *argv, jsval *outResult);
|
||||
@ -343,7 +343,7 @@ static JSBool SystemInfoDeleteProperty(JSContext *context, JSObject *this, jsval
|
||||
}
|
||||
|
||||
|
||||
static JSBool SystemInfoGetProperty(JSContext *context, JSObject *this, jsval name, jsval *outValue)
|
||||
static JSBool SystemInfoGetProperty(OOJS_PROP_ARGS)
|
||||
{
|
||||
volatile NSPoint coords;
|
||||
|
||||
@ -361,11 +361,11 @@ static JSBool SystemInfoGetProperty(JSContext *context, JSObject *this, jsval na
|
||||
BOOL sameGalaxy = [[PlayerEntity sharedPlayer] currentGalaxyID] == [info galaxy];
|
||||
|
||||
|
||||
if (JSVAL_IS_INT(name))
|
||||
if (OOJS_PROPID_IS_INT)
|
||||
{
|
||||
BOOL OK = NO;
|
||||
|
||||
switch (JSVAL_TO_INT(name))
|
||||
switch (OOJS_PROPID_INT)
|
||||
{
|
||||
case kSystemInfo_coordinates:
|
||||
if (sameGalaxy && !savedInterstellarInfo)
|
||||
@ -374,60 +374,59 @@ static JSBool SystemInfoGetProperty(JSContext *context, JSObject *this, jsval na
|
||||
// Convert from internal scale to light years.
|
||||
coords.x *= 0.4;
|
||||
coords.y *= 0.2; // y-axis had a different scale than x-axis
|
||||
OK = NSPointToVectorJSValue(context, coords, outValue);
|
||||
OK = NSPointToVectorJSValue(context, coords, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
OOReportJSError(context, @"Cannot read systemInfo values for %@.", savedInterstellarInfo ? @"invalid interstellar space reference" : @"other galaxies");
|
||||
*outValue = JSVAL_VOID;
|
||||
*value = JSVAL_VOID;
|
||||
// OK remains NO
|
||||
}
|
||||
break;
|
||||
|
||||
case kSystemInfo_galaxyID:
|
||||
*outValue = INT_TO_JSVAL([info galaxy]);
|
||||
*value = INT_TO_JSVAL([info galaxy]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
case kSystemInfo_systemID:
|
||||
*outValue = INT_TO_JSVAL([info system]);
|
||||
*value = INT_TO_JSVAL([info system]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
default:
|
||||
OOReportJSBadPropertySelector(context, @"SystemInfo", JSVAL_TO_INT(name));
|
||||
OOReportJSBadPropertySelector(context, @"SystemInfo", OOJS_PROPID_INT);
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
else if (JSVAL_IS_STRING(name))
|
||||
else if (OOJS_PROPID_IS_STRING)
|
||||
{
|
||||
NSString *key = [NSString stringWithJavaScriptValue:name inContext:context];
|
||||
id value = nil;
|
||||
NSString *key = [NSString stringWithJavaScriptString:OOJS_PROPID_STRING];
|
||||
|
||||
if (!sameGalaxy || savedInterstellarInfo)
|
||||
{
|
||||
OOReportJSError(context, @"Cannot read systemInfo values for %@.", savedInterstellarInfo ? @"invalid interstellar space reference" : @"other galaxies");
|
||||
*outValue = JSVAL_VOID;
|
||||
*value = JSVAL_VOID;
|
||||
return NO;
|
||||
}
|
||||
|
||||
value = [info valueForKey:key];
|
||||
id propValue = [info valueForKey:key];
|
||||
|
||||
if (value != nil)
|
||||
if (propValue != nil)
|
||||
{
|
||||
if ([value isKindOfClass:[NSNumber class]] || OOIsNumberLiteral(value, YES))
|
||||
if ([propValue isKindOfClass:[NSNumber class]] || OOIsNumberLiteral(propValue, YES))
|
||||
{
|
||||
BOOL OK = JS_NewDoubleValue(context, [value doubleValue], outValue);
|
||||
BOOL OK = JS_NewDoubleValue(context, [propValue doubleValue], value);
|
||||
if (!OK)
|
||||
{
|
||||
*outValue = JSVAL_VOID;
|
||||
*value = JSVAL_VOID;
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
*outValue = [value javaScriptValueInContext:context];
|
||||
*value = [propValue javaScriptValueInContext:context];
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -437,7 +436,7 @@ static JSBool SystemInfoGetProperty(JSContext *context, JSObject *this, jsval na
|
||||
}
|
||||
|
||||
|
||||
static JSBool SystemInfoSetProperty(JSContext *context, JSObject *this, jsval name, jsval *value)
|
||||
static JSBool SystemInfoSetProperty(OOJS_PROP_ARGS)
|
||||
{
|
||||
if (this == sSystemInfoPrototype)
|
||||
{
|
||||
@ -447,9 +446,9 @@ static JSBool SystemInfoSetProperty(JSContext *context, JSObject *this, jsval na
|
||||
|
||||
OOJS_NATIVE_ENTER(context);
|
||||
|
||||
if (JSVAL_IS_STRING(name))
|
||||
if (OOJS_PROPID_IS_STRING)
|
||||
{
|
||||
NSString *key = [NSString stringWithJavaScriptValue:name inContext:context];
|
||||
NSString *key = [NSString stringWithJavaScriptString:OOJS_PROPID_STRING];
|
||||
OOSystemInfo *info = JSObjectToObjectOfClass(context, this, [OOSystemInfo class]);
|
||||
|
||||
[info setValue:JSValToNSString(context, *value) forKey:key];
|
||||
|
@ -170,8 +170,8 @@ static JSClass sTimerClass;
|
||||
@end
|
||||
|
||||
|
||||
static JSBool TimerGetProperty(JSContext *context, JSObject *this, jsval name, jsval *outValue);
|
||||
static JSBool TimerSetProperty(JSContext *context, JSObject *this, jsval name, jsval *value);
|
||||
static JSBool TimerGetProperty(OOJS_PROP_ARGS);
|
||||
static JSBool TimerSetProperty(OOJS_PROP_ARGS);
|
||||
static void TimerFinalize(JSContext *context, JSObject *this);
|
||||
static JSBool TimerConstruct(JSContext *context, JSObject *this, uintN argc, jsval *argv, jsval *outResult);
|
||||
|
||||
@ -251,9 +251,9 @@ static BOOL JSTimerGetTimer(JSContext *context, JSObject *entityObj, OOJSTimer *
|
||||
}
|
||||
|
||||
|
||||
static JSBool TimerGetProperty(JSContext *context, JSObject *this, jsval name, jsval *outValue)
|
||||
static JSBool TimerGetProperty(OOJS_PROP_ARGS)
|
||||
{
|
||||
if (!JSVAL_IS_INT(name)) return YES;
|
||||
if (!OOJS_PROPID_IS_INT) return YES;
|
||||
|
||||
OOJS_NATIVE_ENTER(context)
|
||||
|
||||
@ -261,23 +261,23 @@ static JSBool TimerGetProperty(JSContext *context, JSObject *this, jsval name, j
|
||||
BOOL OK = NO;
|
||||
if (EXPECT_NOT(!JSTimerGetTimer(context, this, &timer))) return NO;
|
||||
|
||||
switch (JSVAL_TO_INT(name))
|
||||
switch (OOJS_PROPID_INT)
|
||||
{
|
||||
case kTimer_nextTime:
|
||||
OK = JS_NewDoubleValue(context, [timer nextTime], outValue);
|
||||
OK = JS_NewDoubleValue(context, [timer nextTime], value);
|
||||
break;
|
||||
|
||||
case kTimer_interval:
|
||||
OK = JS_NewDoubleValue(context, [timer interval], outValue);
|
||||
OK = JS_NewDoubleValue(context, [timer interval], value);
|
||||
break;
|
||||
|
||||
case kTimer_isRunning:
|
||||
*outValue = BOOLToJSVal([timer isScheduled]);
|
||||
*value = BOOLToJSVal([timer isScheduled]);
|
||||
OK = YES;
|
||||
break;
|
||||
|
||||
default:
|
||||
OOReportJSBadPropertySelector(context, @"Timer", JSVAL_TO_INT(name));
|
||||
OOReportJSBadPropertySelector(context, @"Timer", OOJS_PROPID_INT);
|
||||
}
|
||||
|
||||
return OK;
|
||||
@ -286,9 +286,9 @@ static JSBool TimerGetProperty(JSContext *context, JSObject *this, jsval name, j
|
||||
}
|
||||
|
||||
|
||||
static JSBool TimerSetProperty(JSContext *context, JSObject *this, jsval name, jsval *value)
|
||||
static JSBool TimerSetProperty(OOJS_PROP_ARGS)
|
||||
{
|
||||
if (!JSVAL_IS_INT(name)) return YES;
|
||||
if (!OOJS_PROPID_IS_INT) return YES;
|
||||
|
||||
OOJS_NATIVE_ENTER(context)
|
||||
|
||||
@ -298,7 +298,7 @@ static JSBool TimerSetProperty(JSContext *context, JSObject *this, jsval name, j
|
||||
|
||||
if (EXPECT_NOT(!JSTimerGetTimer(context, this, &timer))) return NO;
|
||||
|
||||
switch (JSVAL_TO_INT(name))
|
||||
switch (OOJS_PROPID_INT)
|
||||
{
|
||||
case kTimer_nextTime:
|
||||
if (JS_ValueToNumber(context, *value, &fValue))
|
||||
@ -320,7 +320,7 @@ static JSBool TimerSetProperty(JSContext *context, JSObject *this, jsval name, j
|
||||
break;
|
||||
|
||||
default:
|
||||
OOReportJSBadPropertySelector(context, @"Timer", JSVAL_TO_INT(name));
|
||||
OOReportJSBadPropertySelector(context, @"Timer", OOJS_PROPID_INT);
|
||||
}
|
||||
|
||||
return OK;
|
||||
|
@ -391,7 +391,7 @@ static JSBool VectorGetProperty(OOJS_PROP_ARGS)
|
||||
Vector vector;
|
||||
GLfloat fValue;
|
||||
|
||||
if (!OOJS_PROPID_IS_INT()) return YES;
|
||||
if (!OOJS_PROPID_IS_INT) return YES;
|
||||
if (EXPECT_NOT(!JSObjectGetVector(context, this, &vector))) return NO;
|
||||
|
||||
switch (OOJS_PROPID_INT)
|
||||
@ -426,7 +426,7 @@ static JSBool VectorSetProperty(OOJS_PROP_ARGS)
|
||||
Vector vector;
|
||||
jsdouble dval;
|
||||
|
||||
if (!OOJS_PROPID_IS_INT()) return YES;
|
||||
if (!OOJS_PROPID_IS_INT) return YES;
|
||||
if (EXPECT_NOT(!JSObjectGetVector(context, this, &vector))) return NO;
|
||||
if (EXPECT_NOT(!JS_ValueToNumber(context, *value, &dval)))
|
||||
{
|
||||
|
@ -29,7 +29,7 @@ MA 02110-1301, USA.
|
||||
#import "OOJSPlayer.h"
|
||||
|
||||
|
||||
static JSBool WorldScriptsGetProperty(JSContext *context, JSObject *this, jsval name, jsval *outValue);
|
||||
static JSBool WorldScriptsGetProperty(OOJS_PROP_ARGS);
|
||||
static JSBool WorldScriptsEnumerate(JSContext *cx, JSObject *obj);
|
||||
|
||||
static JSBool GetWorldScriptNames(JSContext *context, JSObject *this, jsval name, jsval *outValue);
|
||||
@ -58,7 +58,7 @@ void InitOOJSWorldScripts(JSContext *context, JSObject *global)
|
||||
}
|
||||
|
||||
|
||||
static JSBool WorldScriptsGetProperty(JSContext *context, JSObject *this, jsval name, jsval *outValue)
|
||||
static JSBool WorldScriptsGetProperty(OOJS_PROP_ARGS)
|
||||
{
|
||||
OOJS_NATIVE_ENTER(context)
|
||||
|
||||
@ -66,18 +66,20 @@ static JSBool WorldScriptsGetProperty(JSContext *context, JSObject *this, jsval
|
||||
NSString *scriptName = nil;
|
||||
id script = nil;
|
||||
|
||||
scriptName = JSValToNSString(context, name);
|
||||
if (!OOJS_PROPID_IS_STRING) return YES;
|
||||
scriptName = [NSString stringWithJavaScriptString:OOJS_PROPID_STRING];
|
||||
|
||||
if (scriptName != nil)
|
||||
{
|
||||
script = [[player worldScriptsByName] objectForKey:scriptName];
|
||||
if (script != nil)
|
||||
{
|
||||
/* If script is an OOJSScript, this should return a JS Script
|
||||
object. For other OOScript subclasses, it will return
|
||||
JSVAL_NULL. If no script exists, the value will be
|
||||
JSVAL_VOID.
|
||||
*/
|
||||
*outValue = [script javaScriptValueInContext:context];
|
||||
object. For other OOScript subclasses, it will return
|
||||
JSVAL_NULL. If no script exists, the value will be
|
||||
JSVAL_VOID.
|
||||
*/
|
||||
*value = [script javaScriptValueInContext:context];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -460,9 +460,11 @@ void OOJSDumpStack(NSString *logMessageClass, JSContext *context);
|
||||
#define OOJS_RETURN_QUATERNION(value) do { jsval jsresult; BOOL OK = QuaternionToJSValue(context, value, &jsresult); JS_SET_RVAL(context, vp, jsresult); return OK; } while (0)
|
||||
#define OOJS_RETURN_DOUBLE(value) do { JS_SET_RVAL(context, vp, DOUBLE_TO_JSVAL(value)); return YES; } while (0)
|
||||
|
||||
#define OOJS_PROP_ARGS JSContext *context, JSObject *this, jsid id_id, jsval *value
|
||||
#define OOJS_PROPID_IS_INT() JSID_IS_INT(id_id)
|
||||
#define OOJS_PROPID_INT JSID_TO_INT(id_id)
|
||||
#define OOJS_PROP_ARGS JSContext *context, JSObject *this, jsid propID, jsval *value
|
||||
#define OOJS_PROPID_IS_INT JSID_IS_INT(propID)
|
||||
#define OOJS_PROPID_INT JSID_TO_INT(propID)
|
||||
#define OOJS_PROPID_IS_STRING JSID_IS_STRING(propID)
|
||||
#define OOJS_PROPID_STRING JSID_TO_STRING(propID)
|
||||
|
||||
#else
|
||||
#define OOJS_NATIVE_ARGS JSContext *context, JSObject *this, uintN argc, jsval *argv, jsval *outResult
|
||||
@ -479,9 +481,11 @@ void OOJSDumpStack(NSString *logMessageClass, JSContext *context);
|
||||
#define OOJS_RETURN_QUATERNION(value) do { return QuaternionToJSValue(context, value, outResult); } while (0)
|
||||
#define OOJS_RETURN_DOUBLE(value) do { return JS_NewDoubleValue(context, result, outResult); } while (0)
|
||||
|
||||
#define OOJS_PROP_ARGS JSContext *context, JSObject *this, jsval id_val, jsval *value
|
||||
#define OOJS_PROPID_IS_INT() JSVAL_IS_INT(id_val)
|
||||
#define OOJS_PROPID_INT JSVAL_TO_INT(id_val)
|
||||
#define OOJS_PROP_ARGS JSContext *context, JSObject *this, jsval propID, jsval *value
|
||||
#define OOJS_PROPID_IS_INT JSVAL_IS_INT(propID)
|
||||
#define OOJS_PROPID_INT JSVAL_TO_INT(propID)
|
||||
#define OOJS_PROPID_IS_STRING JSVAL_IS_STRING(propID)
|
||||
#define OOJS_PROPID_STRING JSVAL_TO_STRING(propID)
|
||||
#endif
|
||||
|
||||
#define OOJS_ARG(n) (OOJS_ARGV[(n)])
|
||||
|
@ -696,6 +696,7 @@ void OOReportJSWarningWithArguments(JSContext *context, NSString *format, va_lis
|
||||
|
||||
void OOReportJSBadPropertySelector(JSContext *context, NSString *className, jsint selector)
|
||||
{
|
||||
// FIXME: after API upgrade, should take a jsid and decode it.
|
||||
OOReportJSError(context, @"Internal error: bad property identifier %i in property accessor for class %@.", selector, className);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user