38static JSBool
PlanetGetProperty(JSContext *context, JSObject *
this, jsid propID, jsval *value);
39static JSBool
PlanetSetProperty(JSContext *context, JSObject *
this, jsid propID, JSBool strict, jsval *value);
55 JSCLASS_NO_OPTIONAL_MEMBERS
107@implementation OOPlanetEntity (OOJavaScriptExtensions)
116- (void)getJSClass:(JSClass **)outClass andPrototype:(JSObject **)outPrototype
125 switch ([
self planetType])
141 if (!JSID_IS_INT(propID))
return YES;
145 OOPlanetEntity *planet =
nil;
146 if (!JSPlanetGetPlanetEntity(context,
this, &planet))
return NO;
148 switch (JSID_TO_INT(propID))
155 return JS_NewNumberValue(context, [planet airColorMixRatio], value);
158 return JS_NewNumberValue(context, [planet airDensity], value);
169 return JS_NewNumberValue(context, [planet radius], value);
187 return JS_NewNumberValue(context, [planet rotationalVelocity], value);
190 return VectorToJSValue(context, [planet terminatorThresholdVector], value);
201static JSBool
PlanetSetProperty(JSContext *context, JSObject *
this, jsid propID, JSBool strict, jsval *value)
203 if (!JSID_IS_INT(propID))
return YES;
207 OOPlanetEntity *planet =
nil;
208 NSString *sValue =
nil;
214 if (!JSPlanetGetPlanetEntity(context,
this, &planet))
return NO;
216 switch (JSID_TO_INT(propID))
220 if (colorForScript !=
nil || JSVAL_IS_NULL(*value))
222 [planet setAirColor:colorForScript];
228 if (JS_ValueToNumber(context, *value, &dValue))
230 [planet setAirColorMixRatio:dValue];
236 if (JS_ValueToNumber(context, *value, &dValue))
238 [planet setAirDensity:dValue];
245 if (colorForScript !=
nil || JSVAL_IS_NULL(*value))
247 [planet setIlluminationColor:colorForScript];
254 [planet setName:sValue];
264 if ([planet isKindOfClass:[OOPlanetEntity
class]])
278 OK = [planet setUpPlanetFromTexture:sValue];
279 if (!OK)
OOJSReportWarning(context,
@"Cannot find texture \"%@\
". Value not set.", sValue);
290 quaternion_normalize(&qValue);
291 [planet setOrientation:qValue];
297 if (JS_ValueToNumber(context, *value, &dValue))
299 [planet setRotationalVelocity:dValue];
307 [planet setTerminatorThresholdVector:vValue];
#define OOJS_NATIVE_ENTER(cx)
OOINLINE JSClass * JSEntityClass(void)
OOINLINE JSObject * JSEntityPrototype(void)
void InitOOJSPlanet(JSContext *context, JSObject *global)
static JSClass sPlanetClass
static JSObject * sPlanetPrototype
static JSPropertySpec sPlanetProperties[]
static JSBool PlanetGetProperty(JSContext *context, JSObject *this, jsid propID, jsval *value)
static JSBool PlanetSetProperty(JSContext *context, JSObject *this, jsid propID, JSBool strict, jsval *value)
@ kPlanet_airColorMixRatio
@ kPlanet_terminatorThresholdVector
@ kPlanet_rotationalVelocity
@ kPlanet_illuminationColor
BOOL JSValueToQuaternion(JSContext *context, jsval value, Quaternion *outQuaternion) NONNULL_FUNC
BOOL QuaternionToJSValue(JSContext *context, Quaternion quaternion, jsval *outValue) NONNULL_FUNC
BOOL JSValueToVector(JSContext *context, jsval value, Vector *outVector) NONNULL_FUNC
BOOL VectorToJSValue(JSContext *context, Vector vector, jsval *outValue) NONNULL_FUNC
void OOJSPauseTimeLimiter(void)
void OOJSReportWarning(JSContext *context, NSString *format,...)
#define OOJS_PROP_READWRITE_CB
void OOJSRegisterObjectConverter(JSClass *theClass, OOJSClassConverterCallback converter)
OOINLINE jsval OOJSValueFromNativeObject(JSContext *context, id object)
#define DEFINE_JS_OBJECT_GETTER(NAME, JSCLASS, JSPROTO, OBJCCLASSNAME)
void OOJSObjectWrapperFinalize(JSContext *context, JSObject *this)
void OOJSReportBadPropertySelector(JSContext *context, JSObject *thisObj, jsid propID, JSPropertySpec *propertySpec)
NSString * OOStringFromJSValue(JSContext *context, jsval value)
JSBool OOJSUnconstructableConstruct(JSContext *context, uintN argc, jsval *vp)
void OOJSRegisterSubclass(JSClass *subclass, JSClass *superclass)
OOINLINE jsval OOJSValueFromBOOL(int b) INLINE_CONST_FUNC
void OOJSReportBadPropertyValue(JSContext *context, JSObject *thisObj, jsid propID, JSPropertySpec *propertySpec, jsval value)
id OOJSBasicPrivateObjectConverter(JSContext *context, JSObject *object)
#define OOJS_PROP_READONLY_CB
void OOJSResumeTimeLimiter(void)
@ STELLAR_TYPE_NORMAL_PLANET
BOOL isVisibleToScripts()
NSString * oo_jsClassName()
OOColor * colorWithDescription:(id description)