Oolite
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 62 of file OOJSManifest.m.

62 {
63 kManifest_list // manifest list, array of commodities: name, unit, quantity, displayName - read-only
64};
@ kManifest_list

Function Documentation

◆ InitOOJSManifest()

void InitOOJSManifest ( JSContext * context,
JSObject * global )

Definition at line 115 of file OOJSManifest.m.

116{
117 sManifestPrototype = JS_InitClass(context, global, NULL, &sManifestClass, OOJSUnconstructableConstruct, 0, sManifestProperties, sManifestMethods, NULL, NULL);
119
120 // Create manifest object as a property of the player.ship object.
121 sManifestObject = JS_DefineObject(context, JSPlayerShipObject(), "manifest", &sManifestClass, sManifestPrototype, OOJS_PROP_READONLY);
122 JS_SetPrivate(context, sManifestObject, NULL);
123
124 // Also define manifest object as a property of the global object.
125 // Wait, what? Why? Oh well, too late now. Deprecate for EMMSTRAN? -- Ahruman 2011-02-10
126 JS_DefineObject(context, global, "manifest", &sManifestClass, sManifestPrototype, OOJS_PROP_READONLY);
127}
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.

Referenced by OOJavaScriptEngine(Private)::createMainThreadContext.

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

◆ ManifestComment()

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

Definition at line 202 of file OOJSManifest.m.

203{
204 OOJS_NATIVE_ENTER(context)
205
206 OOCommodityType good = nil;
207 NSString* information = nil;
208
209 if (argc > 0) {
210 good = OOStringFromJSValue(context, OOJS_ARGV[0]);
211 }
212 if (good == nil) {
213 OOJSReportBadArguments(context, @"Manifest", @"comment", MIN(argc, 1U), OOJS_ARGV, nil, @"good");
214 return NO;
215 }
216
217 information = [[PLAYER shipCommodityData] commentForGood:good];
218
219 OOJS_RETURN_OBJECT(information);
220
222}
#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:91
return nil
NSString * OOCommodityType
Definition OOTypes.h:97

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()

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

Definition at line 129 of file OOJSManifest.m.

130{
131 jsval v = JSVAL_VOID;
132 return ManifestSetProperty(context, this, propID, NO, &v);
133}
static JSBool ManifestSetProperty(JSContext *context, JSObject *this, jsid propID, JSBool strict, jsval *value)

References ManifestSetProperty().

Here is the call graph for this function:

◆ ManifestGetProperty()

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

Definition at line 135 of file OOJSManifest.m.

136{
137 OOJS_NATIVE_ENTER(context)
138
139 id result = nil;
141
142 if (JSID_IS_INT(propID)) {
143 switch (JSID_TO_INT(propID)) {
144 case kManifest_list:
145 result = [entity cargoListForScripting];
146 break;
147
148 default:
150 return NO;
151 }
152 } else if (JSID_IS_STRING(propID)) {
153 /* 'list' property is hard-coded
154 * others map to the commodity keys in trade-goods.plist
155 * compatible-ish with 1.80 and earlier except that
156 * alienItems and similar aliases don't work */
157 NSString* key = OOStringFromJSString(context, JSID_TO_STRING(propID));
158 if ([[UNIVERSE commodities] goodDefined:key]) {
159 *value = INT_TO_JSVAL([entity cargoQuantityForType:key]);
160 return YES;
161 } else {
162 return YES;
163 }
164 }
165
166 *value = OOJSValueFromNativeObject(context, result);
167 return YES;
168
170}
PlayerEntity * OOPlayerForScripting(void)
Definition OOJSPlayer.m:175
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:827
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()

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

Definition at line 224 of file OOJSManifest.m.

225{
226 OOJS_NATIVE_ENTER(context)
227
228 BOOL OK;
229 OOCommodityType good = nil;
230 NSString* information = nil;
231
232 if (argc > 1) {
233 good = OOStringFromJSValue(context, OOJS_ARGV[0]);
234 information = OOStringFromJSValue(context, OOJS_ARGV[1]);
235 }
236 if (good == nil || information == nil) {
237 OOJSReportBadArguments(context, @"Manifest", @"setComment", MIN(argc, 2U), OOJS_ARGV, nil, @"good and information text");
238 return NO;
239 }
240
241 OK = [[PLAYER shipCommodityData] setComment:information forGood:good];
242
244
246}
#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()

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

