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:
@@ -0,0 +1,9 @@
|
||||
namespace Content.Server.Doors;
|
||||
|
||||
public enum AirlockWireIdentifier : byte
|
||||
{
|
||||
Bolt,
|
||||
BoltLight,
|
||||
Timing,
|
||||
Safety,
|
||||
}
|
||||
65
Content.Server/Doors/WireActions/DoorBoltLightWireAction.cs
Normal file
65
Content.Server/Doors/WireActions/DoorBoltLightWireAction.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using Content.Server.Doors.Components;
|
||||
using Content.Server.Wires;
|
||||
using Content.Shared.Doors;
|
||||
using Content.Shared.Doors.Components;
|
||||
using Content.Shared.Wires;
|
||||
|
||||
namespace Content.Server.Doors;
|
||||
|
||||
[DataDefinition]
|
||||
public class DoorBoltLightWireAction : BaseWireAction
|
||||
{
|
||||
[DataField("color")]
|
||||
private Color _statusColor = Color.Lime;
|
||||
|
||||
[DataField("name")]
|
||||
private string _text = "BLIT";
|
||||
|
||||
public override StatusLightData? GetStatusLightData(Wire wire)
|
||||
{
|
||||
StatusLightState lightState = StatusLightState.Off;
|
||||
if (IsPowered(wire.Owner) && EntityManager.TryGetComponent<AirlockComponent>(wire.Owner, out var door))
|
||||
{
|
||||
lightState = door.BoltLightsEnabled
|
||||
? StatusLightState.On
|
||||
: StatusLightState.Off;
|
||||
}
|
||||
|
||||
return new StatusLightData(
|
||||
_statusColor,
|
||||
lightState,
|
||||
_text);
|
||||
}
|
||||
|
||||
public override object StatusKey { get; } = AirlockWireStatus.BoltLightIndicator;
|
||||
|
||||
public override bool Cut(EntityUid user, Wire wire)
|
||||
{
|
||||
if (EntityManager.TryGetComponent<AirlockComponent>(wire.Owner, out var door))
|
||||
{
|
||||
door.BoltLightsVisible = false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool Mend(EntityUid user, Wire wire)
|
||||
{
|
||||
if (EntityManager.TryGetComponent<AirlockComponent>(wire.Owner, out var door))
|
||||
{
|
||||
door.BoltLightsVisible = true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool Pulse(EntityUid user, Wire wire)
|
||||
{
|
||||
if (EntityManager.TryGetComponent<AirlockComponent>(wire.Owner, out var door))
|
||||
{
|
||||
door.BoltLightsVisible = !door.BoltLightsEnabled;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
66
Content.Server/Doors/WireActions/DoorBoltWireAction.cs
Normal file
66
Content.Server/Doors/WireActions/DoorBoltWireAction.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
using Content.Server.Doors.Components;
|
||||
using Content.Server.Wires;
|
||||
using Content.Shared.Doors;
|
||||
using Content.Shared.Wires;
|
||||
|
||||
namespace Content.Server.Doors;
|
||||
|
||||
[DataDefinition]
|
||||
public class DoorBoltWireAction : BaseWireAction
|
||||
{
|
||||
[DataField("color")]
|
||||
private Color _statusColor = Color.Red;
|
||||
|
||||
[DataField("name")]
|
||||
private string _text = "BOLT";
|
||||
|
||||
public override StatusLightData? GetStatusLightData(Wire wire)
|
||||
{
|
||||
StatusLightState lightState = StatusLightState.Off;
|
||||
if (IsPowered(wire.Owner)
|
||||
&& EntityManager.TryGetComponent<AirlockComponent>(wire.Owner, out var door))
|
||||
{
|
||||
if (door.BoltsDown)
|
||||
{
|
||||
lightState = StatusLightState.On;
|
||||
}
|
||||
}
|
||||
|
||||
return new StatusLightData(
|
||||
_statusColor,
|
||||
lightState,
|
||||
_text);
|
||||
}
|
||||
|
||||
public override object StatusKey { get; } = AirlockWireStatus.BoltIndicator;
|
||||
|
||||
public override bool Cut(EntityUid user, Wire wire)
|
||||
{
|
||||
if (EntityManager.TryGetComponent<AirlockComponent>(wire.Owner, out var door))
|
||||
{
|
||||
if (!door.BoltsDown)
|
||||
{
|
||||
door.SetBoltsWithAudio(true);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// does nothing
|
||||
public override bool Mend(EntityUid user, Wire wire)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool Pulse(EntityUid user, Wire wire)
|
||||
{
|
||||
if (IsPowered(wire.Owner)
|
||||
&& EntityManager.TryGetComponent<AirlockComponent>(wire.Owner, out var door))
|
||||
{
|
||||
door.SetBoltsWithAudio(!door.BoltsDown);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
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
|
||||
}
|
||||
}
|
||||
105
Content.Server/Doors/WireActions/DoorTimingWireAction.cs
Normal file
105
Content.Server/Doors/WireActions/DoorTimingWireAction.cs
Normal file
@@ -0,0 +1,105 @@
|
||||
using Content.Server.Doors.Components;
|
||||
using Content.Server.Wires;
|
||||
using Content.Shared.Doors;
|
||||
using Content.Shared.Wires;
|
||||
|
||||
namespace Content.Server.Doors;
|
||||
|
||||
[DataDefinition]
|
||||
public class DoorTimingWireAction : BaseWireAction
|
||||
{
|
||||
[DataField("color")]
|
||||
private Color _statusColor = Color.Orange;
|
||||
|
||||
[DataField("name")]
|
||||
private string _text = "TIMR";
|
||||
|
||||
[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))
|
||||
{
|
||||
switch (door.AutoCloseDelayModifier)
|
||||
{
|
||||
case 0f:
|
||||
lightState = StatusLightState.Off;
|
||||
break;
|
||||
case <= 0.5f:
|
||||
lightState = StatusLightState.BlinkingSlow;
|
||||
break;
|
||||
default:
|
||||
lightState = StatusLightState.On;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return new StatusLightData(
|
||||
_statusColor,
|
||||
lightState,
|
||||
_text);
|
||||
}
|
||||
|
||||
public override object StatusKey { get; } = AirlockWireStatus.TimingIndicator;
|
||||
|
||||
public override bool Cut(EntityUid user, Wire wire)
|
||||
{
|
||||
if (EntityManager.TryGetComponent<AirlockComponent>(wire.Owner, out var door))
|
||||
{
|
||||
WiresSystem.TryCancelWireAction(wire.Owner, PulseTimeoutKey.Key);
|
||||
door.AutoCloseDelayModifier = 0f;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool Mend(EntityUid user, Wire wire)
|
||||
{
|
||||
if (EntityManager.TryGetComponent<AirlockComponent>(wire.Owner, out var door))
|
||||
{
|
||||
door.AutoCloseDelayModifier = 1f;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool Pulse(EntityUid user, Wire wire)
|
||||
{
|
||||
if (EntityManager.TryGetComponent<AirlockComponent>(wire.Owner, out var door))
|
||||
{
|
||||
door.AutoCloseDelayModifier = 0.5f;
|
||||
WiresSystem.StartWireAction(wire.Owner, _timeout, PulseTimeoutKey.Key, new TimedWireEvent(AwaitTimingTimerFinish, wire));
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void Update(Wire wire)
|
||||
{
|
||||
if (!IsPowered(wire.Owner))
|
||||
{
|
||||
WiresSystem.TryCancelWireAction(wire.Owner, PulseTimeoutKey.Key);
|
||||
}
|
||||
}
|
||||
|
||||
// timing timer??? ???
|
||||
private void AwaitTimingTimerFinish(Wire wire)
|
||||
{
|
||||
if (!wire.IsCut)
|
||||
{
|
||||
if (EntityManager.TryGetComponent<AirlockComponent>(wire.Owner, out var door))
|
||||
{
|
||||
door.AutoCloseDelayModifier = 1f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private enum PulseTimeoutKey : byte
|
||||
{
|
||||
Key
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user