Merge pull request #366 from dybal/weapon_info

Adds weaponInfo to EquipmentInfo script object
master
phkb 2020-09-01 17:56:59 +10:00 committed by GitHub
commit 8194bd1012
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 1 deletions

View File

@ -142,6 +142,7 @@ SOFTWARE.
// weapon properties
- (BOOL) isTurretLaser;
- (BOOL) isMiningLaser;
- (NSDictionary *) weaponInfo;
- (GLfloat) weaponRange;
- (GLfloat) weaponEnergyUse;
- (GLfloat) weaponDamage;

View File

@ -630,6 +630,12 @@ static NSDictionary *sMissilesRegistry = nil;
}
- (NSDictionary *) weaponInfo
{
return _weaponInfo;
}
- (GLfloat) weaponRange
{
return [_weaponInfo oo_floatForKey:@"range" defaultValue:12500.0];

View File

@ -77,7 +77,8 @@ enum
kEquipmentInfo_requiresNonFullFuel,
kEquipmentInfo_scriptInfo, // arbitrary data for scripts, dictionary, read-only
kEquipmentInfo_scriptName,
kEquipmentInfo_techLevel
kEquipmentInfo_techLevel,
kEquipmentInfo_weaponInfo
};
@ -117,6 +118,7 @@ static JSPropertySpec sEquipmentInfoProperties[] =
{ "scriptInfo", kEquipmentInfo_scriptInfo, OOJS_PROP_READONLY_CB },
{ "scriptName", kEquipmentInfo_scriptName, OOJS_PROP_READONLY_CB },
{ "techLevel", kEquipmentInfo_techLevel, OOJS_PROP_READONLY_CB },
{ "weaponInfo", kEquipmentInfo_weaponInfo, OOJS_PROP_READONLY_CB },
{ 0 }
};
@ -390,6 +392,11 @@ static JSBool EquipmentInfoGetProperty(JSContext *context, JSObject *this, jsid
if (result == nil) result = @"";
break;
case kEquipmentInfo_weaponInfo:
result = [eqType weaponInfo];
if (result == nil) result = [NSDictionary dictionary]; // empty rather than null
break;
default:
OOJSReportBadPropertySelector(context, this, propID, sEquipmentInfoProperties);
return NO;