Definition at line 172 of file OOJSManifest.m.

173{
174 OOJS_NATIVE_ENTER(context)
175
177 int32 iValue;
178
179 if (JSID_IS_STRING(propID)) {
180 NSString* key = OOStringFromJSString(context, JSID_TO_STRING(propID));
181
182 OOMassUnit unit = [[UNIVERSE commodityMarket] massUnitForGood:key];
183 // we can always change gold, platinum & gem-stones quantities, even with special cargo
184 if (unit == UNITS_TONS && [entity specialCargo]) {
185 OOJSReportWarning(context, @"PlayerShip.manifest['foo'] - cannot modify cargo tonnage when Special Cargo is in use.");
186 return YES;
187 }
188
189 if (JS_ValueToInt32(context, *value, &iValue)) {
190 if (iValue < 0)
191 iValue = 0;
192 [entity setCargoQuantityForType:key amount:iValue];
193 } else {
194 OOJSReportBadPropertyValue(context, this, propID, sManifestProperties, *value);
195 }
196 }
197 return YES;
198
200}
void OOJSReportWarning(JSContext *context, NSString *format,...)
void OOJSReportBadPropertyValue(JSContext *context, JSObject *thisObj, jsid propID, JSPropertySpec *propertySpec, jsval value)
OOMassUnit
Definition OOTypes.h:111
@ UNITS_TONS
Definition OOTypes.h:112
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.

Here is the call graph for this function:

◆ ManifestSetShortComment()

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

Definition at line 270 of file OOJSManifest.m.

271{
272 OOJS_NATIVE_ENTER(context)
273
274 BOOL OK;
275 OOCommodityType good = nil;
276 NSString* information = nil;
277
278 if (argc > 1) {
279 good = OOStringFromJSValue(context, OOJS_ARGV[0]);
280 information = OOStringFromJSValue(context, OOJS_ARGV[1]);
281 }
282 if (good == nil || information == nil) {
283 OOJSReportBadArguments(context, @"Manifest", @"setShortComment", MIN(argc, 2U), OOJS_ARGV, nil, @"good and information text");
284 return NO;
285 }
286
287 OK = [[PLAYER shipCommodityData] setShortComment:information forGood:good];
288
290
292}

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:

◆ ManifestShortComment()

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

Definition at line 248 of file OOJSManifest.m.

249{
250 OOJS_NATIVE_ENTER(context)
251
252 OOCommodityType good = nil;
253 NSString* information = nil;
254
255 if (argc > 0) {
256 good = OOStringFromJSValue(context, OOJS_ARGV[0]);
257 }
258 if (good == nil) {
259 OOJSReportBadArguments(context, @"Manifest", @"shortComment", MIN(argc, 1U), OOJS_ARGV, nil, @"good");
260 return NO;
261 }
262
263 information = [[PLAYER shipCommodityData] shortCommentForGood:good];
264
265 OOJS_RETURN_OBJECT(information);
266
268}

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 47 of file OOJSManifest.m.

47 {
48 "Manifest",
49 JSCLASS_HAS_PRIVATE,
50
51 JS_PropertyStub,
55 JS_EnumerateStub,
56 JS_ResolveStub,
57 JS_ConvertStub,
59 JSCLASS_NO_OPTIONAL_MEMBERS
60};

Referenced by InitOOJSManifest(), and 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 72 of file OOJSManifest.m.

72 {
73 // JS name Function min args
74 { "shortComment", ManifestShortComment, 1 },
75 { "setShortComment", ManifestSetShortComment, 2 },
76 { "comment", ManifestComment, 1 },
77 { "setComment", ManifestSetComment, 2 },
78 { 0 }
79};

Referenced by InitOOJSManifest(), and InitOOJSManifest().

◆ sManifestObject

JSObject* sManifestObject
static

Definition at line 36 of file OOJSManifest.m.

Referenced by InitOOJSManifest().

◆ sManifestProperties

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

Definition at line 66 of file OOJSManifest.m.

66 {
67 // JS name ID flags
69 { 0 }
70};

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

◆ sManifestPrototype

JSObject* sManifestPrototype
static

Definition at line 35 of file OOJSManifest.m.

Referenced by InitOOJSManifest(), and OOManifest::oo_jsValueInContext:.