Change markedSystems to a property

git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@5217 127b21dd-08f5-0310-b4b7-95ae10353056
This commit is contained in:
Chris Morris 2012-08-20 19:35:29 +00:00
parent 36b4e9ae04
commit 2700c41434

View File

@ -34,6 +34,7 @@ MA 02110-1301, USA.
#import "OOMusicController.h"
#import "GuiDisplayGen.h"
static JSBool MissionGetProperty(JSContext *context, JSObject *this, jsid propID, jsval *value);
static JSBool MissionMarkSystem(JSContext *context, uintN argc, jsval *vp);
static JSBool MissionMarkedSystems(JSContext *context, uintN argc, jsval *vp);
@ -59,7 +60,7 @@ static JSClass sMissionClass =
JS_PropertyStub,
JS_PropertyStub,
JS_PropertyStub,
MissionGetProperty,
JS_StrictPropertyStub,
JS_EnumerateStub,
JS_ResolveStub,
@ -68,12 +69,25 @@ static JSClass sMissionClass =
};
enum
{
kMission_markedSystems,
};
static JSPropertySpec sMissionProperties[] =
{
// JS name ID flags
{ "markedSystems", kMission_markedSystems, OOJS_PROP_READONLY_CB },
{ 0 }
};
static JSFunctionSpec sMissionMethods[] =
{
// JS name Function min args
{ "addMessageText", MissionAddMessageText, 1 },
{ "markSystem", MissionMarkSystem, 1 },
{ "markedSystems", MissionMarkedSystems, 1 },
{ "runScreen", MissionRunScreen, 1 }, // the callback function is optional!
{ "setInstructions", MissionSetInstructions, 1 },
{ "setInstructionsKey", MissionSetInstructionsKey, 1 },
@ -87,7 +101,7 @@ void InitOOJSMission(JSContext *context, JSObject *global)
sCallbackFunction = JSVAL_NULL;
sCallbackThis = JSVAL_NULL;
JSObject *missionPrototype = JS_InitClass(context, global, NULL, &sMissionClass, OOJSUnconstructableConstruct, 0, NULL, sMissionMethods, NULL, NULL);
JSObject *missionPrototype = JS_InitClass(context, global, NULL, &sMissionClass, OOJSUnconstructableConstruct, 0, sMissionProperties, sMissionMethods, NULL, NULL);
sMissionObject = JS_DefineObject(context, global, "mission", &sMissionClass, missionPrototype, OOJS_PROP_READONLY);
// Ensure JS objects are rooted.
@ -152,6 +166,35 @@ void MissionRunCallback()
}
static JSBool MissionGetProperty(JSContext *context, JSObject *this, jsid propID, jsval *value)
{
if (!JSID_IS_INT(propID)) return YES;
OOJS_NATIVE_ENTER(context)
id result = nil;
PlayerEntity *player = OOPlayerForScripting();
switch (JSID_TO_INT(propID))
{
case kMission_markedSystems:
result = [player getMissionDestinations];
if (result == nil) result = [NSDictionary dictionary];
result = [result allValues];
break;
default:
OOJSReportBadPropertySelector(context, this, propID, sMissionProperties);
return NO;
}
*value = OOJSValueFromNativeObject(context, result);
return YES;
OOJS_NATIVE_EXIT
}
// *** Methods ***
// markSystem(integer+)
@ -521,16 +564,3 @@ static JSBool MissionRunScreen(JSContext *context, uintN argc, jsval *vp)
}
static JSBool MissionMarkedSystems(JSContext *context, uintN argc, jsval *vp)
{
OOJS_PROFILE_ENTER
PlayerEntity *player = PLAYER;
NSDictionary *result = nil;
result = [player getMissionDestinations];
if (result == nil) result = [NSDictionary dictionary];
OOJS_RETURN_OBJECT([result allValues]);
OOJS_PROFILE_EXIT
}