Wire action cleanup (#13496)

This commit is contained in:
Leon Friedrich
2023-01-21 12:51:02 +13:00
committed by GitHub
parent 319cf162fd
commit b20b4b11cc
21 changed files with 294 additions and 627 deletions

View File

@@ -8,19 +8,10 @@ namespace Content.Server.Power;
// Generic power wire action. Use on anything
// that requires power.
[DataDefinition]
public sealed class PowerWireAction : BaseWireAction
{
[DataField("color")]
private Color _statusColor = Color.Red;
[DataField("name")]
private string _text = "POWR";
protected override string Text
{
get => _text;
set => _text = value;
}
public override Color Color { get; set; } = Color.Red;
public override string Name { get; set; } = "wire-name-power";
[DataField("pulseTimeout")]
private int _pulseTimeout = 30;
@@ -29,35 +20,22 @@ public sealed class PowerWireAction : BaseWireAction
public override object StatusKey { get; } = PowerWireActionKey.Status;
public override StatusLightData? GetStatusLightData(Wire wire)
public override StatusLightState? GetLightState(Wire wire)
{
StatusLightState lightState = StatusLightState.Off;
if (WiresSystem.TryGetData(wire.Owner, PowerWireActionKey.MainWire, out int main)
&& main != wire.Id)
{
return null;
}
if (IsPowered(wire.Owner))
{
if (!AllWiresMended(wire.Owner)
if (!AllWiresMended(wire.Owner)
|| WiresSystem.TryGetData(wire.Owner, PowerWireActionKey.Pulsed, out bool pulsed)
&& pulsed)
{
lightState = StatusLightState.BlinkingSlow;
}
else
{
lightState = (AllWiresCut(wire.Owner))
? StatusLightState.Off
: StatusLightState.On;
}
{
return StatusLightState.BlinkingSlow;
}
return new StatusLightData(
_statusColor,
lightState,
_text);
return AllWiresCut(wire.Owner) ? StatusLightState.Off : StatusLightState.On;
}
private bool AllWiresCut(EntityUid owner)
@@ -233,29 +211,23 @@ public sealed class PowerWireAction : BaseWireAction
return true;
}
public override bool Pulse(EntityUid user, Wire wire)
public override void Pulse(EntityUid user, Wire wire)
{
base.Pulse(user, wire);
WiresSystem.TryCancelWireAction(wire.Owner, PowerWireActionKey.ElectrifiedCancel);
var electrocuted = !TrySetElectrocution(user, wire, true);
if (WiresSystem.TryGetData(wire.Owner, PowerWireActionKey.Pulsed, out bool pulsedKey)
&& pulsedKey)
{
return false;
}
if (WiresSystem.TryGetData(wire.Owner, PowerWireActionKey.Pulsed, out bool pulsedKey) && pulsedKey)
return;
WiresSystem.SetData(wire.Owner, PowerWireActionKey.Pulsed, true);
WiresSystem.StartWireAction(wire.Owner, _pulseTimeout, PowerWireActionKey.PulseCancel, new TimedWireEvent(AwaitPulseCancel, wire));
if (electrocuted)
{
return false;
}
return;
SetPower(wire.Owner, true);
return true;
}
public override void Update(Wire wire)