Wires refactor (#7699)
Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Co-authored-by: Kara <lunarautomaton6@gmail.com>
This commit is contained in:
94
Content.Server/Doors/WireActions/DoorSafetyWireAction.cs
Normal file
94
Content.Server/Doors/WireActions/DoorSafetyWireAction.cs
Normal file
@@ -0,0 +1,94 @@
|
||||
using Content.Server.Doors.Components;
|
||||
using Content.Server.Wires;
|
||||
using Content.Shared.Doors;
|
||||
using Content.Shared.Wires;
|
||||
|
||||
namespace Content.Server.Doors;
|
||||
|
||||
[DataDefinition]
|
||||
public class DoorSafetyWireAction : BaseWireAction
|
||||
{
|
||||
[DataField("color")]
|
||||
private Color _statusColor = Color.Red;
|
||||
|
||||
[DataField("name")]
|
||||
private string _text = "SAFE";
|
||||
|
||||
[DataField("timeout")]
|
||||
private int _timeout = 30;
|
||||
|
||||
public override StatusLightData? GetStatusLightData(Wire wire)
|
||||
{
|
||||
var lightState = StatusLightState.Off;
|
||||
if (IsPowered(wire.Owner)
|
||||
&& EntityManager.TryGetComponent<AirlockComponent>(wire.Owner, out var door))
|
||||
{
|
||||
lightState = door.Safety
|
||||
? StatusLightState.On
|
||||
: StatusLightState.Off;
|
||||
}
|
||||
|
||||
return new StatusLightData(
|
||||
_statusColor,
|
||||
lightState,
|
||||
_text);
|
||||
}
|
||||
|
||||
public override object StatusKey { get; } = AirlockWireStatus.SafetyIndicator;
|
||||
|
||||
public override bool Cut(EntityUid user, Wire wire)
|
||||
{
|
||||
if (EntityManager.TryGetComponent<AirlockComponent>(wire.Owner, out var door))
|
||||
{
|
||||
WiresSystem.TryCancelWireAction(wire.Owner, PulseTimeoutKey.Key);
|
||||
door.Safety = false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool Mend(EntityUid user, Wire wire)
|
||||
{
|
||||
if (EntityManager.TryGetComponent<AirlockComponent>(wire.Owner, out var door))
|
||||
{
|
||||
door.Safety = true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool Pulse(EntityUid user, Wire wire)
|
||||
{
|
||||
if (EntityManager.TryGetComponent<AirlockComponent>(wire.Owner, out var door))
|
||||
{
|
||||
door.Safety = false;
|
||||
WiresSystem.StartWireAction(wire.Owner, _timeout, PulseTimeoutKey.Key, new TimedWireEvent(AwaitSafetyTimerFinish, wire));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void Update(Wire wire)
|
||||
{
|
||||
if (!IsPowered(wire.Owner))
|
||||
{
|
||||
WiresSystem.TryCancelWireAction(wire.Owner, PulseTimeoutKey.Key);
|
||||
}
|
||||
}
|
||||
|
||||
private void AwaitSafetyTimerFinish(Wire wire)
|
||||
{
|
||||
if (!wire.IsCut)
|
||||
{
|
||||
if (EntityManager.TryGetComponent<AirlockComponent>(wire.Owner, out var door))
|
||||
{
|
||||
door.Safety = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private enum PulseTimeoutKey : byte
|
||||
{
|
||||
Key
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user