Oolite 1.91.0.7646-241128-10e222e
Loading...
Searching...
No Matches
OOJSDock.m File Reference
import "OOJSDock.h"
import "OOJSEntity.h"
import "OOJSShip.h"
import "OOJSPlayer.h"
import "OOJavaScriptEngine.h"
import "DockEntity.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 63 of file OOJSDock.m.

64{
65 // Property IDs
71};
@ kDock_allowsDocking
Definition OOJSDock.m:66
@ kDock_disallowedDockingCollides
Definition OOJSDock.m:67
@ kDock_launchingQueueLength
Definition OOJSDock.m:70
@ kDock_allowsLaunching
Definition OOJSDock.m:68
@ kDock_dockingQueueLength
Definition OOJSDock.m:69

Function Documentation

◆ DockGetProperty()

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

Definition at line 163 of file OOJSDock.m.

164{
165 if (!JSID_IS_INT(propID)) return YES;
166
167 OOJS_NATIVE_ENTER(context)
168
169 DockEntity *entity = nil;
170
171 if (!JSDockGetDockEntity(context, this, &entity)) return NO;
172 if (entity == nil) { *value = JSVAL_VOID; return YES; }
173
174 switch (JSID_TO_INT(propID))
175 {
177 *value = OOJSValueFromBOOL([entity allowsDocking]);
178 return YES;
179
181 *value = OOJSValueFromBOOL([entity disallowedDockingCollides]);
182 return YES;
183
185 *value = OOJSValueFromBOOL([entity allowsLaunching]);
186 return YES;
187
189 return JS_NewNumberValue(context, [entity countOfShipsInDockingQueue], value);
190
192 return JS_NewNumberValue(context, [entity countOfShipsInLaunchQueue], value);
193
194 default:
195 OOJSReportBadPropertySelector(context, this, propID, sDockProperties);
196 return NO;
197 }
198
200}
static BOOL JSDockGetDockEntity(JSContext *context, JSObject *stationObj, DockEntity **outEntity)
Definition OOJSDock.m:102
static JSPropertySpec sDockProperties[]
Definition OOJSDock.m:74
#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()

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

Definition at line 256 of file OOJSDock.m.

257{
258 OOJS_NATIVE_ENTER(context)
259
260 BOOL result = NO;
261 DockEntity *dock = nil;
262
263 JSDockGetDockEntity(context, OOJS_THIS, &dock);
264 if (argc == 0)
265 {
266 OOJSReportBadArguments(context, @"Dock", @"isQueued", MIN(argc, 1U), OOJS_ARGV, nil, @"ship");
267 return NO;
268 }
269 ShipEntity *ship = nil;
270 JSDockGetShipEntity(context, JSVAL_TO_OBJECT(OOJS_ARGV[0]), &ship);
271 if (ship != nil)
272 {
273 result = [dock shipIsInDockingQueue:ship];
274 }
275
276 OOJS_RETURN_BOOL(result);
277
279}
static BOOL JSDockGetShipEntity(JSContext *context, JSObject *shipObj, ShipEntity **outEntity)
Definition OOJSDock.m:124
#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:111
BOOL shipIsInDockingQueue:(ShipEntity *ship)
Definition DockEntity.m:639

◆ DockSetProperty()

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

Definition at line 203 of file OOJSDock.m.

204{
205 if (!JSID_IS_INT(propID)) return YES;
206
207 OOJS_NATIVE_ENTER(context)
208
209 DockEntity *entity = nil;
210 JSBool bValue;
211// int32 iValue;
212
213 if (!JSDockGetDockEntity(context, this, &entity)) return NO;
214 if (entity == nil) return YES;
215
216 switch (JSID_TO_INT(propID))
217 {
219 if (JS_ValueToBoolean(context, *value, &bValue))
220 {
221 [entity setAllowsDocking:bValue];
222 return YES;
223 }
224 break;
225
227 if (JS_ValueToBoolean(context, *value, &bValue))
228 {
229 [entity setAllowsLaunching:bValue];
230 return YES;
231 }
232 break;
233
235 if (JS_ValueToBoolean(context, *value, &bValue))
236 {
237 [entity setDisallowedDockingCollides:bValue];
238 return YES;
239 }
240 break;
241
242 default:
243 OOJSReportBadPropertySelector(context, this, propID, sDockProperties);
244 return NO;
245 }
246
247 OOJSReportBadPropertyValue(context, this, propID, sDockProperties, *value);
248 return NO;
249
251}
void OOJSReportBadPropertyValue(JSContext *context, JSObject *thisObj, jsid propID, JSPropertySpec *propertySpec, jsval value)
void setAllowsDocking:(BOOL allow)
Definition DockEntity.m:178
void setDisallowedDockingCollides:(BOOL ddc)
Definition DockEntity.m:210
void setAllowsLaunching:(BOOL allow)
Definition DockEntity.m:200

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 94 of file OOJSDock.m.

