number of things, fixing warnings, AtmosAlarmType instead of AtmosMonitorAlarmType

This commit is contained in:
vulppine
2022-08-29 07:37:26 -07:00
parent cb5ffe0f3d
commit e0bf77490d
24 changed files with 177 additions and 148 deletions

View File

@@ -9,7 +9,7 @@ public sealed class AtmosAlarmableVisualsComponent : Component
public string LayerMap { get; } = string.Empty; public string LayerMap { get; } = string.Empty;
[DataField("alarmStates")] [DataField("alarmStates")]
public readonly Dictionary<AtmosMonitorAlarmType, string> AlarmStates = new(); public readonly Dictionary<AtmosAlarmType, string> AlarmStates = new();
[DataField("hideOnDepowered")] [DataField("hideOnDepowered")]
public readonly List<string>? HideOnDepowered; public readonly List<string>? HideOnDepowered;

View File

@@ -14,27 +14,39 @@ public sealed class AtmosAlarmableVisualsSystem : VisualizerSystem<AtmosAlarmabl
{ {
protected override void OnAppearanceChange(EntityUid uid, AtmosAlarmableVisualsComponent component, ref AppearanceChangeEvent args) protected override void OnAppearanceChange(EntityUid uid, AtmosAlarmableVisualsComponent component, ref AppearanceChangeEvent args)
{ {
if (args.Sprite == null || !args.Sprite.LayerMapTryGet(component.LayerMap, out int layer)) if (args.Sprite == null || !args.Sprite.LayerMapTryGet(component.LayerMap, out var layer))
return; return;
if (args.AppearanceData.TryGetValue(PowerDeviceVisuals.Powered, out var poweredObject) if (!args.AppearanceData.TryGetValue(PowerDeviceVisuals.Powered, out var poweredObject) ||
&& poweredObject is bool powered) poweredObject is not bool powered)
{ {
if (component.HideOnDepowered != null) return;
foreach (var visLayer in component.HideOnDepowered) }
if (args.Sprite.LayerMapTryGet(visLayer, out int powerVisibilityLayer))
args.Sprite.LayerSetVisible(powerVisibilityLayer, powered);
if (component.SetOnDepowered != null && !powered) if (component.HideOnDepowered != null)
foreach (var (setLayer, powerState) in component.SetOnDepowered) {
if (args.Sprite.LayerMapTryGet(setLayer, out int setStateLayer)) foreach (var visLayer in component.HideOnDepowered)
args.Sprite.LayerSetState(setStateLayer, new RSI.StateId(powerState)); {
if (args.Sprite.LayerMapTryGet(visLayer, out int powerVisibilityLayer))
args.Sprite.LayerSetVisible(powerVisibilityLayer, powered);
}
}
if (args.AppearanceData.TryGetValue(AtmosMonitorVisuals.AlarmType, out var alarmTypeObject) if (component.SetOnDepowered != null && !powered)
&& alarmTypeObject is AtmosMonitorAlarmType alarmType {
&& powered foreach (var (setLayer, powerState) in component.SetOnDepowered)
&& component.AlarmStates.TryGetValue(alarmType, out var state)) {
args.Sprite.LayerSetState(layer, new RSI.StateId(state)); if (args.Sprite.LayerMapTryGet(setLayer, out int setStateLayer))
args.Sprite.LayerSetState(setStateLayer, new RSI.StateId(powerState));
}
}
if (args.AppearanceData.TryGetValue(AtmosMonitorVisuals.AlarmType, out var alarmTypeObject)
&& alarmTypeObject is AtmosAlarmType alarmType
&& powered
&& component.AlarmStates.TryGetValue(alarmType, out var state))
{
args.Sprite.LayerSetState(layer, new RSI.StateId(state));
} }
} }
} }

View File

