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

Go to the source code of this file.

Classes

class  OOManifest
 

Enumerations

enum  { kManifest_list }
 

Functions

static JSBool ManifestComment (JSContext *context, uintN argc, jsval *vp)
 
static JSBool ManifestSetComment (JSContext *context, uintN argc, jsval *vp)
 
static JSBool ManifestShortComment (JSContext *context, uintN argc, jsval *vp)
 
static JSBool ManifestSetShortComment (JSContext *context, uintN argc, jsval *vp)
 
static JSBool ManifestDeleteProperty (JSContext *context, JSObject *this, jsid propID, jsval *value)
 
static JSBool ManifestGetProperty (JSContext *context, JSObject *this, jsid propID, jsval *value)
 
static JSBool ManifestSetProperty (JSContext *context, JSObject *this, jsid propID, JSBool strict, jsval *value)
 
void InitOOJSManifest (JSContext *context, JSObject *global)
 

Variables

static JSObject * sManifestPrototype
 
static JSObject * sManifestObject
 
static JSClass sManifestClass
 
static JSPropertySpec sManifestProperties []
 
static JSFunctionSpec sManifestMethods []
 

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
kManifest_list 

Definition at line 67 of file OOJSManifest.m.

68{
69 kManifest_list // manifest list, array of commodities: name, unit, quantity, displayName - read-only
70};
@ kManifest_list

Function Documentation

◆ InitOOJSManifest()

void InitOOJSManifest ( JSContext * context,
JSObject * global )

Definition at line 129 of file OOJSManifest.m.

130{
131 sManifestPrototype = JS_InitClass(context, global, NULL, &sManifestClass, OOJSUnconstructableConstruct, 0, sManifestProperties, sManifestMethods, NULL, NULL);
133
134 // Create manifest object as a property of the player.ship object.
135 sManifestObject = JS_DefineObject(context, JSPlayerShipObject(), "manifest", &sManifestClass, sManifestPrototype, OOJS_PROP_READONLY);
136 JS_SetPrivate(context, sManifestObject, NULL);
137
138 // Also define manifest object as a property of the global object.
139 // Wait, what? Why? Oh well, too late now. Deprecate for EMMSTRAN? -- Ahruman 2011-02-10
140 JS_DefineObject(context, global, "manifest", &sManifestClass, sManifestPrototype, OOJS_PROP_READONLY);
141
142}
static JSObject * sManifestPrototype
static JSFunctionSpec sManifestMethods[]
static JSObject * sManifestObject
static JSClass sManifestClass
static JSPropertySpec sManifestProperties[]
JSObject * JSPlayerShipObject(void)
void OOJSRegisterObjectConverter(JSClass *theClass, OOJSClassConverterCallback converter)
JSBool OOJSUnconstructableConstruct(JSContext *context, uintN argc, jsval *vp)
#define OOJS_PROP_READONLY
id OOJSBasicPrivateObjectConverter(JSContext *context, JSObject *object)

References JSPlayerShipObject(), OOJS_PROP_READONLY, OOJSBasicPrivateObjectConverter(), OOJSRegisterObjectConverter(), OOJSUnconstructableConstruct(), sManifestClass, sManifestMethods, sManifestObject, sManifestProperties, and sManifestPrototype.

+ Here is the call graph for this function:

◆ ManifestComment()

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

Definition at line 232 of file OOJSManifest.m.

233{
234 OOJS_NATIVE_ENTER(context)
235
236 OOCommodityType good = nil;
237 NSString * information = nil;
238
239 if (argc > 0)
240 {
241 good = OOStringFromJSValue(context, OOJS_ARGV[0]);
242 }
243 if (good == nil)
244 {
245 OOJSReportBadArguments(context, @"Manifest", @"comment", MIN(argc, 1U), OOJS_ARGV, nil, @"good");
246 return NO;
247 }
248
249 information = [[PLAYER shipCommodityData] commentForGood:good];
250
251 OOJS_RETURN_OBJECT(information);
252
254}
#define OOJS_NATIVE_ENTER(cx)
#define OOJS_NATIVE_EXIT
#define OOJS_RETURN_OBJECT(o)
NSString * OOStringFromJSValue(JSContext *context, jsval value)
#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
return nil
NSString * OOCommodityType
Definition OOTypes.h:106

References MIN, nil, OOJS_ARGV, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_OBJECT, OOJSReportBadArguments(), and OOStringFromJSValue().

+ Here is the call graph for this function:

◆ ManifestDeleteProperty()

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

Definition at line 145 of file OOJSManifest.m.

146{
147 jsval v = JSVAL_VOID;
148 return ManifestSetProperty(context, this, propID, NO, &v);
149}
static JSBool ManifestSetProperty(JSContext *context, JSObject *this, jsid propID, JSBool strict, jsval *value)

