Oolite
Loading...
Searching...
No Matches
OOJSDock.m File Reference
import "OOJSDock.h"
import "OOJSEntity.h"
import "OOJSPlayer.h"
import "OOJSShip.h"
import "OOJavaScriptEngine.h"
import "GameController.h"
Include dependency graph for OOJSDock.m:

Go to the source code of this file.

Enumerations

enum  {
  kDock_allowsDocking , kDock_disallowedDockingCollides , kDock_allowsLaunching , kDock_dockingQueueLength ,
  kDock_launchingQueueLength
}

Functions

static BOOL JSDockGetDockEntity (JSContext *context, JSObject *stationObj, DockEntity **outEntity)
static BOOL JSDockGetShipEntity (JSContext *context, JSObject *shipObj, ShipEntity **outEntity)
static JSBool DockIsQueued (JSContext *context, uintN argc, jsval *vp)
static JSBool DockGetProperty (JSContext *context, JSObject *this, jsid propID, jsval *value)
static JSBool DockSetProperty (JSContext *context, JSObject *this, jsid propID, JSBool strict, jsval *value)
void InitOOJSDock (JSContext *context, JSObject *global)

Variables

static JSObject * sDockPrototype
static JSClass sDockClass
static JSPropertySpec sDockProperties []
static JSFunctionSpec sDockMethods []

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
kDock_allowsDocking 
kDock_disallowedDockingCollides 
kDock_allowsLaunching 
kDock_dockingQueueLength 
kDock_launchingQueueLength 

Definition at line 57 of file OOJSDock.m.

57 {
58 // Property IDs
64};
@ kDock_allowsDocking
Definition OOJSDock.m:59
@ kDock_disallowedDockingCollides
Definition OOJSDock.m:60
@ kDock_launchingQueueLength
Definition OOJSDock.m:63
@ kDock_allowsLaunching
Definition OOJSDock.m:61
@ kDock_dockingQueueLength
Definition OOJSDock.m:62

Function Documentation

◆ DockGetProperty()

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

Definition at line 152 of file OOJSDock.m.

153{
154 if (!JSID_IS_INT(propID))
155 return YES;
156
157 OOJS_NATIVE_ENTER(context)
158
159 DockEntity* entity = nil;
160
161 if (!JSDockGetDockEntity(context, this, &entity))
162 return NO;
163 if (entity == nil) {
164 *value = JSVAL_VOID;
165 return YES;
166 }
167
168 switch (JSID_TO_INT(propID)) {
170 *value = OOJSValueFromBOOL([entity allowsDocking]);
171 return YES;
172
174 *value = OOJSValueFromBOOL([entity disallowedDockingCollides]);
175 return YES;
176
178 *value = OOJSValueFromBOOL([entity allowsLaunching]);
179 return YES;
180
182 return JS_NewNumberValue(context, [entity countOfShipsInDockingQueue], value);
183
185 return JS_NewNumberValue(context, [entity countOfShipsInLaunchQueue], value);
186
187 default:
188 OOJSReportBadPropertySelector(context, this, propID, sDockProperties);
189 return NO;
190 }
191
193}
static BOOL JSDockGetDockEntity(JSContext *context, JSObject *stationObj, DockEntity **outEntity)
Definition OOJSDock.m:89
static JSPropertySpec sDockProperties[]
Definition OOJSDock.m:66
#define OOJS_NATIVE_ENTER(cx)
#define OOJS_NATIVE_EXIT
void OOJSReportBadPropertySelector(JSContext *context, JSObject *thisObj, jsid propID, JSPropertySpec *propertySpec)
OOINLINE jsval OOJSValueFromBOOL(int b) INLINE_CONST_FUNC
return nil

References JSDockGetDockEntity(), kDock_allowsDocking, kDock_allowsLaunching, kDock_disallowedDockingCollides, kDock_dockingQueueLength, kDock_launchingQueueLength, nil, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJSReportBadPropertySelector(), OOJSValueFromBOOL(), and sDockProperties.

Here is the call graph for this function:

◆ DockIsQueued()

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

Definition at line 246 of file OOJSDock.m.

