41static JSBool
EntityGetProperty(JSContext *context, JSObject *
this, jsid propID, jsval *value);
42static JSBool
EntitySetProperty(JSContext *context, JSObject *
this, jsid propID, JSBool strict, jsval *value);
44static JSBool
EntityDumpState(JSContext *context, uintN argc, jsval *vp);
61 JSCLASS_NO_OPTIONAL_MEMBERS
148 if (JSVAL_IS_OBJECT(value))
150 return OOJSEntityGetEntity(context, JSVAL_TO_OBJECT(value), outEntity);
157BOOL
EntityFromArgumentList(JSContext *context, NSString *scriptClass, NSString *
function, uintN argc, jsval *argv,
Entity **outEntity, uintN *outConsumed)
162 if (outConsumed != NULL) *outConsumed = 0;
163 if (
EXPECT_NOT(argc == 0 || argv == NULL || outEntity == NULL))
173 if (scriptClass !=
nil &&
function !=
nil)
175 OOJSReportWarning(context,
@"%@.%@(): expected entity, got %@.", scriptClass,
function, [NSString stringWithJavaScriptParameters:argv
count:1 inContext:context]);
181 if (outConsumed != NULL) *outConsumed = 1;
190 if (!JSID_IS_INT(propID))
return YES;
197 if (
EXPECT_NOT(!OOJSEntityGetEntity(context,
this, &entity)))
return NO;
201 else { *value = JSVAL_VOID; }
205 switch (JSID_TO_INT(propID))
208 return JS_NewNumberValue(context, [entity collisionRadius], value);
228 return JS_NewNumberValue(context, [entity mass], value);
231 result = [entity
owner];
232 if (result == entity) result =
nil;
236 return JS_NewNumberValue(context, [entity energy], value);
239 return JS_NewNumberValue(context, [entity maxEnergy], value);
242 *value = [entity
status] == STATUS_DEAD ? JSVAL_FALSE : JSVAL_TRUE;
294 return JS_NewNumberValue(context, [entity distanceTravelled], value);
297 return JS_NewNumberValue(context, [entity spawnTime], value);
310static JSBool
EntitySetProperty(JSContext *context, JSObject *
this, jsid propID, JSBool strict, jsval *value)
312 if (!JSID_IS_INT(propID))
return YES;
321 if (
EXPECT_NOT(!OOJSEntityGetEntity(context,
this, &entity)))
return NO;
324 switch (JSID_TO_INT(propID))
348 if (JS_ValueToNumber(context, *value, &fValue))
350 fValue = OOClamp_0_max_d(fValue, [entity maxEnergy]);
357 if (JS_ValueToNumber(context, *value, &fValue))
371 if ([entity isShip] && ![entity isPlayer])
374 if (newClass == CLASS_NOT_SET || newClass == CLASS_NO_DRAW || newClass == CLASS_TARGET || newClass == CLASS_WORMHOLE || newClass == CLASS_PLAYER || newClass == CLASS_VISUAL_EFFECT)
376 OOJSReportError(context,
@"entity.scanClass cannot be set to that value.");
384 OOJSReportError(context,
@"entity.scanClass is read-only except on NPC ships.");
405 OOJSEntityGetEntity(context,
OOJS_THIS, &thisEnt);
OOINLINE jsval OOJSValueFromScanClass(JSContext *context, OOScanClass value)
OOINLINE jsval OOJSValueFromEntityStatus(JSContext *context, OOEntityStatus value)
OOINLINE OOScanClass OOScanClassFromJSValue(JSContext *context, jsval value)
#define OOJS_PROFILE_EXIT
#define OOJS_NATIVE_ENTER(cx)
#define OOJS_PROFILE_ENTER
OOINLINE BOOL OOIsStaleEntity(Entity *entity)
static JSBool EntityDumpState(JSContext *context, uintN argc, jsval *vp)
static JSBool EntitySetProperty(JSContext *context, JSObject *this, jsid propID, JSBool strict, jsval *value)
BOOL JSValueToEntity(JSContext *context, jsval value, Entity **outEntity)
static JSBool EntityGetProperty(JSContext *context, JSObject *this, jsid propID, jsval *value)
BOOL EntityFromArgumentList(JSContext *context, NSString *scriptClass, NSString *function, uintN argc, jsval *argv, Entity **outEntity, uintN *outConsumed)
@ kEntity_distanceTravelled
@ kEntity_collisionRadius
JSObject * gOOEntityJSPrototype
static JSFunctionSpec sEntityMethods[]
static JSPropertySpec sEntityProperties[]
void InitOOJSEntity(JSContext *context, JSObject *global)
BOOL JSValueToQuaternion(JSContext *context, jsval value, Quaternion *outQuaternion) NONNULL_FUNC
BOOL QuaternionToJSValue(JSContext *context, Quaternion quaternion, jsval *outValue) NONNULL_FUNC
BOOL HPVectorToJSValue(JSContext *context, HPVector vector, jsval *outValue) NONNULL_FUNC
BOOL JSValueToHPVector(JSContext *context, jsval value, HPVector *outVector) NONNULL_FUNC
BOOL VectorToJSValue(JSContext *context, Vector vector, jsval *outValue) NONNULL_FUNC
void OOJSReportWarning(JSContext *context, NSString *format,...)
JSBool OOJSObjectWrapperToString(JSContext *context, uintN argc, jsval *vp)
#define OOJS_PROP_READWRITE_CB
void OOJSRegisterObjectConverter(JSClass *theClass, OOJSClassConverterCallback converter)
OOINLINE jsval OOJSValueFromNativeObject(JSContext *context, id object)
void OOJSObjectWrapperFinalize(JSContext *context, JSObject *this)
void OOJSReportBadPropertySelector(JSContext *context, JSObject *thisObj, jsid propID, JSPropertySpec *propertySpec)
JSBool OOJSUnconstructableConstruct(JSContext *context, uintN argc, jsval *vp)
void OOJSReportError(JSContext *context, NSString *format,...)
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
#define OOLogGenericParameterError()
Vector vector_forward_from_quaternion(Quaternion quat)
void setMaxEnergy:(GLfloat amount)
void setNormalOrientation:(Quaternion quat)
void setScanClass:(OOScanClass sClass)
void setEnergy:(GLfloat amount)
void setPosition:(HPVector posn)