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,75 @@
|
||||
using Content.Server.Atmos.Monitor.Components;
|
||||
using Content.Server.Atmos.Monitor.Systems;
|
||||
using Content.Server.DeviceNetwork.Components;
|
||||
using Content.Server.Wires;
|
||||
using Content.Shared.Atmos.Monitor.Components;
|
||||
using Content.Shared.Wires;
|
||||
|
||||
namespace Content.Server.Atmos.Monitor;
|
||||
|
||||
[DataDefinition]
|
||||
public sealed class AirAlarmPanicWire : BaseWireAction
|
||||
{
|
||||
private string _text = "PANC";
|
||||
private Color _color = Color.Red;
|
||||
|
||||
private AirAlarmSystem _airAlarmSystem = default!;
|
||||
|
||||
public override object StatusKey { get; } = AirAlarmWireStatus.Panic;
|
||||
|
||||
public override StatusLightData? GetStatusLightData(Wire wire)
|
||||
{
|
||||
var lightState = StatusLightState.Off;
|
||||
if (IsPowered(wire.Owner) && EntityManager.TryGetComponent<AirAlarmComponent>(wire.Owner, out var alarm))
|
||||
{
|
||||
lightState = alarm.CurrentMode == AirAlarmMode.Panic
|
||||
? StatusLightState.On
|
||||
: StatusLightState.Off;
|
||||
}
|
||||
|
||||
return new StatusLightData(
|
||||
_color,
|
||||
lightState,
|
||||
_text);
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
_airAlarmSystem = EntitySystem.Get<AirAlarmSystem>();
|
||||
}
|
||||
|
||||
public override bool Cut(EntityUid user, Wire wire)
|
||||
{
|
||||
if (EntityManager.TryGetComponent<DeviceNetworkComponent>(wire.Owner, out var devNet))
|
||||
{
|
||||
_airAlarmSystem.SetMode(wire.Owner, devNet.Address, AirAlarmMode.Panic, true, false);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool Mend(EntityUid user, Wire wire)
|
||||
{
|
||||
if (EntityManager.TryGetComponent<DeviceNetworkComponent>(wire.Owner, out var devNet)
|
||||
&& EntityManager.TryGetComponent<AirAlarmComponent>(wire.Owner, out var alarm)
|
||||
&& alarm.CurrentMode == AirAlarmMode.Panic)
|
||||
{
|
||||
_airAlarmSystem.SetMode(wire.Owner, devNet.Address, AirAlarmMode.Filtering, true, false, alarm);
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool Pulse(EntityUid user, Wire wire)
|
||||
{
|
||||
if (EntityManager.TryGetComponent<DeviceNetworkComponent>(wire.Owner, out var devNet))
|
||||
{
|
||||
_airAlarmSystem.SetMode(wire.Owner, devNet.Address, AirAlarmMode.Panic, true, false);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
using Content.Server.Atmos.Monitor.Components;
|
||||
using Content.Server.Atmos.Monitor.Systems;
|
||||
using Content.Server.Wires;
|
||||
using Content.Shared.Atmos.Monitor;
|
||||
using Content.Shared.Wires;
|
||||
|
||||
namespace Content.Server.Atmos.Monitor;
|
||||
|
||||
[DataDefinition]
|
||||
public sealed class AtmosMonitorDeviceNetWire : BaseWireAction
|
||||
{
|
||||
// whether or not this wire will send out an alarm upon
|
||||
// being pulsed
|
||||
[DataField("alarmOnPulse")]
|
||||
private bool _alarmOnPulse = false;
|
||||
|
||||
private string _text = "NETW";
|
||||
private Color _color = Color.Orange;
|
||||
|
||||
private AtmosMonitorSystem _atmosMonitorSystem = default!;
|
||||
|
||||
public override object StatusKey { get; } = AtmosMonitorAlarmWireActionKeys.Network;
|
||||
|
||||
public override StatusLightData? GetStatusLightData(Wire wire)
|
||||
{
|
||||
var lightState = StatusLightState.Off;
|
||||
|
||||
if (IsPowered(wire.Owner) && EntityManager.TryGetComponent<AtmosMonitorComponent>(wire.Owner, out var monitor))
|
||||
{
|
||||
lightState = monitor.HighestAlarmInNetwork == AtmosMonitorAlarmType.Danger
|
||||
? StatusLightState.BlinkingFast
|
||||
: StatusLightState.On;
|
||||
}
|
||||
|
||||
return new StatusLightData(
|
||||
_color,
|
||||
lightState,
|
||||
_text);
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
_atmosMonitorSystem = EntitySystem.Get<AtmosMonitorSystem>();
|
||||
}
|
||||
|
||||
public override bool Cut(EntityUid user, Wire wire)
|
||||
{
|
||||
if (EntityManager.TryGetComponent<AtmosMonitorComponent>(wire.Owner, out var monitor))
|
||||
{
|
||||
monitor.NetEnabled = false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool Mend(EntityUid user, Wire wire)
|
||||
{
|
||||
if (EntityManager.TryGetComponent<AtmosMonitorComponent>(wire.Owner, out var monitor))
|
||||
{
|
||||
monitor.NetEnabled = true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool Pulse(EntityUid user, Wire wire)
|
||||
{
|
||||
if (_alarmOnPulse)
|
||||
{
|
||||
_atmosMonitorSystem.Alert(wire.Owner, AtmosMonitorAlarmType.Danger);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user