Oolite 1.91.0.7646-241128-10e222e
Loading...
Searching...
No Matches
OOJSPlanet.m File Reference
import "OOJSPlanet.h"
import "OOJSEntity.h"
import "OOJavaScriptEngine.h"
import "OOJSQuaternion.h"
import "OOJSVector.h"
import "OOPlanetEntity.h"
+ Include dependency graph for OOJSPlanet.m:

Go to the source code of this file.

Enumerations

enum  {
  kPlanet_airColor , kPlanet_airColorMixRatio , kPlanet_airDensity , kPlanet_hasAtmosphere ,
  kPlanet_illuminationColor , kPlanet_isMainPlanet , kPlanet_name , kPlanet_radius ,
  kPlanet_texture , kPlanet_orientation , kPlanet_rotationalVelocity , kPlanet_terminatorThresholdVector
}
 

Functions

static JSBool PlanetGetProperty (JSContext *context, JSObject *this, jsid propID, jsval *value)
 
static JSBool PlanetSetProperty (JSContext *context, JSObject *this, jsid propID, JSBool strict, jsval *value)
 
void InitOOJSPlanet (JSContext *context, JSObject *global)
 

Variables

static JSObject * sPlanetPrototype
 
static JSClass sPlanetClass
 
static JSPropertySpec sPlanetProperties []
 

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
kPlanet_airColor 
kPlanet_airColorMixRatio 
kPlanet_airDensity 
kPlanet_hasAtmosphere 
kPlanet_illuminationColor 
kPlanet_isMainPlanet 
kPlanet_name 
kPlanet_radius 
kPlanet_texture 
kPlanet_orientation 
kPlanet_rotationalVelocity 
kPlanet_terminatorThresholdVector 

Definition at line 59 of file OOJSPlanet.m.

60{
61 // Property IDs
62 kPlanet_airColor, // air color, read/write
63 kPlanet_airColorMixRatio, // air color mix ratio, float, read/write
64 kPlanet_airDensity, // air density, float, read/write
66 kPlanet_illuminationColor, // illumination color, read/write
67 kPlanet_isMainPlanet, // Is [UNIVERSE planet], boolean, read-only
68 kPlanet_name, // Name of planet, string, read/write
69 kPlanet_radius, // Radius of planet in metres, read-only
70 kPlanet_texture, // Planet texture read / write
71 kPlanet_orientation, // orientation, quaternion, read/write
72 kPlanet_rotationalVelocity, // read/write
74};
@ kPlanet_airColor
Definition OOJSPlanet.m:62
@ kPlanet_orientation
Definition OOJSPlanet.m:71
@ kPlanet_radius
Definition OOJSPlanet.m:69
@ kPlanet_airColorMixRatio
Definition OOJSPlanet.m:63
@ kPlanet_isMainPlanet
Definition OOJSPlanet.m:67
@ kPlanet_terminatorThresholdVector
Definition OOJSPlanet.m:73
@ kPlanet_airDensity
Definition OOJSPlanet.m:64
@ kPlanet_name
Definition OOJSPlanet.m:68
@ kPlanet_rotationalVelocity
Definition OOJSPlanet.m:72
@ kPlanet_hasAtmosphere
Definition OOJSPlanet.m:65
@ kPlanet_illuminationColor
Definition OOJSPlanet.m:66
@ kPlanet_texture
Definition OOJSPlanet.m:70

Function Documentation

◆ InitOOJSPlanet()

void InitOOJSPlanet ( JSContext * context,
JSObject * global )

Definition at line 99 of file OOJSPlanet.m.

100{
101 sPlanetPrototype = JS_InitClass(context, global, JSEntityPrototype(), &sPlanetClass, OOJSUnconstructableConstruct, 0, sPlanetProperties, NULL, NULL, NULL);
104}
OOINLINE JSClass * JSEntityClass(void)
Definition OOJSEntity.h:42
OOINLINE JSObject * JSEntityPrototype(void)
Definition OOJSEntity.h:43
static JSClass sPlanetClass
Definition OOJSPlanet.m:42
static JSObject * sPlanetPrototype
Definition OOJSPlanet.m:35
static JSPropertySpec sPlanetProperties[]
Definition OOJSPlanet.m:77
void OOJSRegisterObjectConverter(JSClass *theClass, OOJSClassConverterCallback converter)
JSBool OOJSUnconstructableConstruct(JSContext *context, uintN argc, jsval *vp)
void OOJSRegisterSubclass(JSClass *subclass, JSClass *superclass)
id OOJSBasicPrivateObjectConverter(JSContext *context, JSObject *object)

References JSEntityClass(), JSEntityPrototype(), OOJSBasicPrivateObjectConverter(), OOJSRegisterObjectConverter(), OOJSRegisterSubclass(), OOJSUnconstructableConstruct(), sPlanetClass, sPlanetProperties, and sPlanetPrototype.

+ Here is the call graph for this function:

◆ PlanetGetProperty()

