Oolite 1.91.0.7645-241119-222d325
Loading...
Searching...
No Matches
OOJSFlasher.m File Reference
+ Include dependency graph for OOJSFlasher.m:

Go to the source code of this file.

Macros

#define GET_THIS_FLASHER(THISENT)
 

Enumerations

enum  {
  kFlasher_active , kFlasher_color , kFlasher_fraction , kFlasher_frequency ,
  kFlasher_phase , kFlasher_size
}
 

Functions

static BOOL JSFlasherGetFlasherEntity (JSContext *context, JSObject *jsobj, OOFlasherEntity **outEntity)
 
static JSBool FlasherGetProperty (JSContext *context, JSObject *this, jsid propID, jsval *value)
 
static JSBool FlasherSetProperty (JSContext *context, JSObject *this, jsid propID, JSBool strict, jsval *value)
 
static JSBool FlasherRemove (JSContext *context, uintN argc, jsval *vp)
 
void InitOOJSFlasher (JSContext *context, JSObject *global)
 

Variables

static JSObject * sFlasherPrototype
 
static JSClass sFlasherClass
 
static JSPropertySpec sFlasherProperties []
 
static JSFunctionSpec sFlasherMethods []
 

Macro Definition Documentation

◆ GET_THIS_FLASHER

#define GET_THIS_FLASHER ( THISENT)
Value:
do { \
if (EXPECT_NOT(!JSFlasherGetFlasherEntity(context, OOJS_THIS, &THISENT))) return NO; /* Exception */ \
} while (0)
#define EXPECT_NOT(x)
OOINLINE BOOL OOIsStaleEntity(Entity *entity)
Definition OOJSEntity.h:71
static BOOL JSFlasherGetFlasherEntity(JSContext *context, JSObject *jsobj, OOFlasherEntity **outEntity)
#define OOJS_THIS
#define OOJS_RETURN_VOID

Definition at line 282 of file OOJSFlasher.m.

282#define GET_THIS_FLASHER(THISENT) do { \
283 if (EXPECT_NOT(!JSFlasherGetFlasherEntity(context, OOJS_THIS, &THISENT))) return NO; /* Exception */ \
284 if (OOIsStaleEntity(THISENT)) OOJS_RETURN_VOID; \
285} while (0)

Referenced by OOFlasherEntity(OOJavaScriptExtensions)::getJSClass:andPrototype:.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
kFlasher_active 
kFlasher_color 
kFlasher_fraction 
kFlasher_frequency 
kFlasher_phase 
kFlasher_size 

Definition at line 62 of file OOJSFlasher.m.

63{
64 // Property IDs
71};
@ kFlasher_size
Definition OOJSFlasher.m:70
@ kFlasher_phase
Definition OOJSFlasher.m:69
@ kFlasher_active
Definition OOJSFlasher.m:65
@ kFlasher_fraction
Definition OOJSFlasher.m:67
@ kFlasher_frequency
Definition OOJSFlasher.m:68
@ kFlasher_color
Definition OOJSFlasher.m:66

Function Documentation

◆ FlasherGetProperty()

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

Definition at line 148 of file OOJSFlasher.m.

149{
150 if (!JSID_IS_INT(propID)) return YES;
151
152 OOJS_NATIVE_ENTER(context)
153
154 OOFlasherEntity *entity = nil;
155 id result = nil;
156
157 if (!JSFlasherGetFlasherEntity(context, this, &entity)) return NO;
158 if (entity == nil) { *value = JSVAL_VOID; return YES; }
159
160 switch (JSID_TO_INT(propID))
161 {
162 case kFlasher_active:
163 *value = OOJSValueFromBOOL([entity isActive]);
164 return YES;
165
166 case kFlasher_color:
167 result = [[entity color] normalizedArray];
168 break;
169
171 return JS_NewNumberValue(context, [entity frequency], value);
172
174 return JS_NewNumberValue(context, [entity fraction], value);
175
176 case kFlasher_phase:
177 return JS_NewNumberValue(context, [entity phase], value);
178
179 case kFlasher_size:
180 return JS_NewNumberValue(context, [entity diameter], value);
181
182 default:
184 return NO;
185 }
186
187 *value = OOJSValueFromNativeObject(context, result);
188 return YES;
189
191}
#define OOJS_NATIVE_ENTER(cx)
#define OOJS_NATIVE_EXIT
static JSPropertySpec sFlasherProperties[]
Definition OOJSFlasher.m:74
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
NSArray * normalizedArray()
Definition OOColor.m:511

