Wire action cleanup (#13496)
This commit is contained in:
@@ -7,36 +7,19 @@ using Content.Shared.Wires;
|
||||
|
||||
namespace Content.Server.Atmos.Monitor;
|
||||
|
||||
[DataDefinition]
|
||||
public sealed class AirAlarmPanicWire : BaseWireAction
|
||||
public sealed class AirAlarmPanicWire : ComponentWireAction<AirAlarmComponent>
|
||||
{
|
||||
private string _text = "PANC";
|
||||
protected override string Text
|
||||
{
|
||||
get => _text;
|
||||
set => _text = value;
|
||||
}
|
||||
private Color _color = Color.Red;
|
||||
public override string Name { get; set; } = "wire-name-air-alarm-panic";
|
||||
public override Color Color { get; set; } = 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
|
||||
public override StatusLightState? GetLightState(Wire wire, AirAlarmComponent comp)
|
||||
=> comp.CurrentMode == AirAlarmMode.Panic
|
||||
? StatusLightState.On
|
||||
: StatusLightState.Off;
|
||||
}
|
||||
|
||||
return new StatusLightData(
|
||||
_color,
|
||||
lightState,
|
||||
_text);
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -45,9 +28,8 @@ public sealed class AirAlarmPanicWire : BaseWireAction
|
||||
_airAlarmSystem = EntityManager.System<AirAlarmSystem>();
|
||||
}
|
||||
|
||||
public override bool Cut(EntityUid user, Wire wire)
|
||||
public override bool Cut(EntityUid user, Wire wire, AirAlarmComponent comp)
|
||||
{
|
||||
base.Cut(user, wire);
|
||||
if (EntityManager.TryGetComponent<DeviceNetworkComponent>(wire.Owner, out var devNet))
|
||||
{
|
||||
_airAlarmSystem.SetMode(wire.Owner, devNet.Address, AirAlarmMode.Panic, false);
|
||||
@@ -56,28 +38,22 @@ public sealed class AirAlarmPanicWire : BaseWireAction
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool Mend(EntityUid user, Wire wire)
|
||||
public override bool Mend(EntityUid user, Wire wire, AirAlarmComponent alarm)
|
||||
{
|
||||
base.Mend(user, 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, false, alarm);
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool Pulse(EntityUid user, Wire wire)
|
||||
public override void Pulse(EntityUid user, Wire wire, AirAlarmComponent comp)
|
||||
{
|
||||
base.Pulse(user, wire);
|
||||
if (EntityManager.TryGetComponent<DeviceNetworkComponent>(wire.Owner, out var devNet))
|
||||
{
|
||||
_airAlarmSystem.SetMode(wire.Owner, devNet.Address, AirAlarmMode.Panic, false);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,46 +6,30 @@ using Content.Shared.Wires;
|
||||
|
||||
namespace Content.Server.Atmos.Monitor;
|
||||
|
||||
[DataDefinition]
|
||||
public sealed class AtmosMonitorDeviceNetWire : BaseWireAction
|
||||
public sealed class AtmosMonitorDeviceNetWire : ComponentWireAction<AtmosAlarmableComponent>
|
||||
{
|
||||
// whether or not this wire will send out an alarm upon
|
||||
// being pulsed
|
||||
[DataField("alarmOnPulse")]
|
||||
private bool _alarmOnPulse = false;
|
||||
|
||||
private string _text = "NETW";
|
||||
protected override string Text
|
||||
{
|
||||
get => _text;
|
||||
set => _text = value;
|
||||
}
|
||||
private Color _color = Color.Orange;
|
||||
public override string Name { get; set; } = "wire-name-device-net";
|
||||
public override Color Color { get; set; } = Color.Orange;
|
||||
|
||||
private AtmosAlarmableSystem _atmosAlarmableSystem = default!;
|
||||
|
||||
public override object StatusKey { get; } = AtmosMonitorAlarmWireActionKeys.Network;
|
||||
|
||||
public override StatusLightData? GetStatusLightData(Wire wire)
|
||||
public override StatusLightState? GetLightState(Wire wire, AtmosAlarmableComponent comp)
|
||||
{
|
||||
var lightState = StatusLightState.Off;
|
||||
|
||||
if (IsPowered(wire.Owner) && EntityManager.TryGetComponent<AtmosMonitorComponent>(wire.Owner, out var monitor))
|
||||
if (!_atmosAlarmableSystem.TryGetHighestAlert(wire.Owner, out var alarm, comp))
|
||||
{
|
||||
if (!_atmosAlarmableSystem.TryGetHighestAlert(wire.Owner, out var alarm))
|
||||
{
|
||||
alarm = AtmosAlarmType.Normal;
|
||||
}
|
||||
|
||||
lightState = alarm == AtmosAlarmType.Danger
|
||||
? StatusLightState.BlinkingFast
|
||||
: StatusLightState.On;
|
||||
alarm = AtmosAlarmType.Normal;
|
||||
}
|
||||
|
||||
return new StatusLightData(
|
||||
_color,
|
||||
lightState,
|
||||
_text);
|
||||
return alarm == AtmosAlarmType.Danger
|
||||
? StatusLightState.BlinkingFast
|
||||
: StatusLightState.On;
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
@@ -55,36 +39,21 @@ public sealed class AtmosMonitorDeviceNetWire : BaseWireAction
|
||||
_atmosAlarmableSystem = EntityManager.System<AtmosAlarmableSystem>();
|
||||
}
|
||||
|
||||
public override bool Cut(EntityUid user, Wire wire)
|
||||
public override bool Cut(EntityUid user, Wire wire, AtmosAlarmableComponent comp)
|
||||
{
|
||||
base.Cut(user, wire);
|
||||
if (EntityManager.TryGetComponent<AtmosAlarmableComponent>(wire.Owner, out var monitor))
|
||||
{
|
||||
monitor.IgnoreAlarms = true;
|
||||
}
|
||||
|
||||
comp.IgnoreAlarms = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool Mend(EntityUid user, Wire wire)
|
||||
public override bool Mend(EntityUid user, Wire wire, AtmosAlarmableComponent comp)
|
||||
{
|
||||
base.Mend(user, wire);
|
||||
if (EntityManager.TryGetComponent<AtmosAlarmableComponent>(wire.Owner, out var monitor))
|
||||
{
|
||||
monitor.IgnoreAlarms = false;
|
||||
}
|
||||
|
||||
comp.IgnoreAlarms = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool Pulse(EntityUid user, Wire wire)
|
||||
public override void Pulse(EntityUid user, Wire wire, AtmosAlarmableComponent comp)
|
||||
{
|
||||
base.Pulse(user, wire);
|
||||
if (_alarmOnPulse)
|
||||
{
|
||||
_atmosAlarmableSystem.ForceAlert(wire.Owner, AtmosAlarmType.Danger);
|
||||
}
|
||||
|
||||
return true;
|
||||
_atmosAlarmableSystem.ForceAlert(wire.Owner, AtmosAlarmType.Danger, comp);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user