Oolite
Loading...
Searching...
No Matches
OOJSExhaustPlume.m
Go to the documentation of this file.
1/*
2OOJSExhaustPlume.m (QuickJS-ng)
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
24#import "OOJSExhaustPlume.h"
27#import "OOJSEntity.h"
28#import "OOJSVector.h"
30#import "ShipEntity.h"
31
32static JSClassID sExhaustPlumeClassID;
33
34static BOOL JSExhaustPlumeGetExhaustPlumeEntity(JSContext* context, JSValueConst jsobj, OOExhaustPlumeEntity** outEntity);
35
38
40
41static JSClassDef sExhaustPlumeClass = {
42 .class_name = "ExhaustPlume",
43 .finalizer = OOJSObjectWrapperFinalize,
44};
45
46enum {
47 // Property IDs
49};
50
51static const JSCFunctionListEntry sExhaustPlumeProperties[] = {
52 // JS name, getter, setter, ID
54};
55
56static const JSCFunctionListEntry sExhaustPlumeMethods[] = {
57 // JS name, min args, function
58 JS_CFUNC_DEF("remove", 0, ExhaustPlumeRemove),
59};
60
61void InitOOJSExhaustPlume(JSContext* context, JSValueConst global)
62{
64
65 JSValue parentPrototype = JS_GetClassProto(context, JSEntityClassID());
66 NSCAssert(JS_IsObject(parentPrototype), @"Entity must be initialized before ExhaustPlume.");
67 OOJSInitClass(context, global, sExhaustPlumeClassID, parentPrototype, OOJSUnconstructableConstruct, 0,
69 JS_FreeValue(context, parentPrototype);
70
73}
74
75JSClassID JSExhaustPlumeClassID(void)
76{
78}
79
80static BOOL JSExhaustPlumeGetExhaustPlumeEntity(JSContext* context, JSValueConst jsobj, OOExhaustPlumeEntity** outEntity)
81{
83
84 BOOL result;
85 Entity* entity = nil;
86
87 if (outEntity == NULL)
88 return NO;
89 *outEntity = nil;
90
91 result = OOJSEntityGetEntity(context, jsobj, &entity);
92 if (!result)
93 return NO;
94
95 if (![entity isKindOfClass:[OOExhaustPlumeEntity class]])
96 return NO;
97
98 *outEntity = (OOExhaustPlumeEntity*)entity;
99 return YES;
100
102}
103
104@implementation OOExhaustPlumeEntity (OOJavaScriptExtensions)
105
106- (JSClassID)oo_jsClassID
107{
109}
110
111- (NSString*)oo_jsClassName
112{
113 return @"ExhaustPlume";
114}
115
117{
118 return YES;
119}
120
121@end
122
124{
125 OOJS_NATIVE_ENTER(context)
126
127 OOExhaustPlumeEntity* entity = nil;
128 id result = nil;
129
130 if (!JSExhaustPlumeGetExhaustPlumeEntity(context, this, &entity))
131 return OOJSNativeFailure(context);
132 if (entity == nil) {
133 return JS_UNDEFINED;
134 }
135
136 switch (magic) {
138 OOJS_RETURN_VECTOR([entity scale]);
139
140 default:
142 return OOJSNativeFailure(context);
143 }
144
145 return OOJSValueFromNativeObject(context, result);
146
148}
149
151{
152 OOJS_NATIVE_ENTER(context)
153
154 OOExhaustPlumeEntity* entity = nil;
155 Vector vValue;
156
157 if (!JSExhaustPlumeGetExhaustPlumeEntity(context, this, &entity))
158 return OOJSNativeFailure(context);
159 if (entity == nil)
160 return JS_UNDEFINED;
161
162 switch (magic) {
164 if (JSValueToVector(context, value, &vValue)) {
165 [entity setScale:vValue];
166 return JS_UNDEFINED;
167 }
168 break;
169
170 default:
172 return OOJSNativeFailure(context);
173 }
174
176 return OOJSNativeFailure(context);
177
179}
180
181// *** Methods ***
182
183#define GET_THIS_EXHAUSTPLUME(THISENT) \
184 do { \
185 if (EXPECT_NOT(!JSExhaustPlumeGetExhaustPlumeEntity(context, OOJS_THIS, &THISENT))) \
186 return OOJSNativeFailure(context); /* Exception */ \
187 if (OOIsStaleEntity(THISENT)) \
188 OOJS_RETURN_VOID; \
189 } while (0)
190
192{
193 OOJS_NATIVE_ENTER(context)
194
195 OOExhaustPlumeEntity* thisEnt = nil;
196 GET_THIS_EXHAUSTPLUME(thisEnt);
197
198 ShipEntity* parent = [thisEnt owner];
199 [parent removeExhaust:thisEnt];
200
202
204}
#define OOJS_PROFILE_EXIT
#define OOJS_NATIVE_ENTER(cx)
#define OOJS_NATIVE_EXIT
#define OOJS_PROFILE_ENTER
@ kExhaustPlume_size
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)
static JSClass sExhaustPlumeClass
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:341
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
#define OOJS_RETURN_VECTOR(value)
return nil
JSClassID JSEntityClassID(void)
Definition OOJSEntity.m:115
static JSClassID sExhaustPlumeClassID
JSClassID JSExhaustPlumeClassID(void)
#define OOJS_PROPERTY_RW(name, getter, setter, magic)
JSValue OOJSNativeFailure(JSContext *context)
JSClassID OOJSRegisterClass(JSClassID *ioClassID, const JSClassDef *classDef)
Definition OOJSClasses.m:61
#define OOJS_SETTER_ARGS
JSValueConst OOJSInitClass(JSContext *context, JSValueConst global, JSClassID classID, JSValueConst parentPrototype, JSCFunction *constructor, int constructorArgCount, const JSCFunctionListEntry *properties, size_t propertyCount, const JSCFunctionListEntry *methods, size_t methodCount, const JSCFunctionListEntry *staticMethods, size_t staticMethodCount)
#define OOJS_GETTER_ARGS
#define OOJS_NATIVE_ARGS
#define OOJS_COUNT(array)
id owner()
Definition Entity.m:548
void setScale:(Vector scale)
void removeExhaust:(OOExhaustPlumeEntity *exhaust)