static JSBool PlanetGetProperty ( JSContext * context,
JSObject * this,
jsid propID,
jsval * value )
static

Definition at line 139 of file OOJSPlanet.m.

140{
141 if (!JSID_IS_INT(propID)) return YES;
142
143 OOJS_NATIVE_ENTER(context)
144
145 OOPlanetEntity *planet = nil;
146 if (!JSPlanetGetPlanetEntity(context, this, &planet)) return NO;
147
148 switch (JSID_TO_INT(propID))
149 {
150 case kPlanet_airColor:
151 *value = OOJSValueFromNativeObject(context, [[planet airColor] normalizedArray]);
152 return YES;
153
155 return JS_NewNumberValue(context, [planet airColorMixRatio], value);
156
158 return JS_NewNumberValue(context, [planet airDensity], value);
159
161 *value = OOJSValueFromNativeObject(context, [[planet illuminationColor] normalizedArray]);
162 return YES;
163
165 *value = OOJSValueFromBOOL(planet == (id)[UNIVERSE planet]);
166 return YES;
167
168 case kPlanet_radius:
169 return JS_NewNumberValue(context, [planet radius], value);
170
172 *value = OOJSValueFromBOOL([planet hasAtmosphere]);
173 return YES;
174
175 case kPlanet_texture:
176 *value = OOJSValueFromNativeObject(context, [planet textureFileName]);
177 return YES;
178
179 case kPlanet_name:
180 *value = OOJSValueFromNativeObject(context, [planet name]);
181 return YES;
182
184 return QuaternionToJSValue(context, [planet normalOrientation], value);
185
187 return JS_NewNumberValue(context, [planet rotationalVelocity], value);
188
190 return VectorToJSValue(context, [planet terminatorThresholdVector], value);
191
192 default:
193 OOJSReportBadPropertySelector(context, this, propID, sPlanetProperties);
194 return NO;
195 }
196
198}
#define OOJS_NATIVE_ENTER(cx)
#define OOJS_NATIVE_EXIT
BOOL QuaternionToJSValue(JSContext *context, Quaternion quaternion, jsval *outValue) NONNULL_FUNC
BOOL VectorToJSValue(JSContext *context, Vector vector, jsval *outValue) NONNULL_FUNC
Definition OOJSVector.m:185
OOINLINE jsval OOJSValueFromNativeObject(JSContext *context, id object)
void OOJSReportBadPropertySelector(JSContext *context, JSObject *thisObj, jsid propID, JSPropertySpec *propertySpec)
OOINLINE jsval OOJSValueFromBOOL(int b) INLINE_CONST_FUNC
return nil
#define UNIVERSE
Definition Universe.h:840

References kPlanet_airColor, kPlanet_airColorMixRatio, kPlanet_airDensity, kPlanet_hasAtmosphere, kPlanet_illuminationColor, kPlanet_isMainPlanet, kPlanet_name, kPlanet_orientation, kPlanet_radius, kPlanet_rotationalVelocity, kPlanet_terminatorThresholdVector, kPlanet_texture, nil, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJSReportBadPropertySelector(), OOJSValueFromBOOL(), OOJSValueFromNativeObject(), QuaternionToJSValue(), sPlanetProperties, UNIVERSE, and VectorToJSValue().

+ Here is the call graph for this function:

◆ PlanetSetProperty()

static JSBool PlanetSetProperty ( JSContext * context,
JSObject * this,
jsid propID,
JSBool strict,
jsval * value )
static

Definition at line 201 of file OOJSPlanet.m.