247{
248 OOJS_NATIVE_ENTER(context)
249
250 BOOL result = NO;
251 DockEntity* dock = nil;
252
253 JSDockGetDockEntity(context, OOJS_THIS, &dock);
254 if (argc == 0) {
255 OOJSReportBadArguments(context, @"Dock", @"isQueued", MIN(argc, 1U), OOJS_ARGV, nil, @"ship");
256 return NO;
257 }
258 ShipEntity* ship = nil;
259 JSDockGetShipEntity(context, JSVAL_TO_OBJECT(OOJS_ARGV[0]), &ship);
260 if (ship != nil) {
261 result = [dock shipIsInDockingQueue:ship];
262 }
263
264 OOJS_RETURN_BOOL(result);
265
267}
static BOOL JSDockGetShipEntity(JSContext *context, JSObject *shipObj, ShipEntity **outEntity)
Definition OOJSDock.m:113
#define OOJS_THIS
#define OOJS_RETURN_BOOL(v)
#define OOJS_ARGV
void OOJSReportBadArguments(JSContext *context, NSString *scriptClass, NSString *function, uintN argc, jsval *argv, NSString *message, NSString *expectedArgsDescription)
#define MIN(A, B)
Definition OOMaths.h:91
BOOL shipIsInDockingQueue:(ShipEntity *ship)
Definition DockEntity.m:574

References JSDockGetDockEntity(), JSDockGetShipEntity(), MIN, nil, OOJS_ARGV, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_BOOL, OOJS_THIS, OOJSReportBadArguments(), and DockEntity::shipIsInDockingQueue:.

Here is the call graph for this function:

◆ DockSetProperty()

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

Definition at line 195 of file OOJSDock.m.

196{
197 if (!JSID_IS_INT(propID))
198 return YES;
199
200 OOJS_NATIVE_ENTER(context)
201
202 DockEntity* entity = nil;
203 JSBool bValue;
204 // int32 iValue;
205
206 if (!JSDockGetDockEntity(context, this, &entity))
207 return NO;
208 if (entity == nil)
209 return YES;
210
211 switch (JSID_TO_INT(propID)) {
213 if (JS_ValueToBoolean(context, *value, &bValue)) {
214 [entity setAllowsDocking:bValue];
215 return YES;
216 }
217 break;
218
220 if (JS_ValueToBoolean(context, *value, &bValue)) {
221 [entity setAllowsLaunching:bValue];
222 return YES;
223 }
224 break;
225
227 if (JS_ValueToBoolean(context, *value, &bValue)) {
228 [entity setDisallowedDockingCollides:bValue];
229 return YES;
230 }
231 break;
232
233 default:
234 OOJSReportBadPropertySelector(context, this, propID, sDockProperties);
235 return NO;
236 }
237
238 OOJSReportBadPropertyValue(context, this, propID, sDockProperties, *value);
239 return NO;
240
242}
void OOJSReportBadPropertyValue(JSContext *context, JSObject *thisObj, jsid propID, JSPropertySpec *propertySpec, jsval value)
void setAllowsDocking:(BOOL allow)
Definition DockEntity.m:158
void setDisallowedDockingCollides:(BOOL ddc)
Definition DockEntity.m:184
void setAllowsLaunching:(BOOL allow)
Definition DockEntity.m:176

References JSDockGetDockEntity(), kDock_allowsDocking, kDock_allowsLaunching, kDock_disallowedDockingCollides, nil, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJSReportBadPropertySelector(), OOJSReportBadPropertyValue(), sDockProperties, DockEntity::setAllowsDocking:, DockEntity::setAllowsLaunching:, and DockEntity::setDisallowedDockingCollides:.

Here is the call graph for this function:

◆ InitOOJSDock()

void InitOOJSDock ( JSContext * context,
JSObject * global )

Definition at line 82 of file OOJSDock.m.

83{
84 sDockPrototype = JS_InitClass(context, global, JSShipPrototype(), &sDockClass, OOJSUnconstructableConstruct, 0, sDockProperties, sDockMethods, NULL, NULL);
87}
static JSClass sDockClass
Definition OOJSDock.m:42
static JSObject * sDockPrototype
Definition OOJSDock.m:32
static JSFunctionSpec sDockMethods[]
Definition OOJSDock.m:76
JSObject * JSShipPrototype(void)
Definition OOJSShip.m:587
JSClass * JSShipClass(void)
Definition OOJSShip.m:582
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 JSShipClass(), JSShipPrototype(), OOJSBasicPrivateObjectConverter(), OOJSRegisterObjectConverter(), OOJSRegisterSubclass(), OOJSUnconstructableConstruct(), sDockClass, sDockMethods, sDockProperties, and sDockPrototype.

Referenced by OOJavaScriptEngine(Private)::createMainThreadContext.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ JSDockGetDockEntity()

BOOL JSDockGetDockEntity ( JSContext * context,
JSObject * stationObj,
DockEntity ** outEntity )
static

Definition at line 89 of file OOJSDock.m.

90{
92
93 BOOL result;
94 Entity* entity = nil;
95
96 if (outEntity == NULL)
97 return NO;
98 *outEntity = nil;
99
100 result = OOJSEntityGetEntity(context, dockObj, &entity);
101 if (!result)
102 return NO;
103
104 if (![entity isKindOfClass:[DockEntity class]])
105 return NO;
106
107 *outEntity = (DockEntity*)entity;
108 return YES;
109
111}
#define OOJS_PROFILE_EXIT
#define OOJS_PROFILE_ENTER

