JS interfaces to exhausts, flashers - closes #43
ship.exhausts ship.flashers Exhausts and flashers both have r/w .size property and .remove() method Flashers might get some more properties later for colour/phase/etc.
This commit is contained in:
parent
90ad6c5025
commit
fb53a45ff2
@ -287,6 +287,8 @@ OOLITE_SCRIPTING_FILES = \
|
|||||||
OOJSDock.m \
|
OOJSDock.m \
|
||||||
OOJSEntity.m \
|
OOJSEntity.m \
|
||||||
OOJSEquipmentInfo.m \
|
OOJSEquipmentInfo.m \
|
||||||
|
OOJSExhaustPlume.m \
|
||||||
|
OOJSFlasher.m \
|
||||||
OOJSFunction.m \
|
OOJSFunction.m \
|
||||||
OOJSGlobal.m \
|
OOJSGlobal.m \
|
||||||
OOJSInterfaceDefinition.m \
|
OOJSInterfaceDefinition.m \
|
||||||
|
@ -58,6 +58,9 @@ enum
|
|||||||
|
|
||||||
- (void) resetPlume;
|
- (void) resetPlume;
|
||||||
|
|
||||||
|
- (Vector) scale;
|
||||||
|
- (void) setScale:(Vector)scale;
|
||||||
|
|
||||||
- (OOTexture *) texture;
|
- (OOTexture *) texture;
|
||||||
|
|
||||||
+ (void) setUpTexture;
|
+ (void) setUpTexture;
|
||||||
|
@ -77,13 +77,29 @@ static OOTexture *sPlumeTexture = nil;
|
|||||||
HPVector pos = { [definition oo_floatAtIndex:0], [definition oo_floatAtIndex:1], [definition oo_floatAtIndex:2] };
|
HPVector pos = { [definition oo_floatAtIndex:0], [definition oo_floatAtIndex:1], [definition oo_floatAtIndex:2] };
|
||||||
[self setPosition:pos];
|
[self setPosition:pos];
|
||||||
Vector scale = { [definition oo_floatAtIndex:3], [definition oo_floatAtIndex:4], [definition oo_floatAtIndex:5] };
|
Vector scale = { [definition oo_floatAtIndex:3], [definition oo_floatAtIndex:4], [definition oo_floatAtIndex:5] };
|
||||||
_exhaustScale = scale;
|
[self setScale:scale];
|
||||||
}
|
}
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
- (Vector) scale
|
||||||
|
{
|
||||||
|
return _exhaustScale;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
- (void) setScale:(Vector)scale
|
||||||
|
{
|
||||||
|
_exhaustScale = scale;
|
||||||
|
if (scale.z < 0.5 || scale.z > 2.0)
|
||||||
|
{
|
||||||
|
_exhaustScale.z = 1.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
- (BOOL)isExhaust
|
- (BOOL)isExhaust
|
||||||
{
|
{
|
||||||
return YES;
|
return YES;
|
||||||
@ -166,14 +182,6 @@ static OOTexture *sPlumeTexture = nil;
|
|||||||
GLfloat speedScale = fminf(1.0,speed*5.0);
|
GLfloat speedScale = fminf(1.0,speed*5.0);
|
||||||
|
|
||||||
GLfloat exhaust_factor = _exhaustScale.z;
|
GLfloat exhaust_factor = _exhaustScale.z;
|
||||||
if (exhaust_factor < 0.5)
|
|
||||||
{
|
|
||||||
exhaust_factor = 1.0;
|
|
||||||
}
|
|
||||||
else if (exhaust_factor > 2.0)
|
|
||||||
{
|
|
||||||
exhaust_factor = 1.0;
|
|
||||||
}
|
|
||||||
GLfloat i01 = -0.00 * hyper_fade;
|
GLfloat i01 = -0.00 * hyper_fade;
|
||||||
GLfloat i03 = -0.12 * exhaust_factor;
|
GLfloat i03 = -0.12 * exhaust_factor;
|
||||||
GLfloat i06 = -0.25 * exhaust_factor;
|
GLfloat i06 = -0.25 * exhaust_factor;
|
||||||
|
@ -90,7 +90,7 @@
|
|||||||
|
|
||||||
- (void) clearSubEntities;
|
- (void) clearSubEntities;
|
||||||
- (BOOL) setUpSubEntities;
|
- (BOOL) setUpSubEntities;
|
||||||
- (void) removeSubEntity:(OOVisualEffectEntity *)sub;
|
- (void) removeSubEntity:(Entity<OOSubEntity> *)sub;
|
||||||
- (void) setNoDrawDistance;
|
- (void) setNoDrawDistance;
|
||||||
- (NSArray *)subEntities;
|
- (NSArray *)subEntities;
|
||||||
- (NSUInteger) subEntityCount;
|
- (NSUInteger) subEntityCount;
|
||||||
|
@ -254,7 +254,7 @@ MA 02110-1301, USA.
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
- (void) removeSubEntity:(OOVisualEffectEntity *)sub
|
- (void) removeSubEntity:(Entity<OOSubEntity> *)sub
|
||||||
{
|
{
|
||||||
[sub setOwner:nil];
|
[sub setOwner:nil];
|
||||||
[subEntities removeObject:sub];
|
[subEntities removeObject:sub];
|
||||||
|
@ -30,7 +30,8 @@
|
|||||||
#import "OOJSPropID.h"
|
#import "OOJSPropID.h"
|
||||||
|
|
||||||
@class OOColor, StationEntity, WormholeEntity, AI, Octree, OOMesh, OOScript,
|
@class OOColor, StationEntity, WormholeEntity, AI, Octree, OOMesh, OOScript,
|
||||||
OOJSScript, OORoleSet, OOShipGroup, OOEquipmentType, OOWeakSet;
|
OOJSScript, OORoleSet, OOShipGroup, OOEquipmentType, OOWeakSet,
|
||||||
|
OOExhaustPlumeEntity, OOFlasherEntity;
|
||||||
|
|
||||||
#define MAX_TARGETS 24
|
#define MAX_TARGETS 24
|
||||||
#define RAIDER_MAX_CARGO 5
|
#define RAIDER_MAX_CARGO 5
|
||||||
@ -910,6 +911,10 @@ Vector positionOffsetForShipInRotationToAlignment(ShipEntity* ship, Quaternion q
|
|||||||
|
|
||||||
- (void) resetExhaustPlumes;
|
- (void) resetExhaustPlumes;
|
||||||
|
|
||||||
|
- (void) removeExhaust:(OOExhaustPlumeEntity *)exhaust;
|
||||||
|
- (void) removeFlasher:(OOFlasherEntity *)flasher;
|
||||||
|
|
||||||
|
|
||||||
/*-----------------------------------------
|
/*-----------------------------------------
|
||||||
|
|
||||||
AI piloting methods
|
AI piloting methods
|
||||||
|
@ -8575,6 +8575,20 @@ NSComparisonResult ComparePlanetsBySurfaceDistance(id i1, id i2, void* context)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
- (void) removeExhaust:(OOExhaustPlumeEntity *)exhaust
|
||||||
|
{
|
||||||
|
[subEntities removeObject:exhaust];
|
||||||
|
[exhaust setOwner:nil];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
- (void) removeFlasher:(OOFlasherEntity *)flasher
|
||||||
|
{
|
||||||
|
[subEntities removeObject:flasher];
|
||||||
|
[flasher setOwner:nil];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
- (void)subEntityDied:(ShipEntity *)sub
|
- (void)subEntityDied:(ShipEntity *)sub
|
||||||
{
|
{
|
||||||
if ([self subEntityTakingDamage] == sub) [self setSubEntityTakingDamage:nil];
|
if ([self subEntityTakingDamage] == sub) [self setSubEntityTakingDamage:nil];
|
||||||
|
40
src/Core/Scripting/OOJSExhaustPlume.h
Normal file
40
src/Core/Scripting/OOJSExhaustPlume.h
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
OOJSExhaustPlume.h
|
||||||
|
|
||||||
|
JavaScript proxy for OOExhaustPlumeEntity.
|
||||||
|
|
||||||
|
Oolite
|
||||||
|
Copyright (C) 2004-2013 Giles C Williams and contributors
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License
|
||||||
|
as published by the Free Software Foundation; either version 2
|
||||||
|
of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
MA 02110-1301, USA.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
#include <jsapi.h>
|
||||||
|
#import "OOExhaustPlumeEntity.h"
|
||||||
|
|
||||||
|
|
||||||
|
void InitOOJSExhaustPlume(JSContext *context, JSObject *global);
|
||||||
|
|
||||||
|
@interface OOExhaustPlumeEntity (OOJavaScriptExtensions)
|
||||||
|
|
||||||
|
- (void)getJSClass:(JSClass **)outClass andPrototype:(JSObject **)outPrototype;
|
||||||
|
- (NSString *) oo_jsClassName;
|
||||||
|
- (BOOL) isVisibleToScripts;
|
||||||
|
|
||||||
|
@end
|
223
src/Core/Scripting/OOJSExhaustPlume.m
Normal file
223
src/Core/Scripting/OOJSExhaustPlume.m
Normal file
@ -0,0 +1,223 @@
|
|||||||
|
/*
|
||||||
|
OOJSExhaustPlume.m
|
||||||
|
|
||||||
|
Oolite
|
||||||
|
Copyright (C) 2004-2013 Giles C Williams and contributors
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License
|
||||||
|
as published by the Free Software Foundation; either version 2
|
||||||
|
of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
MA 02110-1301, USA.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#import "OOExhaustPlumeEntity.h"
|
||||||
|
#import "OOJSExhaustPlume.h"
|
||||||
|
#import "OOJSEntity.h"
|
||||||
|
#import "OOJSVector.h"
|
||||||
|
#import "OOJavaScriptEngine.h"
|
||||||
|
#import "EntityOOJavaScriptExtensions.h"
|
||||||
|
#import "ShipEntity.h"
|
||||||
|
|
||||||
|
|
||||||
|
static JSObject *sExhaustPlumePrototype;
|
||||||
|
|
||||||
|
static BOOL JSExhaustPlumeGetExhaustPlumeEntity(JSContext *context, JSObject *jsobj, OOExhaustPlumeEntity **outEntity);
|
||||||
|
|
||||||
|
|
||||||
|
static JSBool ExhaustPlumeGetProperty(JSContext *context, JSObject *this, jsid propID, jsval *value);
|
||||||
|
static JSBool ExhaustPlumeSetProperty(JSContext *context, JSObject *this, jsid propID, JSBool strict, jsval *value);
|
||||||
|
|
||||||
|
static JSBool ExhaustPlumeRemove(JSContext *context, uintN argc, jsval *vp);
|
||||||
|
|
||||||
|
|
||||||
|
static JSClass sExhaustPlumeClass =
|
||||||
|
{
|
||||||
|
"ExhaustPlume",
|
||||||
|
JSCLASS_HAS_PRIVATE,
|
||||||
|
|
||||||
|
JS_PropertyStub, // addProperty
|
||||||
|
JS_PropertyStub, // delProperty
|
||||||
|
ExhaustPlumeGetProperty, // getProperty
|
||||||
|
ExhaustPlumeSetProperty, // setProperty
|
||||||
|
JS_EnumerateStub, // enumerate
|
||||||
|
JS_ResolveStub, // resolve
|
||||||
|
JS_ConvertStub, // convert
|
||||||
|
OOJSObjectWrapperFinalize,// finalize
|
||||||
|
JSCLASS_NO_OPTIONAL_MEMBERS
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
// Property IDs
|
||||||
|
kExhaustPlume_size
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
static JSPropertySpec sExhaustPlumeProperties[] =
|
||||||
|
{
|
||||||
|
// JS name ID flags
|
||||||
|
{ "size", kExhaustPlume_size, OOJS_PROP_READWRITE_CB },
|
||||||
|
{ 0 }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
static JSFunctionSpec sExhaustPlumeMethods[] =
|
||||||
|
{
|
||||||
|
// JS name Function min args
|
||||||
|
{ "remove", ExhaustPlumeRemove, 0 },
|
||||||
|
|
||||||
|
{ 0 }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
void InitOOJSExhaustPlume(JSContext *context, JSObject *global)
|
||||||
|
{
|
||||||
|
sExhaustPlumePrototype = JS_InitClass(context, global, JSEntityPrototype(), &sExhaustPlumeClass, OOJSUnconstructableConstruct, 0, sExhaustPlumeProperties, sExhaustPlumeMethods, NULL, NULL);
|
||||||
|
OOJSRegisterObjectConverter(&sExhaustPlumeClass, OOJSBasicPrivateObjectConverter);
|
||||||
|
OOJSRegisterSubclass(&sExhaustPlumeClass, JSEntityClass());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static BOOL JSExhaustPlumeGetExhaustPlumeEntity(JSContext *context, JSObject *jsobj, OOExhaustPlumeEntity **outEntity)
|
||||||
|
{
|
||||||
|
OOJS_PROFILE_ENTER
|
||||||
|
|
||||||
|
BOOL result;
|
||||||
|
Entity *entity = nil;
|
||||||
|
|
||||||
|
if (outEntity == NULL) return NO;
|
||||||
|
*outEntity = nil;
|
||||||
|
|
||||||
|
result = OOJSEntityGetEntity(context, jsobj, &entity);
|
||||||
|
if (!result) return NO;
|
||||||
|
|
||||||
|
if (![entity isKindOfClass:[OOExhaustPlumeEntity class]]) return NO;
|
||||||
|
|
||||||
|
*outEntity = (OOExhaustPlumeEntity *)entity;
|
||||||
|
return YES;
|
||||||
|
|
||||||
|
OOJS_PROFILE_EXIT
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@implementation OOExhaustPlumeEntity (OOJavaScriptExtensions)
|
||||||
|
|
||||||
|
- (void)getJSClass:(JSClass **)outClass andPrototype:(JSObject **)outPrototype
|
||||||
|
{
|
||||||
|
*outClass = &sExhaustPlumeClass;
|
||||||
|
*outPrototype = sExhaustPlumePrototype;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
- (NSString *) oo_jsClassName
|
||||||
|
{
|
||||||
|
return @"ExhaustPlume";
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL) isVisibleToScripts
|
||||||
|
{
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
static JSBool ExhaustPlumeGetProperty(JSContext *context, JSObject *this, jsid propID, jsval *value)
|
||||||
|
{
|
||||||
|
if (!JSID_IS_INT(propID)) return YES;
|
||||||
|
|
||||||
|
OOJS_NATIVE_ENTER(context)
|
||||||
|
|
||||||
|
OOExhaustPlumeEntity *entity = nil;
|
||||||
|
id result = nil;
|
||||||
|
|
||||||
|
if (!JSExhaustPlumeGetExhaustPlumeEntity(context, this, &entity)) return NO;
|
||||||
|
if (entity == nil) { *value = JSVAL_VOID; return YES; }
|
||||||
|
|
||||||
|
switch (JSID_TO_INT(propID))
|
||||||
|
{
|
||||||
|
case kExhaustPlume_size:
|
||||||
|
return VectorToJSValue(context, [entity scale], value);
|
||||||
|
|
||||||
|
default:
|
||||||
|
OOJSReportBadPropertySelector(context, this, propID, sExhaustPlumeProperties);
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
|
||||||
|
*value = OOJSValueFromNativeObject(context, result);
|
||||||
|
return YES;
|
||||||
|
|
||||||
|
OOJS_NATIVE_EXIT
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static JSBool ExhaustPlumeSetProperty(JSContext *context, JSObject *this, jsid propID, JSBool strict, jsval *value)
|
||||||
|
{
|
||||||
|
if (!JSID_IS_INT(propID)) return YES;
|
||||||
|
|
||||||
|
OOJS_NATIVE_ENTER(context)
|
||||||
|
|
||||||
|
OOExhaustPlumeEntity *entity = nil;
|
||||||
|
Vector vValue;
|
||||||
|
|
||||||
|
if (!JSExhaustPlumeGetExhaustPlumeEntity(context, this, &entity)) return NO;
|
||||||
|
if (entity == nil) return YES;
|
||||||
|
|
||||||
|
switch (JSID_TO_INT(propID))
|
||||||
|
{
|
||||||
|
case kExhaustPlume_size:
|
||||||
|
if (JSValueToVector(context, *value, &vValue))
|
||||||
|
{
|
||||||
|
[entity setScale:vValue];
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
OOJSReportBadPropertySelector(context, this, propID, sExhaustPlumeProperties);
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
|
||||||
|
OOJSReportBadPropertyValue(context, this, propID, sExhaustPlumeProperties, *value);
|
||||||
|
return NO;
|
||||||
|
|
||||||
|
OOJS_NATIVE_EXIT
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// *** Methods ***
|
||||||
|
|
||||||
|
#define GET_THIS_EXHAUSTPLUME(THISENT) do { \
|
||||||
|
if (EXPECT_NOT(!JSExhaustPlumeGetExhaustPlumeEntity(context, OOJS_THIS, &THISENT))) return NO; /* Exception */ \
|
||||||
|
if (OOIsStaleEntity(THISENT)) OOJS_RETURN_VOID; \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
|
||||||
|
static JSBool ExhaustPlumeRemove(JSContext *context, uintN argc, jsval *vp)
|
||||||
|
{
|
||||||
|
OOJS_NATIVE_ENTER(context)
|
||||||
|
|
||||||
|
OOExhaustPlumeEntity *thisEnt = nil;
|
||||||
|
GET_THIS_EXHAUSTPLUME(thisEnt);
|
||||||
|
|
||||||
|
ShipEntity *parent = [thisEnt owner];
|
||||||
|
[parent removeExhaust:thisEnt];
|
||||||
|
|
||||||
|
OOJS_RETURN_VOID;
|
||||||
|
|
||||||
|
OOJS_NATIVE_EXIT
|
||||||
|
}
|
||||||
|
|
||||||
|
|
40
src/Core/Scripting/OOJSFlasher.h
Normal file
40
src/Core/Scripting/OOJSFlasher.h
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
OOJSFlasher.h
|
||||||
|
|
||||||
|
JavaScript proxy for OOFlasherEntity.
|
||||||
|
|
||||||
|
Oolite
|
||||||
|
Copyright (C) 2004-2013 Giles C Williams and contributors
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License
|
||||||
|
as published by the Free Software Foundation; either version 2
|
||||||
|
of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
MA 02110-1301, USA.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
#include <jsapi.h>
|
||||||
|
#import "OOFlasherEntity.h"
|
||||||
|
|
||||||
|
|
||||||
|
void InitOOJSFlasher(JSContext *context, JSObject *global);
|
||||||
|
|
||||||
|
@interface OOFlasherEntity (OOJavaScriptExtensions)
|
||||||
|
|
||||||
|
- (void)getJSClass:(JSClass **)outClass andPrototype:(JSObject **)outPrototype;
|
||||||
|
- (NSString *) oo_jsClassName;
|
||||||
|
- (BOOL) isVisibleToScripts;
|
||||||
|
|
||||||
|
@end
|
234
src/Core/Scripting/OOJSFlasher.m
Normal file
234
src/Core/Scripting/OOJSFlasher.m
Normal file
@ -0,0 +1,234 @@
|
|||||||
|
/*
|
||||||
|
OOJSFlasher.m
|
||||||
|
|
||||||
|
Oolite
|
||||||
|
Copyright (C) 2004-2013 Giles C Williams and contributors
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License
|
||||||
|
as published by the Free Software Foundation; either version 2
|
||||||
|
of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
MA 02110-1301, USA.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#import "OOFlasherEntity.h"
|
||||||
|
#import "OOJSFlasher.h"
|
||||||
|
#import "OOJSEntity.h"
|
||||||
|
#import "OOJSVector.h"
|
||||||
|
#import "OOJavaScriptEngine.h"
|
||||||
|
#import "EntityOOJavaScriptExtensions.h"
|
||||||
|
#import "ShipEntity.h"
|
||||||
|
#import "OOVisualEffectEntity.h"
|
||||||
|
|
||||||
|
|
||||||
|
static JSObject *sFlasherPrototype;
|
||||||
|
|
||||||
|
static BOOL JSFlasherGetFlasherEntity(JSContext *context, JSObject *jsobj, OOFlasherEntity **outEntity);
|
||||||
|
|
||||||
|
|
||||||
|
static JSBool FlasherGetProperty(JSContext *context, JSObject *this, jsid propID, jsval *value);
|
||||||
|
static JSBool FlasherSetProperty(JSContext *context, JSObject *this, jsid propID, JSBool strict, jsval *value);
|
||||||
|
|
||||||
|
static JSBool FlasherRemove(JSContext *context, uintN argc, jsval *vp);
|
||||||
|
|
||||||
|
|
||||||
|
static JSClass sFlasherClass =
|
||||||
|
{
|
||||||
|
"Flasher",
|
||||||
|
JSCLASS_HAS_PRIVATE,
|
||||||
|
|
||||||
|
JS_PropertyStub, // addProperty
|
||||||
|
JS_PropertyStub, // delProperty
|
||||||
|
FlasherGetProperty, // getProperty
|
||||||
|
FlasherSetProperty, // setProperty
|
||||||
|
JS_EnumerateStub, // enumerate
|
||||||
|
JS_ResolveStub, // resolve
|
||||||
|
JS_ConvertStub, // convert
|
||||||
|
OOJSObjectWrapperFinalize,// finalize
|
||||||
|
JSCLASS_NO_OPTIONAL_MEMBERS
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
// Property IDs
|
||||||
|
kFlasher_size
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
static JSPropertySpec sFlasherProperties[] =
|
||||||
|
{
|
||||||
|
// JS name ID flags
|
||||||
|
{ "size", kFlasher_size, OOJS_PROP_READWRITE_CB },
|
||||||
|
{ 0 }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
static JSFunctionSpec sFlasherMethods[] =
|
||||||
|
{
|
||||||
|
// JS name Function min args
|
||||||
|
{ "remove", FlasherRemove, 0 },
|
||||||
|
|
||||||
|
{ 0 }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
void InitOOJSFlasher(JSContext *context, JSObject *global)
|
||||||
|
{
|
||||||
|
sFlasherPrototype = JS_InitClass(context, global, JSEntityPrototype(), &sFlasherClass, OOJSUnconstructableConstruct, 0, sFlasherProperties, sFlasherMethods, NULL, NULL);
|
||||||
|
OOJSRegisterObjectConverter(&sFlasherClass, OOJSBasicPrivateObjectConverter);
|
||||||
|
OOJSRegisterSubclass(&sFlasherClass, JSEntityClass());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static BOOL JSFlasherGetFlasherEntity(JSContext *context, JSObject *jsobj, OOFlasherEntity **outEntity)
|
||||||
|
{
|
||||||
|
OOJS_PROFILE_ENTER
|
||||||
|
|
||||||
|
BOOL result;
|
||||||
|
Entity *entity = nil;
|
||||||
|
|
||||||
|
if (outEntity == NULL) return NO;
|
||||||
|
*outEntity = nil;
|
||||||
|
|
||||||
|
result = OOJSEntityGetEntity(context, jsobj, &entity);
|
||||||
|
if (!result) return NO;
|
||||||
|
|
||||||
|
if (![entity isKindOfClass:[OOFlasherEntity class]]) return NO;
|
||||||
|
|
||||||
|
*outEntity = (OOFlasherEntity *)entity;
|
||||||
|
return YES;
|
||||||
|
|
||||||
|
OOJS_PROFILE_EXIT
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@implementation OOFlasherEntity (OOJavaScriptExtensions)
|
||||||
|
|
||||||
|
- (void)getJSClass:(JSClass **)outClass andPrototype:(JSObject **)outPrototype
|
||||||
|
{
|
||||||
|
*outClass = &sFlasherClass;
|
||||||
|
*outPrototype = sFlasherPrototype;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
- (NSString *) oo_jsClassName
|
||||||
|
{
|
||||||
|
return @"Flasher";
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL) isVisibleToScripts
|
||||||
|
{
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
static JSBool FlasherGetProperty(JSContext *context, JSObject *this, jsid propID, jsval *value)
|
||||||
|
{
|
||||||
|
if (!JSID_IS_INT(propID)) return YES;
|
||||||
|
|
||||||
|
OOJS_NATIVE_ENTER(context)
|
||||||
|
|
||||||
|
OOFlasherEntity *entity = nil;
|
||||||
|
id result = nil;
|
||||||
|
|
||||||
|
if (!JSFlasherGetFlasherEntity(context, this, &entity)) return NO;
|
||||||
|
if (entity == nil) { *value = JSVAL_VOID; return YES; }
|
||||||
|
|
||||||
|
switch (JSID_TO_INT(propID))
|
||||||
|
{
|
||||||
|
case kFlasher_size:
|
||||||
|
return JS_NewNumberValue(context, [entity diameter], value);
|
||||||
|
|
||||||
|
default:
|
||||||
|
OOJSReportBadPropertySelector(context, this, propID, sFlasherProperties);
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
|
||||||
|
*value = OOJSValueFromNativeObject(context, result);
|
||||||
|
return YES;
|
||||||
|
|
||||||
|
OOJS_NATIVE_EXIT
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static JSBool FlasherSetProperty(JSContext *context, JSObject *this, jsid propID, JSBool strict, jsval *value)
|
||||||
|
{
|
||||||
|
if (!JSID_IS_INT(propID)) return YES;
|
||||||
|
|
||||||
|
OOJS_NATIVE_ENTER(context)
|
||||||
|
|
||||||
|
OOFlasherEntity *entity = nil;
|
||||||
|
jsdouble fValue;
|
||||||
|
|
||||||
|
if (!JSFlasherGetFlasherEntity(context, this, &entity)) return NO;
|
||||||
|
if (entity == nil) return YES;
|
||||||
|
|
||||||
|
switch (JSID_TO_INT(propID))
|
||||||
|
{
|
||||||
|
case kFlasher_size:
|
||||||
|
if (JS_ValueToNumber(context, *value, &fValue))
|
||||||
|
{
|
||||||
|
if (fValue > 0.0)
|
||||||
|
{
|
||||||
|
[entity setDiameter:fValue];
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
OOJSReportBadPropertySelector(context, this, propID, sFlasherProperties);
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
|
||||||
|
OOJSReportBadPropertyValue(context, this, propID, sFlasherProperties, *value);
|
||||||
|
return NO;
|
||||||
|
|
||||||
|
OOJS_NATIVE_EXIT
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// *** Methods ***
|
||||||
|
|
||||||
|
#define GET_THIS_FLASHER(THISENT) do { \
|
||||||
|
if (EXPECT_NOT(!JSFlasherGetFlasherEntity(context, OOJS_THIS, &THISENT))) return NO; /* Exception */ \
|
||||||
|
if (OOIsStaleEntity(THISENT)) OOJS_RETURN_VOID; \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
|
||||||
|
static JSBool FlasherRemove(JSContext *context, uintN argc, jsval *vp)
|
||||||
|
{
|
||||||
|
OOJS_NATIVE_ENTER(context)
|
||||||
|
|
||||||
|
OOFlasherEntity *thisEnt = nil;
|
||||||
|
GET_THIS_FLASHER(thisEnt);
|
||||||
|
|
||||||
|
Entity *parent = [thisEnt owner];
|
||||||
|
if ([parent isShip])
|
||||||
|
{
|
||||||
|
[(ShipEntity *)parent removeFlasher:thisEnt];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
[(OOVisualEffectEntity *)parent removeSubEntity:thisEnt];
|
||||||
|
}
|
||||||
|
|
||||||
|
OOJS_RETURN_VOID;
|
||||||
|
|
||||||
|
OOJS_NATIVE_EXIT
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -212,7 +212,9 @@ enum
|
|||||||
kShip_escortGroup, // group, ShipGroup, read-only
|
kShip_escortGroup, // group, ShipGroup, read-only
|
||||||
kShip_escorts, // deployed escorts, array of Ship, read-only
|
kShip_escorts, // deployed escorts, array of Ship, read-only
|
||||||
kShip_exhaustEmissiveColor, // exhaust emissive color, array, read/write
|
kShip_exhaustEmissiveColor, // exhaust emissive color, array, read/write
|
||||||
|
kShip_exhausts, // exhausts, array, read-only
|
||||||
kShip_extraCargo, // cargo space increase granted by large cargo bay, int, read-only
|
kShip_extraCargo, // cargo space increase granted by large cargo bay, int, read-only
|
||||||
|
kShip_flashers, // flashers, array, read-only
|
||||||
kShip_forwardWeapon, // the ship's forward weapon, equipmentType, read/write
|
kShip_forwardWeapon, // the ship's forward weapon, equipmentType, read/write
|
||||||
kShip_fuel, // fuel, float, read/write
|
kShip_fuel, // fuel, float, read/write
|
||||||
kShip_fuelChargeRate, // fuel scoop rate & charge multiplier, float, read-only
|
kShip_fuelChargeRate, // fuel scoop rate & charge multiplier, float, read-only
|
||||||
@ -349,7 +351,9 @@ static JSPropertySpec sShipProperties[] =
|
|||||||
{ "escorts", kShip_escorts, OOJS_PROP_READONLY_CB },
|
{ "escorts", kShip_escorts, OOJS_PROP_READONLY_CB },
|
||||||
{ "escortGroup", kShip_escortGroup, OOJS_PROP_READONLY_CB },
|
{ "escortGroup", kShip_escortGroup, OOJS_PROP_READONLY_CB },
|
||||||
{ "exhaustEmissiveColor", kShip_exhaustEmissiveColor, OOJS_PROP_READWRITE_CB },
|
{ "exhaustEmissiveColor", kShip_exhaustEmissiveColor, OOJS_PROP_READWRITE_CB },
|
||||||
|
{ "exhausts", kShip_exhausts, OOJS_PROP_READONLY_CB },
|
||||||
{ "extraCargo", kShip_extraCargo, OOJS_PROP_READONLY_CB },
|
{ "extraCargo", kShip_extraCargo, OOJS_PROP_READONLY_CB },
|
||||||
|
{ "flashers", kShip_flashers, OOJS_PROP_READONLY_CB },
|
||||||
{ "forwardWeapon", kShip_forwardWeapon, OOJS_PROP_READWRITE_CB },
|
{ "forwardWeapon", kShip_forwardWeapon, OOJS_PROP_READWRITE_CB },
|
||||||
{ "fuel", kShip_fuel, OOJS_PROP_READWRITE_CB },
|
{ "fuel", kShip_fuel, OOJS_PROP_READWRITE_CB },
|
||||||
{ "fuelChargeRate", kShip_fuelChargeRate, OOJS_PROP_READONLY_CB },
|
{ "fuelChargeRate", kShip_fuelChargeRate, OOJS_PROP_READONLY_CB },
|
||||||
@ -643,6 +647,14 @@ static JSBool ShipGetProperty(JSContext *context, JSObject *this, jsid propID, j
|
|||||||
case kShip_subEntities:
|
case kShip_subEntities:
|
||||||
result = [entity subEntitiesForScript];
|
result = [entity subEntitiesForScript];
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case kShip_exhausts:
|
||||||
|
result = [[entity exhaustEnumerator] allObjects];
|
||||||
|
break;
|
||||||
|
|
||||||
|
case kShip_flashers:
|
||||||
|
result = [[entity flasherEnumerator] allObjects];
|
||||||
|
break;
|
||||||
|
|
||||||
case kShip_subEntityCapacity:
|
case kShip_subEntityCapacity:
|
||||||
return JS_NewNumberValue(context, [entity maxShipSubEntities], value);
|
return JS_NewNumberValue(context, [entity maxShipSubEntities], value);
|
||||||
|
@ -49,6 +49,8 @@ MA 02110-1301, USA.
|
|||||||
#import "OOJSStation.h"
|
#import "OOJSStation.h"
|
||||||
#import "OOJSDock.h"
|
#import "OOJSDock.h"
|
||||||
#import "OOJSVisualEffect.h"
|
#import "OOJSVisualEffect.h"
|
||||||
|
#import "OOJSExhaustPlume.h"
|
||||||
|
#import "OOJSFlasher.h"
|
||||||
#import "OOJSWormhole.h"
|
#import "OOJSWormhole.h"
|
||||||
#import "OOJSWaypoint.h"
|
#import "OOJSWaypoint.h"
|
||||||
#import "OOJSPlayer.h"
|
#import "OOJSPlayer.h"
|
||||||
@ -352,6 +354,8 @@ static void ReportJSError(JSContext *context, const char *message, JSErrorReport
|
|||||||
InitOOJSStation(gOOJSMainThreadContext, _globalObject);
|
InitOOJSStation(gOOJSMainThreadContext, _globalObject);
|
||||||
InitOOJSDock(gOOJSMainThreadContext, _globalObject);
|
InitOOJSDock(gOOJSMainThreadContext, _globalObject);
|
||||||
InitOOJSVisualEffect(gOOJSMainThreadContext, _globalObject);
|
InitOOJSVisualEffect(gOOJSMainThreadContext, _globalObject);
|
||||||
|
InitOOJSExhaustPlume(gOOJSMainThreadContext, _globalObject);
|
||||||
|
InitOOJSFlasher(gOOJSMainThreadContext, _globalObject);
|
||||||
InitOOJSWormhole(gOOJSMainThreadContext, _globalObject);
|
InitOOJSWormhole(gOOJSMainThreadContext, _globalObject);
|
||||||
InitOOJSWaypoint(gOOJSMainThreadContext, _globalObject);
|
InitOOJSWaypoint(gOOJSMainThreadContext, _globalObject);
|
||||||
InitOOJSPlayer(gOOJSMainThreadContext, _globalObject);
|
InitOOJSPlayer(gOOJSMainThreadContext, _globalObject);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user