system.addPlanet() and system.addMoon() now return the new planet.

git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@3042 127b21dd-08f5-0310-b4b7-95ae10353056
This commit is contained in:
Jens Ayton 2010-02-26 11:33:22 +00:00
parent 93f35500f7
commit a97c00a247
5 changed files with 28 additions and 19 deletions

View File

@ -53,9 +53,10 @@ shaderMode : String (read/write)
NOTE: this is equivalent to oolite.gameSettings.shaderEffectsLevel, which
is available even when the debug console is not active, but is read-only.
function consoleMessage(colorCode : String, message : String)
Similar to Log(), but takes a colour code which is looked up in
debugConfig.plist. null is equivalent to "general".
function consoleMessage(colorCode : String, message : String [, emphasisStart : Number, emphasisLength : Number])
Similar to log(), but takes a colour code which is looked up in
debugConfig.plist. null is equivalent to "general". It can also optionally
take a range of characters that should be emphasised.
function clearConsole()
Clear the console.
@ -110,7 +111,7 @@ SOFTWARE.
this.name = "oolite-debug-console";
this.author = "Jens Ayton";
this.copyright = "© 2007-2008 the Oolite team.";
this.copyright = "© 2007-2010 the Oolite team.";
this.description = "Debug console script.";
this.version = "1.74";

View File

@ -345,7 +345,7 @@ static JSBool ConsoleSettingsSetProperty(JSContext *context, JSObject *this, jsv
// *** Methods ***
// function consoleMessage(message : String) : void
// function consoleMessage(colorCode : String, message : String [, emphasisStart : Number, emphasisLength : Number]) : void
static JSBool ConsoleConsoleMessage(JSContext *context, JSObject *this, uintN argc, jsval *argv, jsval *outResult)
{
id monitor = nil;

View File

@ -224,8 +224,8 @@ typedef enum
- (void) blowUpStation;
- (void) sendAllShipsAway;
- (void) addPlanet: (NSString *)planetKey;
- (void) addMoon: (NSString *)moonKey;
- (OOPlanetEntity *) addPlanet: (NSString *)planetKey;
- (OOPlanetEntity *) addMoon: (NSString *)moonKey;
- (void) debugOn;
- (void) debugOff;

View File

@ -2218,17 +2218,17 @@ static int scriptRandomSeed = -1; // ensure proper random function
}
- (void) addPlanet: (NSString *)planetKey
- (OOPlanetEntity *) addPlanet: (NSString *)planetKey
{
OOLog(kOOLogNoteAddPlanet, @"addPlanet: %@", planetKey);
if (!UNIVERSE)
return;
return nil;
NSDictionary* dict = [[UNIVERSE planetInfo] oo_dictionaryForKey:planetKey];
if (!dict)
{
OOLog(@"script.error.addPlanet.keyNotFound", @"***** ERROR: could not find an entry in planetinfo.plist for '%@'", planetKey);
return;
return nil;
}
/*- add planet -*/
@ -2244,7 +2244,7 @@ static int scriptRandomSeed = -1; // ensure proper random function
if (![dict objectForKey:@"position"])
{
OOLog(@"script.error.addPlanet.noPosition", @"***** ERROR: you must specify a position for scripted planet '%@' before it can be created", planetKey);
return;
return nil;
}
NSString *positionString = [dict objectForKey:@"position"];
@ -2266,20 +2266,21 @@ static int scriptRandomSeed = -1; // ensure proper random function
[planet setPosition: posn];
[UNIVERSE addEntity:planet];
return planet;
}
- (void) addMoon: (NSString *)moonKey
- (OOPlanetEntity *) addMoon: (NSString *)moonKey
{
OOLog(kOOLogNoteAddPlanet, @"DEBUG: addMoon '%@'", moonKey);
if (!UNIVERSE)
return;
return nil;
NSDictionary* dict = [[UNIVERSE planetInfo] oo_dictionaryForKey:moonKey];
if (!dict)
{
OOLog(@"script.error.addPlanet.keyNotFound", @"***** ERROR: could not find an entry in planetinfo.plist for '%@'", moonKey);
return;
return nil;
}
OOLog(kOOLogDebugAddPlanet, @"DEBUG: initMoonFromDictionary: %@", dict);
@ -2294,7 +2295,7 @@ static int scriptRandomSeed = -1; // ensure proper random function
if (![dict objectForKey:@"position"])
{
OOLog(@"script.error.addPlanet.noPosition", @"***** ERROR: you must specify a position for scripted moon '%@' before it can be created", moonKey);
return;
return nil;
}
NSString *positionString = [dict objectForKey:@"position"];
@ -2315,6 +2316,7 @@ static int scriptRandomSeed = -1; // ensure proper random function
[planet setPosition: posn];
[UNIVERSE addEntity:planet];
return planet;
}

View File

@ -441,11 +441,12 @@ static JSBool SystemToString(JSContext *context, JSObject *this, uintN argc, jsv
}
// addPlanet(key : String)
// addPlanet(key : String) : Planet
static JSBool SystemAddPlanet(JSContext *context, JSObject *this, uintN argc, jsval *argv, jsval *outResult)
{
PlayerEntity *player = OOPlayerForScripting();
NSString *key = nil;
OOPlanetEntity *planet = nil;
key = JSValToNSString(context, argv[0]);
if (EXPECT_NOT(key == nil))
@ -454,16 +455,19 @@ static JSBool SystemAddPlanet(JSContext *context, JSObject *this, uintN argc, js
return NO;
}
[player addPlanet:key];
planet = [player addPlanet:key];
*outResult = planet ? [planet javaScriptValueInContext:context] : JSVAL_NULL;
return YES;
}
// addMoon(key : String)
// addMoon(key : String) : Planet
static JSBool SystemAddMoon(JSContext *context, JSObject *this, uintN argc, jsval *argv, jsval *outResult)
{
PlayerEntity *player = OOPlayerForScripting();
NSString *key = nil;
OOPlanetEntity *planet = nil;
key = JSValToNSString(context, argv[0]);
if (EXPECT_NOT(key == nil))
@ -472,7 +476,9 @@ static JSBool SystemAddMoon(JSContext *context, JSObject *this, uintN argc, jsva
return NO;
}
[player addMoon:key];
planet = [player addMoon:key];
*outResult = planet ? [planet javaScriptValueInContext:context] : JSVAL_NULL;
return YES;
}