202{
203 if (!JSID_IS_INT(propID)) return YES;
204
205 OOJS_NATIVE_ENTER(context)
206
207 OOPlanetEntity *planet = nil;
208 NSString *sValue = nil;
209 Quaternion qValue;
210 Vector vValue;
211 jsdouble dValue;
212 OOColor *colorForScript = nil;
213
214 if (!JSPlanetGetPlanetEntity(context, this, &planet)) return NO;
215
216 switch (JSID_TO_INT(propID))
217 {
218 case kPlanet_airColor:
219 colorForScript = [OOColor colorWithDescription:OOJSNativeObjectFromJSValue(context, *value)];
220 if (colorForScript != nil || JSVAL_IS_NULL(*value))
221 {
222 [planet setAirColor:colorForScript];
223 return YES;
224 }
225 break;
226
228 if (JS_ValueToNumber(context, *value, &dValue))
229 {
230 [planet setAirColorMixRatio:dValue];
231 return YES;
232 }
233 break;
234
236 if (JS_ValueToNumber(context, *value, &dValue))
237 {
238 [planet setAirDensity:dValue];
239 return YES;
240 }
241 break;
242
244 colorForScript = [OOColor colorWithDescription:OOJSNativeObjectFromJSValue(context, *value)];
245 if (colorForScript != nil || JSVAL_IS_NULL(*value))
246 {
247 [planet setIlluminationColor:colorForScript];
248 return YES;
249 }
250 break;
251
252 case kPlanet_name:
253 sValue = OOStringFromJSValue(context, *value);
254 [planet setName:sValue];
255 return YES;
256
257 case kPlanet_texture:
258 {
259 BOOL OK = NO;
260 sValue = OOStringFromJSValue(context, *value);
261
263
264 if ([planet isKindOfClass:[OOPlanetEntity class]])
265 {
266 if (sValue == nil)
267 {
268 OOJSReportWarning(context, @"Expected texture string. Value not set.");
269 }
270 else
271 {
272 OK = YES;
273 }
274 }
275
276 if (OK)
277 {
278 OK = [planet setUpPlanetFromTexture:sValue];
279 if (!OK) OOJSReportWarning(context, @"Cannot find texture \"%@\". Value not set.", sValue);
280 }
281
283
284 return YES; // Even if !OK, no exception was raised.
285 }
286
288 if (JSValueToQuaternion(context, *value, &qValue))
289 {
290 quaternion_normalize(&qValue);
291 [planet setOrientation:qValue];
292 return YES;
293 }
294 break;
295
297 if (JS_ValueToNumber(context, *value, &dValue))
298 {
299 [planet setRotationalVelocity:dValue];
300 return YES;
301 }
302 break;
303
305 if (JSValueToVector(context, *value, &vValue))
306 {
307 [planet setTerminatorThresholdVector:vValue];
308 return YES;
309 }
310 break;
311
312 default:
313 OOJSReportBadPropertySelector(context, this, propID, sPlanetProperties);
314 return NO;
315 }
316
317 OOJSReportBadPropertyValue(context, this, propID, sPlanetProperties, *value);
318 return NO;
319
321}
BOOL JSValueToQuaternion(JSContext *context, jsval value, Quaternion *outQuaternion) NONNULL_FUNC
BOOL JSValueToVector(JSContext *context, jsval value, Vector *outVector) NONNULL_FUNC
Definition OOJSVector.m:259
void OOJSPauseTimeLimiter(void)
void OOJSReportWarning(JSContext *context, NSString *format,...)
NSString * OOStringFromJSValue(JSContext *context, jsval value)
void OOJSReportBadPropertyValue(JSContext *context, JSObject *thisObj, jsid propID, JSPropertySpec *propertySpec, jsval value)
void OOJSResumeTimeLimiter(void)
OOColor * colorWithDescription:(id description)
Definition OOColor.m:127

Variable Documentation

◆ sPlanetClass

JSClass sPlanetClass
static
Initial value:
=
{
"Planet",
JSCLASS_HAS_PRIVATE,
JS_PropertyStub,
JS_PropertyStub,
JS_EnumerateStub,
JS_ResolveStub,
JS_ConvertStub,
JSCLASS_NO_OPTIONAL_MEMBERS
}
static JSBool PlanetGetProperty(JSContext *context, JSObject *this, jsid propID, jsval *value)
Definition OOJSPlanet.m:139
static JSBool PlanetSetProperty(JSContext *context, JSObject *this, jsid propID, JSBool strict, jsval *value)
Definition OOJSPlanet.m:201
void OOJSObjectWrapperFinalize(JSContext *context, JSObject *this)

Definition at line 42 of file OOJSPlanet.m.

43{
44 "Planet",
45 JSCLASS_HAS_PRIVATE,
46
47 JS_PropertyStub, // addProperty
48 JS_PropertyStub, // delProperty
49 PlanetGetProperty, // getProperty
50 PlanetSetProperty, // setProperty
51 JS_EnumerateStub, // enumerate
52 JS_ResolveStub, // resolve
53 JS_ConvertStub, // convert
55 JSCLASS_NO_OPTIONAL_MEMBERS
56};

Referenced by InitOOJSPlanet().

◆ sPlanetProperties

JSPropertySpec sPlanetProperties[]
static
Initial value:

Definition at line 77 of file OOJSPlanet.m.

78{
79 // JS name ID flags
81 { "airColorMixRatio", kPlanet_airColorMixRatio, OOJS_PROP_READWRITE_CB },
83 { "hasAtmosphere", kPlanet_hasAtmosphere, OOJS_PROP_READONLY_CB },
84 { "illuminationColor", kPlanet_illuminationColor, OOJS_PROP_READWRITE_CB },
88 { "rotationalVelocity", kPlanet_rotationalVelocity, OOJS_PROP_READWRITE_CB },
90 { "orientation", kPlanet_orientation, OOJS_PROP_READWRITE_CB }, // Not documented since it's inherited from Entity
91 { "terminatorThresholdVector", kPlanet_terminatorThresholdVector, OOJS_PROP_READWRITE_CB },
92 { 0 }
93};

Referenced by OOPlanetEntity(OOJavaScriptExtensions)::getJSClass:andPrototype:, InitOOJSPlanet(), and PlanetGetProperty().

◆ sPlanetPrototype

JSObject* sPlanetPrototype
static

Definition at line 35 of file OOJSPlanet.m.

Referenced by InitOOJSPlanet().