References nil, OOJS_PROFILE_ENTER, and OOJS_PROFILE_EXIT.

Referenced by DockGetProperty(), DockGetProperty(), DockIsQueued(), DockIsQueued(), DockSetProperty(), and DockSetProperty().

Here is the caller graph for this function:

◆ JSDockGetShipEntity()

BOOL JSDockGetShipEntity ( JSContext * context,
JSObject * shipObj,
ShipEntity ** outEntity )
static

Definition at line 113 of file OOJSDock.m.

114{
116
117 BOOL result;
118 Entity* entity = nil;
119
120 if (outEntity == NULL)
121 return NO;
122 *outEntity = nil;
123
124 result = OOJSEntityGetEntity(context, shipObj, &entity);
125 if (!result)
126 return NO;
127
128 if (![entity isKindOfClass:[ShipEntity class]])
129 return NO;
130
131 *outEntity = (ShipEntity*)entity;
132 return YES;
133
135}

References nil, OOJS_PROFILE_ENTER, and OOJS_PROFILE_EXIT.

Referenced by DockIsQueued(), and DockIsQueued().

Here is the caller graph for this function:

Variable Documentation

◆ sDockClass

JSClass sDockClass
static
Initial value:
= {
"Dock",
JSCLASS_HAS_PRIVATE,
JS_PropertyStub,
JS_PropertyStub,
JS_EnumerateStub,
JS_ResolveStub,
JS_ConvertStub,
JSCLASS_NO_OPTIONAL_MEMBERS
}
static JSBool DockSetProperty(JSContext *context, JSObject *this, jsid propID, JSBool strict, jsval *value)
Definition OOJSDock.m:195
static JSBool DockGetProperty(JSContext *context, JSObject *this, jsid propID, jsval *value)
Definition OOJSDock.m:152
void OOJSObjectWrapperFinalize(JSContext *context, JSObject *this)

Definition at line 42 of file OOJSDock.m.

42 {
43 "Dock",
44 JSCLASS_HAS_PRIVATE,
45
46 JS_PropertyStub, // addProperty
47 JS_PropertyStub, // delProperty
48 DockGetProperty, // getProperty
49 DockSetProperty, // setProperty
50 JS_EnumerateStub, // enumerate
51 JS_ResolveStub, // resolve
52 JS_ConvertStub, // convert
53 OOJSObjectWrapperFinalize, // finalize
54 JSCLASS_NO_OPTIONAL_MEMBERS
55};

Referenced by DockEntity(OOJavaScriptExtensions)::getJSClass:andPrototype:, InitOOJSDock(), and InitOOJSDock().

◆ sDockMethods

JSFunctionSpec sDockMethods[]
static
Initial value:
= {
{ "isQueued", DockIsQueued, 1 },
{ 0 }
}
static JSBool DockIsQueued(JSContext *context, uintN argc, jsval *vp)
Definition OOJSDock.m:246

Definition at line 76 of file OOJSDock.m.

76 {
77 // JS name Function min args
78 { "isQueued", DockIsQueued, 1 },
79 { 0 }
80};

Referenced by InitOOJSDock(), and InitOOJSDock().

◆ sDockProperties

JSPropertySpec sDockProperties[]
static
Initial value:
= {
{ "disallowedDockingCollides", kDock_disallowedDockingCollides, OOJS_PROP_READWRITE_CB },
{ "dockingQueueLength", kDock_dockingQueueLength, OOJS_PROP_READONLY_CB },
{ "launchingQueueLength", kDock_launchingQueueLength, OOJS_PROP_READONLY_CB },
{ 0 }
}
#define OOJS_PROP_READWRITE_CB
#define OOJS_PROP_READONLY_CB

Definition at line 66 of file OOJSDock.m.

66 {
67 // JS name ID flags
68 { "allowsDocking", kDock_allowsDocking, OOJS_PROP_READWRITE_CB },
69 { "disallowedDockingCollides", kDock_disallowedDockingCollides, OOJS_PROP_READWRITE_CB },
70 { "allowsLaunching", kDock_allowsLaunching, OOJS_PROP_READWRITE_CB },
71 { "dockingQueueLength", kDock_dockingQueueLength, OOJS_PROP_READONLY_CB },
72 { "launchingQueueLength", kDock_launchingQueueLength, OOJS_PROP_READONLY_CB },
73 { 0 }
74};

Referenced by DockGetProperty(), DockGetProperty(), DockSetProperty(), DockSetProperty(), InitOOJSDock(), and InitOOJSDock().

◆ sDockPrototype

JSObject* sDockPrototype
static