Skip to content

Commit

Permalink
making playership.compassTarget readwrite
Browse files Browse the repository at this point in the history
  • Loading branch information
phkb authored and AnotherCommander committed Sep 29, 2017
1 parent 16e47d9 commit 399de8c
Showing 1 changed file with 33 additions and 4 deletions.
37 changes: 33 additions & 4 deletions src/Core/Scripting/OOJSPlayerShip.m
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
kPlayerShip_aftShield, // aft shield charge level, nonnegative float, read/write
kPlayerShip_aftShieldRechargeRate, // aft shield recharge rate, positive float, read-only
kPlayerShip_compassMode, // compass mode, string, read/write
kPlayerShip_compassTarget, // object targeted by the compass, entity, read-only
kPlayerShip_compassTarget, // object targeted by the compass, entity, read/write
kPlayerShip_compassType, // basic / advanced, string, read/write
kPlayerShip_currentWeapon, // shortcut property to _aftWeapon, etc. overrides kShip generic version
kPlayerShip_crosshairs, // custom plist file defining crosshairs
Expand Down Expand Up @@ -172,7 +172,7 @@
{ "aftShield", kPlayerShip_aftShield, OOJS_PROP_READWRITE_CB },
{ "aftShieldRechargeRate", kPlayerShip_aftShieldRechargeRate, OOJS_PROP_READWRITE_CB },
{ "compassMode", kPlayerShip_compassMode, OOJS_PROP_READWRITE_CB },
{ "compassTarget", kPlayerShip_compassTarget, OOJS_PROP_READONLY_CB },
{ "compassTarget", kPlayerShip_compassTarget, OOJS_PROP_READWRITE_CB },
{ "compassType", kPlayerShip_compassType, OOJS_PROP_READWRITE_CB },
{ "currentWeapon", kPlayerShip_currentWeapon, OOJS_PROP_READWRITE_CB },
{ "crosshairs", kPlayerShip_crosshairs, OOJS_PROP_READWRITE_CB },
Expand Down Expand Up @@ -616,7 +616,8 @@ static JSBool PlayerShipSetProperty(JSContext *context, JSObject *this, jsid pro
OOGalacticHyperspaceBehaviour ghBehaviour;
Vector vValue;
OOColor *colorForScript = nil;

Entity *eValue = nil;

switch (JSID_TO_INT(propID))
{
case kPlayerShip_fuelLeakRate:
Expand Down Expand Up @@ -678,7 +679,35 @@ static JSBool PlayerShipSetProperty(JSContext *context, JSObject *this, jsid pro
return YES;
}
break;


case kPlayerShip_compassTarget:
// can't change compass target in basic mode
if (![player hasEquipmentItemProviding:@"EQ_ADVANCED_COMPASS"])
{
OOJSReportError(context, @"Compass target cannot be set with a basic compass.");
return NO;
}
// make sure we have a valid entity
if (!JSVAL_IS_NULL(*value) && JSValueToEntity(context, *value, &eValue))
{
Entity *current = [player compassTarget];
[player setNextCompassMode];
[player validateCompassTarget];
// cycle the targets until we either get back to the start (entity not found) or we find the one we're looking for
while ([player compassTarget] != current && [player compassTarget] != eValue)
{
[player setNextCompassMode];
[player validateCompassTarget];
}
return [player compassTarget] != current;
}
else
{
OOJSReportError(context, @"Invalid compass target entity provided.");
return NO;
}
break;

case kPlayerShip_galacticHyperspaceBehaviour:
ghBehaviour = OOGalacticHyperspaceBehaviourFromJSValue(context, *value);
if (ghBehaviour != GALACTIC_HYPERSPACE_BEHAVIOUR_UNKNOWN)
Expand Down

0 comments on commit 399de8c

Please sign in to comment.