@@ -13,7 +13,8 @@ public sealed class AirAlarmBoundUserInterface : BoundUserInterface
private AirAlarmWindow? _window; private AirAlarmWindow? _window;
public AirAlarmBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey) public AirAlarmBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey)
{} {
}
protected override void Open() protected override void Open()
{ {
@@ -21,7 +22,10 @@ public sealed class AirAlarmBoundUserInterface : BoundUserInterface
_window = new AirAlarmWindow(); _window = new AirAlarmWindow();
if (State != null) UpdateState(State); if (State != null)
{
UpdateState(State);
}
_window.OpenCentered(); _window.OpenCentered();

View File

@@ -50,7 +50,9 @@ public sealed partial class AirAlarmWindow : DefaultWindow
RobustXamlLoader.Load(this); RobustXamlLoader.Load(this);
foreach (var mode in Enum.GetValues<AirAlarmMode>()) foreach (var mode in Enum.GetValues<AirAlarmMode>())
{
_modes.AddItem($"{mode}", (int) mode); _modes.AddItem($"{mode}", (int) mode);
}
_modes.OnItemSelected += args => _modes.OnItemSelected += args =>
{ {

View File

@@ -29,7 +29,7 @@ public sealed partial class PumpControl : BoxContainer
{ {
RobustXamlLoader.Load(this); RobustXamlLoader.Load(this);
this.Name = address; Name = address;
_data = data; _data = data;
_address = address; _address = address;
@@ -60,7 +60,9 @@ public sealed partial class PumpControl : BoxContainer
_externalBound.IsValid += value => value >= 0; _externalBound.IsValid += value => value >= 0;
foreach (var value in Enum.GetValues<VentPumpDirection>()) foreach (var value in Enum.GetValues<VentPumpDirection>())
{
_pumpDirection.AddItem(Loc.GetString($"{value}"), (int) value); _pumpDirection.AddItem(Loc.GetString($"{value}"), (int) value);
}
_pumpDirection.SelectId((int) _data.PumpDirection); _pumpDirection.SelectId((int) _data.PumpDirection);
_pumpDirection.OnItemSelected += args => _pumpDirection.OnItemSelected += args =>
@@ -71,7 +73,9 @@ public sealed partial class PumpControl : BoxContainer
}; };
foreach (var value in Enum.GetValues<VentPressureBound>()) foreach (var value in Enum.GetValues<VentPressureBound>())
{
_pressureCheck.AddItem(Loc.GetString($"{value}"), (int) value); _pressureCheck.AddItem(Loc.GetString($"{value}"), (int) value);
}
_pressureCheck.SelectId((int) _data.PressureChecks); _pressureCheck.SelectId((int) _data.PressureChecks);
_pressureCheck.OnItemSelected += args => _pressureCheck.OnItemSelected += args =>

View File

@@ -34,7 +34,7 @@ public sealed partial class ScrubberControl : BoxContainer
{ {
RobustXamlLoader.Load(this); RobustXamlLoader.Load(this);
this.Name = address; Name = address;
_data = data; _data = data;
_address = address; _address = address;
@@ -64,7 +64,9 @@ public sealed partial class ScrubberControl : BoxContainer
_volumeRate.IsValid += value => value >= 0; _volumeRate.IsValid += value => value >= 0;
foreach (var value in Enum.GetValues<ScrubberPumpDirection>()) foreach (var value in Enum.GetValues<ScrubberPumpDirection>())
{
_pumpDirection.AddItem(Loc.GetString($"{value}"), (int) value); _pumpDirection.AddItem(Loc.GetString($"{value}"), (int) value);
}
_pumpDirection.SelectId((int) _data.PumpDirection); _pumpDirection.SelectId((int) _data.PumpDirection);
_pumpDirection.OnItemSelected += args => _pumpDirection.OnItemSelected += args =>
@@ -116,7 +118,9 @@ public sealed partial class ScrubberControl : BoxContainer
var intersect = _data.FilterGases.Intersect(data.FilterGases); var intersect = _data.FilterGases.Intersect(data.FilterGases);
foreach (var value in Enum.GetValues<Gas>()) foreach (var value in Enum.GetValues<Gas>())
{
if (!intersect.Contains(value)) if (!intersect.Contains(value))
_gasControls[value].Pressed = false; _gasControls[value].Pressed = false;
}
} }
} }

View File

@@ -208,18 +208,18 @@ public sealed partial class ThresholdControl : BoxContainer
_modifier = modifier > 0 ? modifier : 1; _modifier = modifier > 0 ? modifier : 1;
_value = value; _value = value;
this.HorizontalExpand = true; HorizontalExpand = true;
this.Orientation = LayoutOrientation.Vertical; Orientation = LayoutOrientation.Vertical;
this.AddChild(new Label { Text = Loc.GetString($"air-alarm-ui-thresholds-{name}") }); AddChild(new Label { Text = Loc.GetString($"air-alarm-ui-thresholds-{name}") });
_bound = new FloatSpinBox(.01f, 2); _bound = new FloatSpinBox(.01f, 2);
this.AddChild(_bound); AddChild(_bound);
_boundEnabled = new CheckBox _boundEnabled = new CheckBox
{ {
Text = Loc.GetString("Enabled") Text = Loc.GetString("Enabled")
}; };
this.AddChild(_boundEnabled); AddChild(_boundEnabled);
_bound.Value = ModifiedValue ?? 0; _bound.Value = ModifiedValue ?? 0;
_lastValue = _value ?? 0; _lastValue = _value ?? 0;
@@ -289,7 +289,9 @@ public sealed partial class ThresholdControl : BoxContainer
OnValidBoundChanged!.Invoke(); OnValidBoundChanged!.Invoke();
} }
private bool ValidateThreshold(float value) => (_value != null) && (value >= 0); private bool ValidateThreshold(float value)
{
return _value != null && value >= 0;
}
} }
} }

View File

@@ -29,9 +29,9 @@ namespace Content.Server.Atmos.Monitor.Components;
public sealed class AtmosAlarmableComponent : Component public sealed class AtmosAlarmableComponent : Component
{ {
[ViewVariables] [ViewVariables]
public readonly Dictionary<string, AtmosMonitorAlarmType> NetworkAlarmStates = new(); public readonly Dictionary<string, AtmosAlarmType> NetworkAlarmStates = new();
[ViewVariables] public AtmosMonitorAlarmType LastAlarmState = AtmosMonitorAlarmType.Normal; [ViewVariables] public AtmosAlarmType LastAlarmState = AtmosAlarmType.Normal;
[ViewVariables] public bool IgnoreAlarms { get; set; } = false; [ViewVariables] public bool IgnoreAlarms { get; set; } = false;

View File

@@ -57,7 +57,7 @@ public sealed class AtmosMonitorComponent : Component
// Stores the last alarm state of this alarm. // Stores the last alarm state of this alarm.
[ViewVariables] [ViewVariables]
public AtmosMonitorAlarmType LastAlarmState = AtmosMonitorAlarmType.Normal; public AtmosAlarmType LastAlarmState = AtmosAlarmType.Normal;
[ViewVariables] public HashSet<AtmosMonitorThresholdType> TrippedThresholds = new(); [ViewVariables] public HashSet<AtmosMonitorThresholdType> TrippedThresholds = new();

View File

@@ -62,14 +62,17 @@ public sealed class AirAlarmModeFactory
// still not a fan since ReplaceMode must have an allocation // still not a fan since ReplaceMode must have an allocation
// but it's whatever // but it's whatever
public static IAirAlarmMode? ModeToExecutor(AirAlarmMode mode) => mode switch public static IAirAlarmMode? ModeToExecutor(AirAlarmMode mode)
{ {
AirAlarmMode.Filtering => _filterMode, return mode switch
AirAlarmMode.Fill => _fillMode, {
AirAlarmMode.Panic => _panicMode, AirAlarmMode.Filtering => _filterMode,
AirAlarmMode.None => _noneMode, AirAlarmMode.Fill => _fillMode,
_ => null AirAlarmMode.Panic => _panicMode,
}; AirAlarmMode.None => _noneMode,
_ => null
};
}
} }
// like a tiny little EntitySystem // like a tiny little EntitySystem

View File