References OOFlasherEntity::color, JSFlasherGetFlasherEntity(), kFlasher_active, kFlasher_color, kFlasher_fraction, kFlasher_frequency, kFlasher_phase, kFlasher_size, nil, OOColor::normalizedArray, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJSReportBadPropertySelector(), OOJSValueFromBOOL(), OOJSValueFromNativeObject(), and sFlasherProperties.

+ Here is the call graph for this function:

◆ FlasherRemove()

static JSBool FlasherRemove ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 288 of file OOJSFlasher.m.

289{
290 OOJS_NATIVE_ENTER(context)
291
292 OOFlasherEntity *thisEnt = nil;
293 GET_THIS_FLASHER(thisEnt);
294
295 Entity *parent = [thisEnt owner];
296 if ([parent isShip])
297 {
298 [(ShipEntity *)parent removeFlasher:thisEnt];
299 }
300 else
301 {
302 [(OOVisualEffectEntity *)parent removeSubEntity:thisEnt];
303 }
304
306
308}
#define GET_THIS_FLASHER(THISENT)
id owner()
Definition Entity.m:583

◆ FlasherSetProperty()

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

Definition at line 194 of file OOJSFlasher.m.

195{
196 if (!JSID_IS_INT(propID)) return YES;
197
198 OOJS_NATIVE_ENTER(context)
199
200 OOFlasherEntity *entity = nil;
201 jsdouble fValue;
202 JSBool bValue;
203 OOColor *colorForScript = nil;
204
205 if (!JSFlasherGetFlasherEntity(context, this, &entity)) return NO;
206 if (entity == nil) return YES;
207
208 switch (JSID_TO_INT(propID))
209 {
210 case kFlasher_active:
211 if (JS_ValueToBoolean(context, *value, &bValue))
212 {
213 [entity setActive:bValue];
214 return YES;
215 }
216 break;
217
218 case kFlasher_color:
219 colorForScript = [OOColor colorWithDescription:OOJSNativeObjectFromJSValue(context, *value)];
220 if (colorForScript != nil || JSVAL_IS_NULL(*value))
221 {
222 [entity setColor:colorForScript];
223 return YES;
224 }
225 break;
226
228 if (JS_ValueToNumber(context, *value, &fValue))
229 {
230 if (fValue >= 0.0)
231 {
232 [entity setFrequency:fValue];
233 return YES;
234 }
235 }
236 break;
237
239 if (JS_ValueToNumber(context, *value, &fValue))
240 {
241 if (fValue > 0.0 && fValue <= 1.0)
242 {
243 [entity setFraction:fValue];
244 return YES;
245 }
246 }
247 break;
248
249 case kFlasher_phase:
250 if (JS_ValueToNumber(context, *value, &fValue))
251 {
252 [entity setPhase:fValue];
253 return YES;
254 }
255 break;
256
257 case kFlasher_size:
258 if (JS_ValueToNumber(context, *value, &fValue))
259 {
260 if (fValue > 0.0)
261 {
262 [entity setDiameter:fValue];
263 return YES;
264 }
265 }
266 break;
267
268 default:
270 return NO;
271 }
272
273 OOJSReportBadPropertyValue(context, this, propID, sFlasherProperties, *value);
274 return NO;
275
277}
void OOJSReportBadPropertyValue(JSContext *context, JSObject *thisObj, jsid propID, JSPropertySpec *propertySpec, jsval value)
OOColor * colorWithDescription:(id description)
Definition OOColor.m:127
void setPhase:(float phase)
void setFrequency:(float frequency)
void setActive:(BOOL active)
void setFraction:(float fraction)
void setColor:(OOColor *color)
void setDiameter:(float diameter)

References OOColor::colorWithDescription:, JSFlasherGetFlasherEntity(), kFlasher_active, kFlasher_color, kFlasher_fraction, kFlasher_frequency, kFlasher_phase, kFlasher_size, nil, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJSReportBadPropertySelector(), OOJSReportBadPropertyValue(), OOFlasherEntity::setActive:, OOLightParticleEntity::setColor:, OOLightParticleEntity::setDiameter:, OOFlasherEntity::setFraction:, OOFlasherEntity::setFrequency:, OOFlasherEntity::setPhase:, and sFlasherProperties.