References ManifestSetProperty().

+ Here is the call graph for this function:

◆ ManifestGetProperty()

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

Definition at line 152 of file OOJSManifest.m.

153{
154 OOJS_NATIVE_ENTER(context)
155
156 id result = nil;
158
159 if (JSID_IS_INT(propID))
160 {
161 switch (JSID_TO_INT(propID))
162 {
163 case kManifest_list:
164 result = [entity cargoListForScripting];
165 break;
166
167 default:
169 return NO;
170 }
171 }
172 else if (JSID_IS_STRING(propID))
173 {
174 /* 'list' property is hard-coded
175 * others map to the commodity keys in trade-goods.plist
176 * compatible-ish with 1.80 and earlier except that
177 * alienItems and similar aliases don't work */
178 NSString *key = OOStringFromJSString(context, JSID_TO_STRING(propID));
179 if ([[UNIVERSE commodities] goodDefined:key])
180 {
181 *value = INT_TO_JSVAL([entity cargoQuantityForType:key]);
182 return YES;
183 }
184 else
185 {
186 return YES;
187 }
188 }
189
190 *value = OOJSValueFromNativeObject(context, result);
191 return YES;
192
194}
PlayerEntity * OOPlayerForScripting(void)
Definition OOJSPlayer.m:191
OOINLINE jsval OOJSValueFromNativeObject(JSContext *context, id object)
void OOJSReportBadPropertySelector(JSContext *context, JSObject *thisObj, jsid propID, JSPropertySpec *propertySpec)
NSString * OOStringFromJSString(JSContext *context, JSString *string)
#define UNIVERSE
Definition Universe.h:833
NSArray * cargoListForScripting()

References PlayerEntity::cargoListForScripting, kManifest_list, nil, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJSReportBadPropertySelector(), OOJSValueFromNativeObject(), OOPlayerForScripting(), OOStringFromJSString(), sManifestProperties, and UNIVERSE.

+ Here is the call graph for this function:

◆ ManifestSetComment()

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

Definition at line 257 of file OOJSManifest.m.

258{
259 OOJS_NATIVE_ENTER(context)
260
261 BOOL OK;
262 OOCommodityType good = nil;
263 NSString * information = nil;
264
265 if (argc > 1)
266 {
267 good = OOStringFromJSValue(context, OOJS_ARGV[0]);
268 information = OOStringFromJSValue(context, OOJS_ARGV[1]);
269 }
270 if (good == nil || information == nil)
271 {
272 OOJSReportBadArguments(context, @"Manifest", @"setComment", MIN(argc, 2U), OOJS_ARGV, nil, @"good and information text");
273 return NO;
274 }
275
276 OK = [[PLAYER shipCommodityData] setComment:information forGood:good];
277
279
281}
#define OOJS_RETURN_BOOL(v)

References MIN, nil, OOJS_ARGV, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_BOOL, OOJSReportBadArguments(), and OOStringFromJSValue().

+ Here is the call graph for this function:

◆ ManifestSetProperty()

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

Definition at line 197 of file OOJSManifest.m.

198{
199 OOJS_NATIVE_ENTER(context)
200
202 int32 iValue;
203
204 if (JSID_IS_STRING(propID))
205 {
206 NSString *key = OOStringFromJSString(context, JSID_TO_STRING(propID));
207
208 OOMassUnit unit = [[UNIVERSE commodityMarket] massUnitForGood:key];
209 // we can always change gold, platinum & gem-stones quantities, even with special cargo
210 if (unit == UNITS_TONS && [entity specialCargo])
211 {
212 OOJSReportWarning(context, @"PlayerShip.manifest['foo'] - cannot modify cargo tonnage when Special Cargo is in use.");
213 return YES;
214 }
215
216 if (JS_ValueToInt32(context, *value, &iValue))
217 {
218 if (iValue < 0) iValue = 0;
219 [entity setCargoQuantityForType:key amount:iValue];
220 }
221 else
222 {
223 OOJSReportBadPropertyValue(context, this, propID, sManifestProperties, *value);
224 }
225 }
226 return YES;
227
229}
void OOJSReportWarning(JSContext *context, NSString *format,...)
void OOJSReportBadPropertyValue(JSContext *context, JSObject *thisObj, jsid propID, JSPropertySpec *propertySpec, jsval value)
OOMassUnit
Definition OOTypes.h:123
@ UNITS_TONS
Definition OOTypes.h:124
OOCargoQuantity setCargoQuantityForType:amount:(OOCommodityType type,[amount] OOCargoQuantity amount)

References OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJSReportBadPropertyValue(), OOJSReportWarning(), OOPlayerForScripting(), OOStringFromJSString(), PlayerEntity::setCargoQuantityForType:amount:, sManifestProperties, and UNITS_TONS.

Referenced by ManifestDeleteProperty().

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

◆ ManifestSetShortComment()

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

Definition at line 309 of file OOJSManifest.m.

310{
311 OOJS_NATIVE_ENTER(context)
312
313 BOOL OK;
314 OOCommodityType good = nil;
315 NSString * information = nil;
316
317 if (argc > 1)
318 {
319 good = OOStringFromJSValue(context, OOJS_ARGV[0]);
320 information = OOStringFromJSValue(context, OOJS_ARGV[1]);
321 }
322 if (good == nil || information == nil)
323 {
324 OOJSReportBadArguments(context, @"Manifest", @"setShortComment", MIN(argc, 2U), OOJS_ARGV, nil, @"good and information text");
325 return NO;
326 }
327
328 OK = [[PLAYER shipCommodityData] setShortComment:information forGood:good];
329
331
333}

◆ ManifestShortComment()

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

Definition at line 284 of file OOJSManifest.m.

285{
286 OOJS_NATIVE_ENTER(context)
287
288 OOCommodityType good = nil;
289 NSString * information = nil;
290
291 if (argc > 0)
292 {
293 good = OOStringFromJSValue(context, OOJS_ARGV[0]);
294 }
295 if (good == nil)
296 {
297 OOJSReportBadArguments(context, @"Manifest", @"shortComment", MIN(argc, 1U), OOJS_ARGV, nil, @"good");
298 return NO;
299 }
300
301 information = [[PLAYER shipCommodityData] shortCommentForGood:good];
302
303 OOJS_RETURN_OBJECT(information);
304
306}

References MIN, nil, OOJS_ARGV, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_OBJECT, OOJSReportBadArguments(), and OOStringFromJSValue().

+ Here is the call graph for this function:

Variable Documentation

◆ sManifestClass

JSClass sManifestClass
static
Initial value:
=
{
"Manifest",
JSCLASS_HAS_PRIVATE,
JS_PropertyStub,
JS_EnumerateStub,
JS_ResolveStub,
JS_ConvertStub,
JSCLASS_NO_OPTIONAL_MEMBERS
}
static JSBool ManifestDeleteProperty(JSContext *context, JSObject *this, jsid propID, jsval *value)
static JSBool ManifestGetProperty(JSContext *context, JSObject *this, jsid propID, jsval *value)
void OOJSObjectWrapperFinalize(JSContext *context, JSObject *this)

Definition at line 50 of file OOJSManifest.m.

51{
52 "Manifest",
53 JSCLASS_HAS_PRIVATE,
54
55 JS_PropertyStub,
59 JS_EnumerateStub,
60 JS_ResolveStub,
61 JS_ConvertStub,
63 JSCLASS_NO_OPTIONAL_MEMBERS
64};

Referenced by InitOOJSManifest().

◆ sManifestMethods

JSFunctionSpec sManifestMethods[]
static
Initial value:
=
{
{ "shortComment", ManifestShortComment, 1 },
{ "setShortComment", ManifestSetShortComment, 2 },
{ "comment", ManifestComment, 1 },
{ "setComment", ManifestSetComment, 2 },
{ 0 }
}
static JSBool ManifestShortComment(JSContext *context, uintN argc, jsval *vp)
static JSBool ManifestSetShortComment(JSContext *context, uintN argc, jsval *vp)
static JSBool ManifestComment(JSContext *context, uintN argc, jsval *vp)
static JSBool ManifestSetComment(JSContext *context, uintN argc, jsval *vp)

Definition at line 81 of file OOJSManifest.m.

82{
83 // JS name Function min args
84 { "shortComment", ManifestShortComment, 1 },
85 { "setShortComment", ManifestSetShortComment, 2 },
86 { "comment", ManifestComment, 1 },
87 { "setComment", ManifestSetComment, 2 },
88 { 0 }
89};

Referenced by InitOOJSManifest().

◆ sManifestObject

JSObject* sManifestObject
static

Definition at line 37 of file OOJSManifest.m.

Referenced by InitOOJSManifest().

◆ sManifestProperties

JSPropertySpec sManifestProperties[]
static
Initial value:
=
{
{ 0 }
}
#define OOJS_PROP_READONLY_CB

Definition at line 73 of file OOJSManifest.m.

74{
75 // JS name ID flags
77 { 0 }
78};

Referenced by InitOOJSManifest(), ManifestGetProperty(), and ManifestSetProperty().

◆ sManifestPrototype

JSObject* sManifestPrototype
static

Definition at line 36 of file OOJSManifest.m.

Referenced by InitOOJSManifest().