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

@@ -7,85 +7,46 @@ using Content.Shared.Wires;
namespace Content.Server.Doors;
[DataDefinition]
public sealed class DoorTimingWireAction : BaseWireAction
public sealed class DoorTimingWireAction : ComponentWireAction<AirlockComponent>
{
[DataField("color")]
private Color _statusColor = Color.Orange;
[DataField("name")]
private string _text = "TIMR";
protected override string Text
{
get => _text;
set => _text = value;
}
public override Color Color { get; set; } = Color.Orange;
public override string Name { get; set; } = "wire-name-door-timer";
[DataField("timeout")]
private int _timeout = 30;
public override StatusLightData? GetStatusLightData(Wire wire)
public override StatusLightState? GetLightState(Wire wire, AirlockComponent comp)
{
var lightState = StatusLightState.Off;
if (IsPowered(wire.Owner)
&& EntityManager.TryGetComponent<AirlockComponent>(wire.Owner, out var door))
switch (comp.AutoCloseDelayModifier)
{
switch (door.AutoCloseDelayModifier)
{
case 0.01f:
lightState = StatusLightState.Off;
break;
case <= 0.5f:
lightState = StatusLightState.BlinkingSlow;
break;
default:
lightState = StatusLightState.On;
break;
}
case 0.01f:
return StatusLightState.Off;
case <= 0.5f:
return StatusLightState.BlinkingSlow;
default:
return StatusLightState.On;
}
return new StatusLightData(
_statusColor,
lightState,
_text);
}
public override object StatusKey { get; } = AirlockWireStatus.TimingIndicator;
public override bool Cut(EntityUid user, Wire wire)
public override bool Cut(EntityUid user, Wire wire, AirlockComponent door)
{
base.Cut(user, wire);
if (EntityManager.TryGetComponent<AirlockComponent>(wire.Owner, out var door))
{
WiresSystem.TryCancelWireAction(wire.Owner, PulseTimeoutKey.Key);
EntityManager.System<SharedAirlockSystem>().SetAutoCloseDelayModifier(door, 0.01f);
}
WiresSystem.TryCancelWireAction(wire.Owner, PulseTimeoutKey.Key);
EntityManager.System<SharedAirlockSystem>().SetAutoCloseDelayModifier(door, 0.01f);
return true;
}
public override bool Mend(EntityUid user, Wire wire)
public override bool Mend(EntityUid user, Wire wire, AirlockComponent door)
{
base.Mend(user, wire);
if (EntityManager.TryGetComponent<AirlockComponent>(wire.Owner, out var door))
{
EntityManager.System<SharedAirlockSystem>().SetAutoCloseDelayModifier(door, 1f);
}
EntityManager.System<SharedAirlockSystem>().SetAutoCloseDelayModifier(door, 1f);
return true;
}
public override bool Pulse(EntityUid user, Wire wire)
public override void Pulse(EntityUid user, Wire wire, AirlockComponent door)
{
base.Pulse(user, wire);
if (EntityManager.TryGetComponent<AirlockComponent>(wire.Owner, out var door))
{
EntityManager.System<SharedAirlockSystem>().SetAutoCloseDelayModifier(door, 0.5f);
WiresSystem.StartWireAction(wire.Owner, _timeout, PulseTimeoutKey.Key, new TimedWireEvent(AwaitTimingTimerFinish, wire));
}
return true;
EntityManager.System<SharedAirlockSystem>().SetAutoCloseDelayModifier(door, 0.5f);
WiresSystem.StartWireAction(wire.Owner, _timeout, PulseTimeoutKey.Key, new TimedWireEvent(AwaitTimingTimerFinish, wire));
}
public override void Update(Wire wire)