95{
96 sDockPrototype = JS_InitClass(context, global, JSShipPrototype(), &sDockClass, OOJSUnconstructableConstruct, 0, sDockProperties, sDockMethods, NULL, NULL);
99}
static JSClass sDockClass
Definition OOJSDock.m:46
static JSObject * sDockPrototype
Definition OOJSDock.m:34
static JSFunctionSpec sDockMethods[]
Definition OOJSDock.m:86
JSObject * JSShipPrototype(void)
Definition OOJSShip.m:601
JSClass * JSShipClass(void)
Definition OOJSShip.m:595
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.

+ Here is the call graph for this function:

◆ JSDockGetDockEntity()

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

Definition at line 102 of file OOJSDock.m.

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

References nil, OOJS_PROFILE_ENTER, and OOJS_PROFILE_EXIT.

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

+ Here is the caller graph for this function:

◆ JSDockGetShipEntity()

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

Definition at line 124 of file OOJSDock.m.

125{
127
128 BOOL result;
129 Entity *entity = nil;
130
131 if (outEntity == NULL) return NO;
132 *outEntity = nil;
133
134 result = OOJSEntityGetEntity(context, shipObj, &entity);
135 if (!result) return NO;
136
137 if (![entity isKindOfClass:[ShipEntity class]]) return NO;
138
139 *outEntity = (ShipEntity *)entity;
140 return YES;
141
143}

References nil, OOJS_PROFILE_ENTER, and OOJS_PROFILE_EXIT.

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

+ 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:203
static JSBool DockGetProperty(JSContext *context, JSObject *this, jsid propID, jsval *value)
Definition OOJSDock.m:163
void OOJSObjectWrapperFinalize(JSContext *context, JSObject *this)

Definition at line 46 of file OOJSDock.m.

47{
48 "Dock",
49 JSCLASS_HAS_PRIVATE,
50
51 JS_PropertyStub, // addProperty
52 JS_PropertyStub, // delProperty
53 DockGetProperty, // getProperty
54 DockSetProperty, // setProperty
55 JS_EnumerateStub, // enumerate
56 JS_ResolveStub, // resolve
57 JS_ConvertStub, // convert
59 JSCLASS_NO_OPTIONAL_MEMBERS
60};

Referenced by InitOOJSDock().

◆ sDockMethods

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

Definition at line 86 of file OOJSDock.m.

87{
88 // JS name Function min args
89 { "isQueued", DockIsQueued, 1 },
90 { 0 }
91};

Referenced by 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 74 of file OOJSDock.m.

75{
76 // JS name ID flags
77 { "allowsDocking", kDock_allowsDocking, OOJS_PROP_READWRITE_CB },
78 { "disallowedDockingCollides", kDock_disallowedDockingCollides, OOJS_PROP_READWRITE_CB },
79 { "allowsLaunching", kDock_allowsLaunching, OOJS_PROP_READWRITE_CB },
80 { "dockingQueueLength", kDock_dockingQueueLength, OOJS_PROP_READONLY_CB },
81 { "launchingQueueLength", kDock_launchingQueueLength, OOJS_PROP_READONLY_CB },
82 { 0 }
83};

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

◆ sDockPrototype

JSObject* sDockPrototype
static

Definition at line 34 of file OOJSDock.m.

Referenced by InitOOJSDock().