@@ -81,7 +81,7 @@ public sealed class AirAlarmSystem : EntitySystem
/// on this network. /// on this network.
/// </summary> /// </summary>
/// <param name="uid"></param> /// <param name="uid"></param>
public void SyncRegisterAllDevices(EntityUid uid) private void SyncRegisterAllDevices(EntityUid uid)
{ {
_atmosDevNetSystem.Register(uid, null); _atmosDevNetSystem.Register(uid, null);
_atmosDevNetSystem.Sync(uid, null); _atmosDevNetSystem.Sync(uid, null);
@@ -129,7 +129,7 @@ public sealed class AirAlarmSystem : EntitySystem
/// Sync this air alarm's mode with the rest of the network. /// Sync this air alarm's mode with the rest of the network.
/// </summary> /// </summary>
/// <param name="mode">The mode to sync with the rest of the network.</param> /// <param name="mode">The mode to sync with the rest of the network.</param>
public void SyncMode(EntityUid uid, AirAlarmMode mode) private void SyncMode(EntityUid uid, AirAlarmMode mode)
{ {
if (EntityManager.TryGetComponent(uid, out AtmosMonitorComponent? monitor) if (EntityManager.TryGetComponent(uid, out AtmosMonitorComponent? monitor)
&& !monitor.NetEnabled) && !monitor.NetEnabled)
@@ -231,20 +231,22 @@ public sealed class AirAlarmSystem : EntitySystem
private void OnResyncAll(EntityUid uid, AirAlarmComponent component, AirAlarmResyncAllDevicesMessage args) private void OnResyncAll(EntityUid uid, AirAlarmComponent component, AirAlarmResyncAllDevicesMessage args)
{ {
if (AccessCheck(uid, args.Session.AttachedEntity, component)) if (!AccessCheck(uid, args.Session.AttachedEntity, component))
{ {
component.KnownDevices.Clear(); return;
component.VentData.Clear();
component.ScrubberData.Clear();
component.SensorData.Clear();
SyncRegisterAllDevices(uid);
} }
component.KnownDevices.Clear();
component.VentData.Clear();
component.ScrubberData.Clear();
component.SensorData.Clear();
SyncRegisterAllDevices(uid);
} }
private void OnUpdateAlarmMode(EntityUid uid, AirAlarmComponent component, AirAlarmUpdateAlarmModeMessage args) private void OnUpdateAlarmMode(EntityUid uid, AirAlarmComponent component, AirAlarmUpdateAlarmModeMessage args)
{ {
string addr = string.Empty; var addr = string.Empty;
if (EntityManager.TryGetComponent(uid, out DeviceNetworkComponent? netConn)) addr = netConn.Address; if (EntityManager.TryGetComponent(uid, out DeviceNetworkComponent? netConn)) addr = netConn.Address;
if (AccessCheck(uid, args.Session.AttachedEntity, component)) if (AccessCheck(uid, args.Session.AttachedEntity, component))
SetMode(uid, addr, args.Mode, true, false); SetMode(uid, addr, args.Mode, true, false);
@@ -292,15 +294,15 @@ public sealed class AirAlarmSystem : EntitySystem
SyncAllDevices(uid); SyncAllDevices(uid);
} }
string addr = string.Empty; var addr = string.Empty;
if (EntityManager.TryGetComponent(uid, out DeviceNetworkComponent? netConn)) addr = netConn.Address; if (EntityManager.TryGetComponent(uid, out DeviceNetworkComponent? netConn)) addr = netConn.Address;
if (args.AlarmType == AtmosMonitorAlarmType.Danger) if (args.AlarmType == AtmosAlarmType.Danger)
{ {
SetMode(uid, addr, AirAlarmMode.None, true, false); SetMode(uid, addr, AirAlarmMode.None, true, false);
} }
else if (args.AlarmType == AtmosMonitorAlarmType.Normal) else if (args.AlarmType == AtmosAlarmType.Normal)
{ {
SetMode(uid, addr, AirAlarmMode.Filtering, true, false); SetMode(uid, addr, AirAlarmMode.Filtering, true, false);
} }
@@ -324,7 +326,7 @@ public sealed class AirAlarmSystem : EntitySystem
if (!Resolve(uid, ref controller)) return; if (!Resolve(uid, ref controller)) return;
controller.CurrentMode = mode; controller.CurrentMode = mode;
// setting it to UI only maans we don't have // setting it to UI only means we don't have
// to deal with the issue of not-single-owner // to deal with the issue of not-single-owner
// alarm mode executors // alarm mode executors
if (!uiOnly) if (!uiOnly)
@@ -344,12 +346,14 @@ public sealed class AirAlarmSystem : EntitySystem
} }
// only one air alarm in a network can use an air alarm mode // only one air alarm in a network can use an air alarm mode
// that updates, so even if it's a ui-only change, // that updates, so even if it's a ui-only change,
// we have to invalidte the last mode's updater and // we have to invalidate the last mode's updater and
// remove it because otherwise it'll execute a now // remove it because otherwise it'll execute a now
// invalid mode // invalid mode
else if (controller.CurrentModeUpdater != null else if (controller.CurrentModeUpdater != null
&& controller.CurrentModeUpdater.NetOwner != origin) && controller.CurrentModeUpdater.NetOwner != origin)
{
controller.CurrentModeUpdater = null; controller.CurrentModeUpdater = null;
}
UpdateUI(uid, controller); UpdateUI(uid, controller);
@@ -364,9 +368,12 @@ public sealed class AirAlarmSystem : EntitySystem
/// </summary> /// </summary>
/// <param name="address">The address to send the new data to.</param> /// <param name="address">The address to send the new data to.</param>
/// <param name="devData">The device data to be sent.</param> /// <param name="devData">The device data to be sent.</param>
public void SetDeviceData(EntityUid uid, string address, IAtmosDeviceData devData, AirAlarmComponent? controller = null) private void SetDeviceData(EntityUid uid, string address, IAtmosDeviceData devData, AirAlarmComponent? controller = null)
{ {
if (!Resolve(uid, ref controller)) return; if (!Resolve(uid, ref controller))
{
return;
}
devData.Dirty = true; devData.Dirty = true;
SetData(uid, address, devData); SetData(uid, address, devData);
@@ -421,32 +428,35 @@ public sealed class AirAlarmSystem : EntitySystem
#region UI #region UI
// List of active user interfaces. // List of active user interfaces.
private HashSet<EntityUid> _activeUserInterfaces = new(); private readonly HashSet<EntityUid> _activeUserInterfaces = new();
/// <summary> /// <summary>
/// Adds an active interface to be updated. /// Adds an active interface to be updated.
/// </summary> /// </summary>
public void AddActiveInterface(EntityUid uid) => private void AddActiveInterface(EntityUid uid)
{
_activeUserInterfaces.Add(uid); _activeUserInterfaces.Add(uid);
}
/// <summary> /// <summary>
/// Removes an active interface from the system update loop. /// Removes an active interface from the system update loop.
/// </summary> /// </summary>
public void RemoveActiveInterface(EntityUid uid) => private void RemoveActiveInterface(EntityUid uid)
{
_activeUserInterfaces.Remove(uid); _activeUserInterfaces.Remove(uid);
}
/// <summary> /// <summary>
/// Force closes all interfaces currently open related to this air alarm. /// Force closes all interfaces currently open related to this air alarm.
/// </summary> /// </summary>
public void ForceCloseAllInterfaces(EntityUid uid) private void ForceCloseAllInterfaces(EntityUid uid)
{ {
_uiSystem.TryCloseAll(uid, SharedAirAlarmInterfaceKey.Key); _uiSystem.TryCloseAll(uid, SharedAirAlarmInterfaceKey.Key);
} }
public void OnAtmosUpdate(EntityUid uid, AirAlarmComponent alarm, AtmosDeviceUpdateEvent args) private void OnAtmosUpdate(EntityUid uid, AirAlarmComponent alarm, AtmosDeviceUpdateEvent args)
{ {
if (alarm.CurrentModeUpdater != null) alarm.CurrentModeUpdater?.Update(uid);
alarm.CurrentModeUpdater.Update(uid);
} }
public float CalculatePressureAverage(AirAlarmComponent alarm) public float CalculatePressureAverage(AirAlarmComponent alarm)
@@ -506,7 +516,7 @@ public sealed class AirAlarmSystem : EntitySystem
if (!_atmosAlarmable.TryGetHighestAlert(uid, out var highestAlarm)) if (!_atmosAlarmable.TryGetHighestAlert(uid, out var highestAlarm))
{ {
highestAlarm = AtmosMonitorAlarmType.Normal; highestAlarm = AtmosAlarmType.Normal;
} }
_uiSystem.TrySetUiState( _uiSystem.TrySetUiState(
@@ -515,13 +525,13 @@ public sealed class AirAlarmSystem : EntitySystem
new AirAlarmUIState(devNet.Address, deviceCount, pressure, temperature, dataToSend, alarm.CurrentMode, alarm.CurrentTab, highestAlarm.Value)); new AirAlarmUIState(devNet.Address, deviceCount, pressure, temperature, dataToSend, alarm.CurrentMode, alarm.CurrentTab, highestAlarm.Value));
} }
private const float _delay = 8f; private const float Delay = 8f;
private float _timer = 0f; private float _timer;
public override void Update(float frameTime) public override void Update(float frameTime)
{ {
_timer += frameTime; _timer += frameTime;
if (_timer >= _delay) if (_timer >= Delay)
{ {
_timer = 0f; _timer = 0f;
foreach (var uid in _activeUserInterfaces) foreach (var uid in _activeUserInterfaces)

View File

@@ -55,7 +55,7 @@ public sealed class AtmosAlarmableSystem : EntitySystem
{ {
TryUpdateAlert( TryUpdateAlert(
uid, uid,
TryGetHighestAlert(uid, out var alarm) ? alarm.Value : AtmosMonitorAlarmType.Normal, TryGetHighestAlert(uid, out var alarm) ? alarm.Value : AtmosAlarmType.Normal,
component, component,
false); false);
} }
@@ -86,7 +86,7 @@ public sealed class AtmosAlarmableSystem : EntitySystem
case AlertCmd: case AlertCmd:
// Set the alert state, and then cache it so we can calculate // Set the alert state, and then cache it so we can calculate
// the maximum alarm state at all times. // the maximum alarm state at all times.
if (!args.Data.TryGetValue(DeviceNetworkConstants.CmdSetState, out AtmosMonitorAlarmType state)) if (!args.Data.TryGetValue(DeviceNetworkConstants.CmdSetState, out AtmosAlarmType state))
{ {
break; break;
} }
@@ -111,12 +111,12 @@ public sealed class AtmosAlarmableSystem : EntitySystem
// it may mean that the threshold we need to look at has // it may mean that the threshold we need to look at has
// been removed from the threshold types passed: // been removed from the threshold types passed:
// basically, we need to reset this state to normal here. // basically, we need to reset this state to normal here.
component.NetworkAlarmStates[args.SenderAddress] = isValid ? state : AtmosMonitorAlarmType.Normal; component.NetworkAlarmStates[args.SenderAddress] = isValid ? state : AtmosAlarmType.Normal;
} }
if (!TryGetHighestAlert(uid, out var netMax, component)) if (!TryGetHighestAlert(uid, out var netMax, component))
{ {
netMax = AtmosMonitorAlarmType.Normal; netMax = AtmosAlarmType.Normal;
} }
TryUpdateAlert(uid, netMax.Value, component); TryUpdateAlert(uid, netMax.Value, component);
@@ -127,7 +127,7 @@ public sealed class AtmosAlarmableSystem : EntitySystem
break; break;
case SyncAlerts: case SyncAlerts:
if (!args.Data.TryGetValue(SyncAlerts, if (!args.Data.TryGetValue(SyncAlerts,
out IReadOnlyDictionary<string, AtmosMonitorAlarmType>? alarms)) out IReadOnlyDictionary<string, AtmosAlarmType>? alarms))
{ {
break; break;
} }
@@ -149,7 +149,7 @@ public sealed class AtmosAlarmableSystem : EntitySystem
} }
} }
private void TryUpdateAlert(EntityUid uid, AtmosMonitorAlarmType type, AtmosAlarmableComponent alarmable, bool sync = true) private void TryUpdateAlert(EntityUid uid, AtmosAlarmType type, AtmosAlarmableComponent alarmable, bool sync = true)
{ {
if (alarmable.LastAlarmState == type) if (alarmable.LastAlarmState == type)
{ {
@@ -191,7 +191,7 @@ public sealed class AtmosAlarmableSystem : EntitySystem
/// <param name="uid"></param> /// <param name="uid"></param>
/// <param name="alarmType"></param> /// <param name="alarmType"></param>
/// <param name="alarmable"></param> /// <param name="alarmable"></param>
public void ForceAlert(EntityUid uid, AtmosMonitorAlarmType alarmType, public void ForceAlert(EntityUid uid, AtmosAlarmType alarmType,
AtmosAlarmableComponent? alarmable = null, DeviceNetworkComponent? devNet = null, TagComponent? tags = null) AtmosAlarmableComponent? alarmable = null, DeviceNetworkComponent? devNet = null, TagComponent? tags = null)
{ {
if (!Resolve(uid, ref alarmable, ref devNet, ref tags)) if (!Resolve(uid, ref alarmable, ref devNet, ref tags))
@@ -233,7 +233,7 @@ public sealed class AtmosAlarmableSystem : EntitySystem
return; return;
} }
TryUpdateAlert(uid, AtmosMonitorAlarmType.Normal, alarmable, false); TryUpdateAlert(uid, AtmosAlarmType.Normal, alarmable, false);
alarmable.NetworkAlarmStates.Clear(); alarmable.NetworkAlarmStates.Clear();
} }
@@ -263,7 +263,7 @@ public sealed class AtmosAlarmableSystem : EntitySystem
/// <param name="alarm"></param> /// <param name="alarm"></param>
/// <param name="alarmable"></param> /// <param name="alarmable"></param>
/// <returns></returns> /// <returns></returns>
public bool TryGetHighestAlert(EntityUid uid, [NotNullWhen(true)] out AtmosMonitorAlarmType? alarm, public bool TryGetHighestAlert(EntityUid uid, [NotNullWhen(true)] out AtmosAlarmType? alarm,
AtmosAlarmableComponent? alarmable = null) AtmosAlarmableComponent? alarmable = null)
{ {
alarm = null; alarm = null;
@@ -281,15 +281,15 @@ public sealed class AtmosAlarmableSystem : EntitySystem
return alarm != null; return alarm != null;
} }
private void PlayAlertSound(EntityUid uid, AtmosMonitorAlarmType alarm, AtmosAlarmableComponent alarmable) private void PlayAlertSound(EntityUid uid, AtmosAlarmType alarm, AtmosAlarmableComponent alarmable)
{ {
if (alarm == AtmosMonitorAlarmType.Danger) if (alarm == AtmosAlarmType.Danger)
{ {
_audioSystem.PlayPvs(alarmable.AlarmSound, uid, AudioParams.Default.WithVolume(alarmable.AlarmVolume)); _audioSystem.PlayPvs(alarmable.AlarmSound, uid, AudioParams.Default.WithVolume(alarmable.AlarmVolume));
} }
} }
private void UpdateAppearance(EntityUid uid, AtmosMonitorAlarmType alarm) private void UpdateAppearance(EntityUid uid, AtmosAlarmType alarm)
{ {
_appearance.SetData(uid, AtmosMonitorVisuals.AlarmType, alarm); _appearance.SetData(uid, AtmosMonitorVisuals.AlarmType, alarm);
} }
@@ -297,9 +297,9 @@ public sealed class AtmosAlarmableSystem : EntitySystem
public sealed class AtmosAlarmEvent : EntityEventArgs public sealed class AtmosAlarmEvent : EntityEventArgs
{ {
public AtmosMonitorAlarmType AlarmType { get; } public AtmosAlarmType AlarmType { get; }
public AtmosAlarmEvent(AtmosMonitorAlarmType netMax) public AtmosAlarmEvent(AtmosAlarmType netMax)
{ {
AlarmType = netMax; AlarmType = netMax;
} }

View File

@@ -62,8 +62,10 @@ public sealed class AtmosMonitorSystem : EntitySystem
{ {
component.GasThresholds = new(); component.GasThresholds = new();
foreach (var (gas, id) in component.GasThresholdIds) foreach (var (gas, id) in component.GasThresholdIds)
{
if (_prototypeManager.TryIndex<AtmosAlarmThreshold>(id, out var gasThreshold)) if (_prototypeManager.TryIndex<AtmosAlarmThreshold>(id, out var gasThreshold))
component.GasThresholds.Add(gas, new(gasThreshold)); component.GasThresholds.Add(gas, new(gasThreshold));
}
} }
} }
@@ -73,7 +75,6 @@ public sealed class AtmosMonitorSystem : EntitySystem
&& TryComp<AtmosDeviceComponent>(uid, out var atmosDeviceComponent)) && TryComp<AtmosDeviceComponent>(uid, out var atmosDeviceComponent))
{ {
_atmosDeviceSystem.LeaveAtmosphere(atmosDeviceComponent); _atmosDeviceSystem.LeaveAtmosphere(atmosDeviceComponent);
return;
} }
} }
@@ -174,10 +175,10 @@ public sealed class AtmosMonitorSystem : EntitySystem
// //
// somebody else can reset it :sunglasses: // somebody else can reset it :sunglasses:
if (component.MonitorFire if (component.MonitorFire
&& component.LastAlarmState != AtmosMonitorAlarmType.Danger) && component.LastAlarmState != AtmosAlarmType.Danger)
{ {
component.TrippedThresholds.Add(AtmosMonitorThresholdType.Temperature); component.TrippedThresholds.Add(AtmosMonitorThresholdType.Temperature);
Alert(uid, AtmosMonitorAlarmType.Danger, null, component); // technically??? Alert(uid, AtmosAlarmType.Danger, null, component); // technically???
} }
// only monitor state elevation so that stuff gets alarmed quicker during a fire, // only monitor state elevation so that stuff gets alarmed quicker during a fire,
@@ -188,7 +189,7 @@ public sealed class AtmosMonitorSystem : EntitySystem
&& temperatureState > component.LastAlarmState) && temperatureState > component.LastAlarmState)
{ {
component.TrippedThresholds.Add(AtmosMonitorThresholdType.Temperature); component.TrippedThresholds.Add(AtmosMonitorThresholdType.Temperature);
Alert(uid, AtmosMonitorAlarmType.Danger, null, component); Alert(uid, AtmosAlarmType.Danger, null, component);
} }
} }
@@ -227,7 +228,7 @@ public sealed class AtmosMonitorSystem : EntitySystem
if (!Resolve(uid, ref monitor)) return; if (!Resolve(uid, ref monitor)) return;
AtmosMonitorAlarmType state = AtmosMonitorAlarmType.Normal; var state = AtmosAlarmType.Normal;
HashSet<AtmosMonitorThresholdType> alarmTypes = new(monitor.TrippedThresholds); HashSet<AtmosMonitorThresholdType> alarmTypes = new(monitor.TrippedThresholds);
if (monitor.TemperatureThreshold != null if (monitor.TemperatureThreshold != null
@@ -238,7 +239,7 @@ public sealed class AtmosMonitorSystem : EntitySystem
state = temperatureState; state = temperatureState;
alarmTypes.Add(AtmosMonitorThresholdType.Temperature); alarmTypes.Add(AtmosMonitorThresholdType.Temperature);
} }
else if (temperatureState == AtmosMonitorAlarmType.Normal) else if (temperatureState == AtmosAlarmType.Normal)
{ {
alarmTypes.Remove(AtmosMonitorThresholdType.Temperature); alarmTypes.Remove(AtmosMonitorThresholdType.Temperature);
} }
@@ -253,7 +254,7 @@ public sealed class AtmosMonitorSystem : EntitySystem
state = pressureState; state = pressureState;
alarmTypes.Add(AtmosMonitorThresholdType.Pressure); alarmTypes.Add(AtmosMonitorThresholdType.Pressure);
} }
else if (pressureState == AtmosMonitorAlarmType.Normal) else if (pressureState == AtmosAlarmType.Normal)
{ {
alarmTypes.Remove(AtmosMonitorThresholdType.Pressure); alarmTypes.Remove(AtmosMonitorThresholdType.Pressure);
} }
@@ -296,7 +297,7 @@ public sealed class AtmosMonitorSystem : EntitySystem
/// </summary> /// </summary>
/// <param name="state">The alarm state to set this monitor to.</param> /// <param name="state">The alarm state to set this monitor to.</param>
/// <param name="alarms">The alarms that caused this alarm state.</param> /// <param name="alarms">The alarms that caused this alarm state.</param>
public void Alert(EntityUid uid, AtmosMonitorAlarmType state, HashSet<AtmosMonitorThresholdType>? alarms = null, AtmosMonitorComponent? monitor = null) public void Alert(EntityUid uid, AtmosAlarmType state, HashSet<AtmosMonitorThresholdType>? alarms = null, AtmosMonitorComponent? monitor = null)
{ {
if (!Resolve(uid, ref monitor)) return; if (!Resolve(uid, ref monitor)) return;
@@ -313,7 +314,7 @@ public sealed class AtmosMonitorSystem : EntitySystem
/// </summary> /// </summary>
private void Reset(EntityUid uid) private void Reset(EntityUid uid)
{ {
Alert(uid, AtmosMonitorAlarmType.Normal); Alert(uid, AtmosAlarmType.Normal);
} }
/// <summary> /// <summary>

View File

@@ -39,12 +39,12 @@ public sealed class FireAlarmSystem : EntitySystem
{ {
if (!_atmosAlarmable.TryGetHighestAlert(uid, out var alarm)) if (!_atmosAlarmable.TryGetHighestAlert(uid, out var alarm))
{ {
alarm = AtmosMonitorAlarmType.Normal; alarm = AtmosAlarmType.Normal;
} }
if (alarm == AtmosMonitorAlarmType.Normal) if (alarm == AtmosAlarmType.Normal)
{ {
_atmosAlarmable.ForceAlert(uid, AtmosMonitorAlarmType.Danger); _atmosAlarmable.ForceAlert(uid, AtmosAlarmType.Danger);
} }
else else
{ {
@@ -58,7 +58,7 @@ public sealed class FireAlarmSystem : EntitySystem
if (TryComp<AtmosAlarmableComponent>(uid, out var alarmable)) if (TryComp<AtmosAlarmableComponent>(uid, out var alarmable))
{ {
// Remove the atmos alarmable component permanently from this device. // Remove the atmos alarmable component permanently from this device.
_atmosAlarmable.ForceAlert(uid, AtmosMonitorAlarmType.Emagged, alarmable); _atmosAlarmable.ForceAlert(uid, AtmosAlarmType.Emagged, alarmable);
RemCompDeferred<AtmosAlarmableComponent>(uid); RemCompDeferred<AtmosAlarmableComponent>(uid);
} }
} }

View File

@@ -37,7 +37,7 @@ public sealed class AirAlarmPanicWire : BaseWireAction
{ {
base.Initialize(); base.Initialize();
_airAlarmSystem = EntitySystem.Get<AirAlarmSystem>(); _airAlarmSystem = EntityManager.System<AirAlarmSystem>();
} }
public override bool Cut(EntityUid user, Wire wire) public override bool Cut(EntityUid user, Wire wire)

View File

@@ -29,10 +29,10 @@ public sealed class AtmosMonitorDeviceNetWire : BaseWireAction
{ {
if (!_atmosAlarmableSystem.TryGetHighestAlert(wire.Owner, out var alarm)) if (!_atmosAlarmableSystem.TryGetHighestAlert(wire.Owner, out var alarm))
{ {
alarm = AtmosMonitorAlarmType.Normal; alarm = AtmosAlarmType.Normal;
} }
lightState = alarm == AtmosMonitorAlarmType.Danger lightState = alarm == AtmosAlarmType.Danger
? StatusLightState.BlinkingFast ? StatusLightState.BlinkingFast
: StatusLightState.On; : StatusLightState.On;
} }
@@ -47,14 +47,14 @@ public sealed class AtmosMonitorDeviceNetWire : BaseWireAction
{ {
base.Initialize(); base.Initialize();
_atmosAlarmableSystem = EntitySystem.Get<AtmosAlarmableSystem>(); _atmosAlarmableSystem = EntityManager.System<AtmosAlarmableSystem>();
} }
public override bool Cut(EntityUid user, Wire wire) public override bool Cut(EntityUid user, Wire wire)
{ {
if (EntityManager.TryGetComponent<AtmosMonitorComponent>(wire.Owner, out var monitor)) if (EntityManager.TryGetComponent<AtmosAlarmableComponent>(wire.Owner, out var monitor))
{ {
monitor.NetEnabled = false; monitor.IgnoreAlarms = true;
} }
return true; return true;
@@ -62,9 +62,9 @@ public sealed class AtmosMonitorDeviceNetWire : BaseWireAction
public override bool Mend(EntityUid user, Wire wire) public override bool Mend(EntityUid user, Wire wire)
{ {
if (EntityManager.TryGetComponent<AtmosMonitorComponent>(wire.Owner, out var monitor)) if (EntityManager.TryGetComponent<AtmosAlarmableComponent>(wire.Owner, out var monitor))
{ {
monitor.NetEnabled = true; monitor.IgnoreAlarms = false;
} }
return true; return true;
@@ -74,7 +74,7 @@ public sealed class AtmosMonitorDeviceNetWire : BaseWireAction
{ {
if (_alarmOnPulse) if (_alarmOnPulse)
{ {
_atmosAlarmableSystem.ForceAlert(wire.Owner, AtmosMonitorAlarmType.Danger); _atmosAlarmableSystem.ForceAlert(wire.Owner, AtmosAlarmType.Danger);
} }
return true; return true;

View File

@@ -160,11 +160,11 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
private void OnAtmosAlarm(EntityUid uid, GasVentPumpComponent component, AtmosAlarmEvent args) private void OnAtmosAlarm(EntityUid uid, GasVentPumpComponent component, AtmosAlarmEvent args)
{ {
if (args.AlarmType == AtmosMonitorAlarmType.Danger) if (args.AlarmType == AtmosAlarmType.Danger)
{ {
component.Enabled = false; component.Enabled = false;
} }
else if (args.AlarmType == AtmosMonitorAlarmType.Normal) else if (args.AlarmType == AtmosAlarmType.Normal)
{ {
component.Enabled = true; component.Enabled = true;
} }

View File

@@ -126,11 +126,11 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
private void OnAtmosAlarm(EntityUid uid, GasVentScrubberComponent component, AtmosAlarmEvent args) private void OnAtmosAlarm(EntityUid uid, GasVentScrubberComponent component, AtmosAlarmEvent args)
{ {
if (args.AlarmType == AtmosMonitorAlarmType.Danger) if (args.AlarmType == AtmosAlarmType.Danger)
{ {
component.Enabled = false; component.Enabled = false;
} }
else if (args.AlarmType == AtmosMonitorAlarmType.Normal) else if (args.AlarmType == AtmosAlarmType.Normal)
{ {
component.Enabled = true; component.Enabled = true;
} }

View File

@@ -83,7 +83,7 @@ namespace Content.Server.Doors.Systems
// Make firelocks autoclose, but only if the last alarm type it // Make firelocks autoclose, but only if the last alarm type it
// remembers was a danger. This is to prevent people from // remembers was a danger. This is to prevent people from
// flooding hallways with endless bad air/fire. // flooding hallways with endless bad air/fire.
if (_atmosAlarmable.TryGetHighestAlert(uid, out var alarm) && alarm != AtmosMonitorAlarmType.Danger || alarm == null) if (_atmosAlarmable.TryGetHighestAlert(uid, out var alarm) && alarm != AtmosAlarmType.Danger || alarm == null)
args.Cancel(); args.Cancel();
} }
@@ -91,12 +91,12 @@ namespace Content.Server.Doors.Systems
{ {
if (!TryComp<DoorComponent>(uid, out var doorComponent)) return; if (!TryComp<DoorComponent>(uid, out var doorComponent)) return;
if (args.AlarmType == AtmosMonitorAlarmType.Normal) if (args.AlarmType == AtmosAlarmType.Normal)
{ {
if (doorComponent.State == DoorState.Closed) if (doorComponent.State == DoorState.Closed)
_doorSystem.TryOpen(uid); _doorSystem.TryOpen(uid);
} }
else if (args.AlarmType == AtmosMonitorAlarmType.Danger) else if (args.AlarmType == AtmosAlarmType.Danger)
{ {
component.EmergencyPressureStop(); component.EmergencyPressureStop();
} }

View File

@@ -9,11 +9,11 @@ namespace Content.Shared.Atmos.Monitor;
[Serializable, NetSerializable] [Serializable, NetSerializable]
public sealed class AtmosAlarmThreshold : IPrototype, ISerializationHooks public sealed class AtmosAlarmThreshold : IPrototype, ISerializationHooks
{ {
[IdDataFieldAttribute] [IdDataField]
public string ID { get; } = default!; public string ID { get; } = default!;
[ViewVariables] [ViewVariables]
[DataField("ignore")] [DataField("ignore")]
public bool Ignore = false; public bool Ignore;
// zero bounds are not allowed - just // zero bounds are not allowed - just
// set the bound to null if you want // set the bound to null if you want
@@ -41,19 +41,14 @@ public sealed class AtmosAlarmThreshold : IPrototype, ISerializationHooks
public float? LowerWarningPercentage { get; private set; } public float? LowerWarningPercentage { get; private set; }
[ViewVariables] [ViewVariables]
public float? UpperWarningBound public float? UpperWarningBound => CalculateWarningBound(AtmosMonitorThresholdBound.Upper);
{
get => CalculateWarningBound(AtmosMonitorThresholdBound.Upper);
}
[ViewVariables] [ViewVariables]
public float? LowerWarningBound public float? LowerWarningBound => CalculateWarningBound(AtmosMonitorThresholdBound.Lower);
{
get => CalculateWarningBound(AtmosMonitorThresholdBound.Lower);
}
public AtmosAlarmThreshold() public AtmosAlarmThreshold()
{} {
}
public AtmosAlarmThreshold(AtmosAlarmThreshold other) public AtmosAlarmThreshold(AtmosAlarmThreshold other)
{ {
@@ -80,19 +75,22 @@ public sealed class AtmosAlarmThreshold : IPrototype, ISerializationHooks
} }
// utility function to check a threshold against some calculated value // utility function to check a threshold against some calculated value
public bool CheckThreshold(float value, out AtmosMonitorAlarmType state) public bool CheckThreshold(float value, out AtmosAlarmType state)
{ {
state = AtmosMonitorAlarmType.Normal; state = AtmosAlarmType.Normal;
if (Ignore) return false; if (Ignore)
{
return false;
}
if (value >= UpperBound || value <= LowerBound) if (value >= UpperBound || value <= LowerBound)
{ {
state = AtmosMonitorAlarmType.Danger; state = AtmosAlarmType.Danger;
return true; return true;
} }
if (value >= UpperWarningBound || value <= LowerWarningBound) if (value >= UpperWarningBound || value <= LowerWarningBound)
{ {
state = AtmosMonitorAlarmType.Warning; state = AtmosAlarmType.Warning;
return true; return true;
} }
@@ -117,7 +115,7 @@ public sealed class AtmosAlarmThreshold : IPrototype, ISerializationHooks
return true; return true;
} }
float value = (float) input; var value = (float) input;
if (value <= 0f || float.IsNaN(value)) if (value <= 0f || float.IsNaN(value))
return false; return false;
@@ -141,7 +139,7 @@ public sealed class AtmosAlarmThreshold : IPrototype, ISerializationHooks
break; break;
} }
bool isValid = true; var isValid = true;
if (targetValue != null) if (targetValue != null)
{ {
var result = targetValue.Value.target.CompareTo(value); var result = targetValue.Value.target.CompareTo(value);
@@ -191,8 +189,8 @@ public sealed class AtmosAlarmThreshold : IPrototype, ISerializationHooks
if (UpperBound == null) if (UpperBound == null)
return false; return false;
float upperWarning = (float) (input / UpperBound); var upperWarning = (float) (input / UpperBound);
float upperTestValue = (upperWarning * (float) UpperBound); var upperTestValue = upperWarning * (float) UpperBound;
if (upperWarning > 1f if (upperWarning > 1f
|| upperTestValue < LowerWarningBound || upperTestValue < LowerWarningBound
@@ -206,8 +204,8 @@ public sealed class AtmosAlarmThreshold : IPrototype, ISerializationHooks
if (LowerBound == null) if (LowerBound == null)
return false; return false;
float lowerWarning = (float) (input / LowerBound); var lowerWarning = (float) (input / LowerBound);
float testValue = (lowerWarning * (float) LowerBound); var testValue = lowerWarning * (float) LowerBound;
if (lowerWarning < 1f if (lowerWarning < 1f
|| testValue > UpperWarningBound || testValue > UpperWarningBound
@@ -265,6 +263,5 @@ public enum AtmosMonitorThresholdType
[Serializable, NetSerializable] [Serializable, NetSerializable]
public enum AtmosMonitorVisuals : byte public enum AtmosMonitorVisuals : byte
{ {
Offset,
AlarmType, AlarmType,
} }

View File

@@ -3,10 +3,10 @@ using Robust.Shared.Serialization;
namespace Content.Shared.Atmos.Monitor; namespace Content.Shared.Atmos.Monitor;
[Serializable, NetSerializable] [Serializable, NetSerializable]
public enum AtmosMonitorAlarmType : sbyte public enum AtmosAlarmType : sbyte
{ {
Normal = 0, Normal = 0,
Warning = 1, Warning = 1,
Danger = 2, // 1 << 1 is the exact same thing and we're not really doing **bitmasking** are we? Danger = 2, // 1 << 1 is the exact same thing and we're not really doing **bitmasking** are we?
Emagged = 3, Emagged = 3,
} }

View File

@@ -6,7 +6,7 @@ namespace Content.Shared.Atmos.Monitor;
[Serializable, NetSerializable] [Serializable, NetSerializable]
public sealed class AtmosSensorData : IAtmosDeviceData public sealed class AtmosSensorData : IAtmosDeviceData
{ {
public AtmosSensorData(float pressure, float temperature, float totalMoles, AtmosMonitorAlarmType alarmState, Dictionary<Gas, float> gases, AtmosAlarmThreshold pressureThreshold, AtmosAlarmThreshold temperatureThreshold, Dictionary<Gas, AtmosAlarmThreshold> gasThresholds) public AtmosSensorData(float pressure, float temperature, float totalMoles, AtmosAlarmType alarmState, Dictionary<Gas, float> gases, AtmosAlarmThreshold pressureThreshold, AtmosAlarmThreshold temperatureThreshold, Dictionary<Gas, AtmosAlarmThreshold> gasThresholds)
{ {
Pressure = pressure; Pressure = pressure;
Temperature = temperature; Temperature = temperature;
@@ -39,7 +39,7 @@ public sealed class AtmosSensorData : IAtmosDeviceData
/// <summary> /// <summary>
/// Current alarm state of this sensor. Does not reflect the highest alarm state on the network. /// Current alarm state of this sensor. Does not reflect the highest alarm state on the network.
/// </summary> /// </summary>
public AtmosMonitorAlarmType AlarmState { get; } public AtmosAlarmType AlarmState { get; }
/// <summary> /// <summary>
/// Current number of gases on this sensor. /// Current number of gases on this sensor.
/// </summary> /// </summary>

View File

@@ -36,7 +36,7 @@ public interface IAtmosDeviceData
[Serializable, NetSerializable] [Serializable, NetSerializable]
public sealed class AirAlarmUIState : BoundUserInterfaceState public sealed class AirAlarmUIState : BoundUserInterfaceState
{ {
public AirAlarmUIState(string address, int deviceCount, float pressureAverage, float temperatureAverage, Dictionary<string, IAtmosDeviceData> deviceData, AirAlarmMode mode, AirAlarmTab tab, AtmosMonitorAlarmType alarmType) public AirAlarmUIState(string address, int deviceCount, float pressureAverage, float temperatureAverage, Dictionary<string, IAtmosDeviceData> deviceData, AirAlarmMode mode, AirAlarmTab tab, AtmosAlarmType alarmType)
{ {
Address = address; Address = address;
DeviceCount = deviceCount; DeviceCount = deviceCount;
@@ -61,7 +61,7 @@ public sealed class AirAlarmUIState : BoundUserInterfaceState
public Dictionary<string, IAtmosDeviceData> DeviceData { get; } public Dictionary<string, IAtmosDeviceData> DeviceData { get; }
public AirAlarmMode Mode { get; } public AirAlarmMode Mode { get; }
public AirAlarmTab Tab { get; } public AirAlarmTab Tab { get; }
public AtmosMonitorAlarmType AlarmType { get; } public AtmosAlarmType AlarmType { get; }
} }
[Serializable, NetSerializable] [Serializable, NetSerializable]

View File

@@ -1,10 +0,0 @@
using Robust.Shared.Serialization;
namespace Content.Shared.Atmos.Monitor.Components;
[Serializable, NetSerializable]
public enum FireAlarmWireStatus
{
Power,
Alarm
}