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:
95
Content.Server/Access/AccessWireAction.cs
Normal file
95
Content.Server/Access/AccessWireAction.cs
Normal file
@@ -0,0 +1,95 @@
|
||||
using Content.Server.Wires;
|
||||
using Content.Shared.Access;
|
||||
using Content.Shared.Access.Components;
|
||||
using Content.Shared.Wires;
|
||||
|
||||
namespace Content.Server.Access;
|
||||
|
||||
[DataDefinition]
|
||||
public class AccessWireAction : BaseWireAction
|
||||
{
|
||||
[DataField("color")]
|
||||
private Color _statusColor = Color.Green;
|
||||
|
||||
[DataField("name")]
|
||||
private string _text = "ACC";
|
||||
|
||||
[DataField("pulseTimeout")]
|
||||
private int _pulseTimeout = 30;
|
||||
|
||||
public override StatusLightData? GetStatusLightData(Wire wire)
|
||||
{
|
||||
StatusLightState lightState = StatusLightState.Off;
|
||||
if (IsPowered(wire.Owner)
|
||||
&& EntityManager.TryGetComponent<AccessReaderComponent>(wire.Owner, out var access))
|
||||
{
|
||||
if (access.Enabled)
|
||||
{
|
||||
lightState = StatusLightState.On;
|
||||
}
|
||||
}
|
||||
|
||||
return new StatusLightData(
|
||||
_statusColor,
|
||||
lightState,
|
||||
_text);
|
||||
}
|
||||
|
||||
public override object StatusKey { get; } = AccessWireActionKey.Status;
|
||||
|
||||
public override bool Cut(EntityUid user, Wire wire)
|
||||
{
|
||||
if (EntityManager.TryGetComponent<AccessReaderComponent>(wire.Owner, out var access))
|
||||
{
|
||||
WiresSystem.TryCancelWireAction(wire.Owner, PulseTimeoutKey.Key);
|
||||
access.Enabled = false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool Mend(EntityUid user, Wire wire)
|
||||
{
|
||||
if (EntityManager.TryGetComponent<AccessReaderComponent>(wire.Owner, out var access))
|
||||
{
|
||||
access.Enabled = true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool Pulse(EntityUid user, Wire wire)
|
||||
{
|
||||
if (EntityManager.TryGetComponent<AccessReaderComponent>(wire.Owner, out var access))
|
||||
{
|
||||
access.Enabled = false;
|
||||
WiresSystem.StartWireAction(wire.Owner, _pulseTimeout, PulseTimeoutKey.Key, new TimedWireEvent(AwaitPulseCancel, wire));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void Update(Wire wire)
|
||||
{
|
||||
if (!IsPowered(wire.Owner))
|
||||
{
|
||||
WiresSystem.TryCancelWireAction(wire.Owner, PulseTimeoutKey.Key);
|
||||
}
|
||||
}
|
||||
|
||||
private void AwaitPulseCancel(Wire wire)
|
||||
{
|
||||
if (!wire.IsCut)
|
||||
{
|
||||
if (EntityManager.TryGetComponent<AccessReaderComponent>(wire.Owner, out var access))
|
||||
{
|
||||
access.Enabled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private enum PulseTimeoutKey : byte
|
||||
{
|
||||
Key
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user