Oolite 1.91.0.7645-241119-222d325
Loading...
Searching...
No Matches
OOJSExhaustPlume.m
Go to the documentation of this file.
1/*
2OOJSExhaustPlume.m
3
4Oolite
5Copyright (C) 2004-2013 Giles C Williams and contributors
6
7This program is free software; you can redistribute it and/or
8modify it under the terms of the GNU General Public License
9as published by the Free Software Foundation; either version 2
10of the License, or (at your option) any later version.
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with this program; if not, write to the Free Software
19Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20MA 02110-1301, USA.
21
22 */
23
25#import "OOJSExhaustPlume.h"
26#import "OOJSEntity.h"
27#import "OOJSVector.h"
30#import "ShipEntity.h"
31
32
33static JSObject *sExhaustPlumePrototype;
34
35static BOOL JSExhaustPlumeGetExhaustPlumeEntity(JSContext *context, JSObject *jsobj, OOExhaustPlumeEntity **outEntity);
36
37
38static JSBool ExhaustPlumeGetProperty(JSContext *context, JSObject *this, jsid propID, jsval *value);
39static JSBool ExhaustPlumeSetProperty(JSContext *context, JSObject *this, jsid propID, JSBool strict, jsval *value);
40
41static JSBool ExhaustPlumeRemove(JSContext *context, uintN argc, jsval *vp);
42
43
44static JSClass sExhaustPlumeClass =
45{
46 "ExhaustPlume",
47 JSCLASS_HAS_PRIVATE,
48
49 JS_PropertyStub, // addProperty
50 JS_PropertyStub, // delProperty
51 ExhaustPlumeGetProperty, // getProperty
52 ExhaustPlumeSetProperty, // setProperty
53 JS_EnumerateStub, // enumerate
54 JS_ResolveStub, // resolve
55 JS_ConvertStub, // convert
57 JSCLASS_NO_OPTIONAL_MEMBERS
58};
59
60
61enum
62{
63 // Property IDs
65};
66
67
68static JSPropertySpec sExhaustPlumeProperties[] =
69{
70 // JS name ID flags
72 { 0 }
73};
74
75
76static JSFunctionSpec sExhaustPlumeMethods[] =
77{
78 // JS name Function min args
79 { "remove", ExhaustPlumeRemove, 0 },
80
81 { 0 }
82};
83
84
91
92
93static BOOL JSExhaustPlumeGetExhaustPlumeEntity(JSContext *context, JSObject *jsobj, OOExhaustPlumeEntity **outEntity)
94{
96
97 BOOL result;
98 Entity *entity = nil;
99
100 if (outEntity == NULL) return NO;
101 *outEntity = nil;
102
103 result = OOJSEntityGetEntity(context, jsobj, &entity);
104 if (!result) return NO;
105
106 if (![entity isKindOfClass:[OOExhaustPlumeEntity class]]) return NO;
107
108 *outEntity = (OOExhaustPlumeEntity *)entity;
109 return YES;
110
112}
113
114
115@implementation OOExhaustPlumeEntity (OOJavaScriptExtensions)
116
117- (void)getJSClass:(JSClass **)outClass andPrototype:(JSObject **)outPrototype
118{
119 *outClass = &sExhaustPlumeClass;
120 *outPrototype = sExhaustPlumePrototype;
121}
122
123
124- (NSString *) oo_jsClassName
125{
126 return @"ExhaustPlume";
127}
128
129- (BOOL) isVisibleToScripts
130{
131 return YES;
132}
133
134@end
135
136
137static JSBool ExhaustPlumeGetProperty(JSContext *context, JSObject *this, jsid propID, jsval *value)
138{
139 if (!JSID_IS_INT(propID)) return YES;
140
141 OOJS_NATIVE_ENTER(context)
142
143 OOExhaustPlumeEntity *entity = nil;
144 id result = nil;
145
146 if (!JSExhaustPlumeGetExhaustPlumeEntity(context, this, &entity)) return NO;
147 if (entity == nil) { *value = JSVAL_VOID; return YES; }
148
149 switch (JSID_TO_INT(propID))
150 {
152 return VectorToJSValue(context, [entity scale], value);
153
154 default:
156 return NO;
157 }
158
159 *value = OOJSValueFromNativeObject(context, result);
160 return YES;
161
163}
164
165
166static JSBool ExhaustPlumeSetProperty(JSContext *context, JSObject *this, jsid propID, JSBool strict, jsval *value)
167{
168 if (!JSID_IS_INT(propID)) return YES;
169
170 OOJS_NATIVE_ENTER(context)
171
172 OOExhaustPlumeEntity *entity = nil;
173 Vector vValue;
174
175 if (!JSExhaustPlumeGetExhaustPlumeEntity(context, this, &entity)) return NO;
176 if (entity == nil) return YES;
177
178 switch (JSID_TO_INT(propID))
179 {
181 if (JSValueToVector(context, *value, &vValue))
182 {
183 [entity setScale:vValue];
184 return YES;
185 }
186 break;
187
188 default:
190 return NO;
191 }
192
193 OOJSReportBadPropertyValue(context, this, propID, sExhaustPlumeProperties, *value);
194 return NO;
195
197}
198
199
200// *** Methods ***
201
202#define GET_THIS_EXHAUSTPLUME(THISENT) do { \
203 if (EXPECT_NOT(!JSExhaustPlumeGetExhaustPlumeEntity(context, OOJS_THIS, &THISENT))) return NO; /* Exception */ \
204 if (OOIsStaleEntity(THISENT)) OOJS_RETURN_VOID; \
205} while (0)
206
207
208static JSBool ExhaustPlumeRemove(JSContext *context, uintN argc, jsval *vp)
209{
210 OOJS_NATIVE_ENTER(context)
211
212 OOExhaustPlumeEntity *thisEnt = nil;
213 GET_THIS_EXHAUSTPLUME(thisEnt);
214
215 ShipEntity *parent = [thisEnt owner];
216 [parent removeExhaust:thisEnt];
217
219
221}
222
223
#define OOJS_PROFILE_EXIT
#define OOJS_NATIVE_ENTER(cx)
#define OOJS_NATIVE_EXIT
#define OOJS_PROFILE_ENTER
OOINLINE JSClass * JSEntityClass(void)
Definition OOJSEntity.h:42
OOINLINE JSObject * JSEntityPrototype(void)
Definition OOJSEntity.h:43
static JSBool ExhaustPlumeGetProperty(JSContext *context, JSObject *this, jsid propID, jsval *value)
#define GET_THIS_EXHAUSTPLUME(THISENT)
void InitOOJSExhaustPlume(JSContext *context, JSObject *global)
static JSPropertySpec sExhaustPlumeProperties[]
static BOOL JSExhaustPlumeGetExhaustPlumeEntity(JSContext *context, JSObject *jsobj, OOExhaustPlumeEntity **outEntity)
static JSBool ExhaustPlumeRemove(JSContext *context, uintN argc, jsval *vp)
@ kExhaustPlume_size
static JSClass sExhaustPlumeClass
static JSObject * sExhaustPlumePrototype
static JSBool ExhaustPlumeSetProperty(JSContext *context, JSObject *this, jsid propID, JSBool strict, jsval *value)
static JSFunctionSpec sExhaustPlumeMethods[]
BOOL JSValueToVector(JSContext *context, jsval value, Vector *outVector) NONNULL_FUNC
Definition OOJSVector.m:259
BOOL VectorToJSValue(JSContext *context, Vector vector, jsval *outValue) NONNULL_FUNC
Definition OOJSVector.m:185
#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 OOJSRegisterSubclass(JSClass *subclass, JSClass *superclass)
void OOJSReportBadPropertyValue(JSContext *context, JSObject *thisObj, jsid propID, JSPropertySpec *propertySpec, jsval value)
id OOJSBasicPrivateObjectConverter(JSContext *context, JSObject *object)
#define OOJS_RETURN_VOID
return nil
id owner()
Definition Entity.m:583
void setScale:(Vector scale)
void removeExhaust:(OOExhaustPlumeEntity *exhaust)