+ Here is the call graph for this function:

◆ InitOOJSFlasher()

void InitOOJSFlasher ( JSContext * context,
JSObject * global )

Definition at line 96 of file OOJSFlasher.m.

97{
101}
OOINLINE JSClass * JSEntityClass(void)
Definition OOJSEntity.h:42
OOINLINE JSObject * JSEntityPrototype(void)
Definition OOJSEntity.h:43
static JSObject * sFlasherPrototype
Definition OOJSFlasher.m:34
static JSFunctionSpec sFlasherMethods[]
Definition OOJSFlasher.m:87
static JSClass sFlasherClass
Definition OOJSFlasher.m:45
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(), sFlasherClass, sFlasherMethods, sFlasherProperties, and sFlasherPrototype.

+ Here is the call graph for this function:

◆ JSFlasherGetFlasherEntity()

static BOOL JSFlasherGetFlasherEntity ( JSContext * context,
JSObject * jsobj,
OOFlasherEntity ** outEntity )
static

Definition at line 104 of file OOJSFlasher.m.

105{
107
108 BOOL result;
109 Entity *entity = nil;
110
111 if (outEntity == NULL) return NO;
112 *outEntity = nil;
113
114 result = OOJSEntityGetEntity(context, jsobj, &entity);
115 if (!result) return NO;
116
117 if (![entity isKindOfClass:[OOFlasherEntity class]]) return NO;
118
119 *outEntity = (OOFlasherEntity *)entity;
120 return YES;
121
123}
#define OOJS_PROFILE_EXIT
#define OOJS_PROFILE_ENTER

References nil, OOJS_PROFILE_ENTER, and OOJS_PROFILE_EXIT.

Referenced by FlasherGetProperty(), and FlasherSetProperty().

+ Here is the caller graph for this function:

Variable Documentation

◆ sFlasherClass

JSClass sFlasherClass
static
Initial value:
=
{
"Flasher",
JSCLASS_HAS_PRIVATE,
JS_PropertyStub,
JS_PropertyStub,
JS_EnumerateStub,
JS_ResolveStub,
JS_ConvertStub,
JSCLASS_NO_OPTIONAL_MEMBERS
}
static JSBool FlasherGetProperty(JSContext *context, JSObject *this, jsid propID, jsval *value)
static JSBool FlasherSetProperty(JSContext *context, JSObject *this, jsid propID, JSBool strict, jsval *value)
void OOJSObjectWrapperFinalize(JSContext *context, JSObject *this)

Definition at line 45 of file OOJSFlasher.m.

46{
47 "Flasher",
48 JSCLASS_HAS_PRIVATE,
49
50 JS_PropertyStub, // addProperty
51 JS_PropertyStub, // delProperty
52 FlasherGetProperty, // getProperty
53 FlasherSetProperty, // setProperty
54 JS_EnumerateStub, // enumerate
55 JS_ResolveStub, // resolve
56 JS_ConvertStub, // convert
58 JSCLASS_NO_OPTIONAL_MEMBERS
59};

Referenced by InitOOJSFlasher().

◆ sFlasherMethods

JSFunctionSpec sFlasherMethods[]
static
Initial value:
=
{
{ "remove", FlasherRemove, 0 },
{ 0 }
}
static JSBool FlasherRemove(JSContext *context, uintN argc, jsval *vp)

Definition at line 87 of file OOJSFlasher.m.

88{
89 // JS name Function min args
90 { "remove", FlasherRemove, 0 },
91
92 { 0 }
93};

Referenced by InitOOJSFlasher().

◆ sFlasherProperties

JSPropertySpec sFlasherProperties[]
static
Initial value:

Definition at line 74 of file OOJSFlasher.m.

75{
76 // JS name ID flags
83 { 0 }
84};

Referenced by FlasherGetProperty(), FlasherSetProperty(), and InitOOJSFlasher().

◆ sFlasherPrototype

JSObject* sFlasherPrototype
static

Definition at line 34 of file OOJSFlasher.m.

Referenced by InitOOJSFlasher().