From e0bf77490de8f177cada42734339cb5ea5de763d Mon Sep 17 00:00:00 2001 From: vulppine Date: Mon, 29 Aug 2022 07:37:26 -0700 Subject: [PATCH] number of things, fixing warnings, AtmosAlarmType instead of AtmosMonitorAlarmType --- .../Monitor/AtmosAlarmableVisualsComponent.cs | 2 +- .../Monitor/AtmosAlarmableVisualsSystem.cs | 44 ++++++++----- .../Monitor/UI/AirAlarmBoundUserInterface.cs | 8 ++- .../Atmos/Monitor/UI/AirAlarmWindow.xaml.cs | 2 + .../Monitor/UI/Widgets/PumpControl.xaml.cs | 6 +- .../UI/Widgets/ScrubberControl.xaml.cs | 6 +- .../UI/Widgets/ThresholdControl.xaml.cs | 16 +++-- .../Components/AtmosAlarmableComponent.cs | 4 +- .../Components/AtmosMonitorComponent.cs | 2 +- .../Atmos/Monitor/Systems/AirAlarmModes.cs | 17 +++-- .../Atmos/Monitor/Systems/AirAlarmSystem.cs | 66 +++++++++++-------- .../Monitor/Systems/AtmosAlarmableSystem.cs | 28 ++++---- .../Monitor/Systems/AtmosMonitoringSystem.cs | 19 +++--- .../Atmos/Monitor/Systems/FireAlarmSystem.cs | 8 +-- .../Monitor/WireActions/AirAlarmPanicWire.cs | 2 +- ...larmWire.cs => AtmosAlarmableAlarmWire.cs} | 16 ++--- .../Unary/EntitySystems/GasVentPumpSystem.cs | 4 +- .../EntitySystems/GasVentScrubberSystem.cs | 4 +- .../Doors/Systems/FirelockSystem.cs | 6 +- .../Atmos/Monitor/AtmosAlarmThreshold.cs | 43 ++++++------ ...sMonitorAlarmType.cs => AtmosAlarmType.cs} | 4 +- .../Atmos/Monitor/AtmosSensorData.cs | 4 +- .../Components/SharedAirAlarmComponent.cs | 4 +- .../Components/SharedFireAlarmComponent.cs | 10 --- 24 files changed, 177 insertions(+), 148 deletions(-) rename Content.Server/Atmos/Monitor/WireActions/{AtmosMonitorAlarmWire.cs => AtmosAlarmableAlarmWire.cs} (75%) rename Content.Shared/Atmos/Monitor/{AtmosMonitorAlarmType.cs => AtmosAlarmType.cs} (85%) delete mode 100644 Content.Shared/Atmos/Monitor/Components/SharedFireAlarmComponent.cs diff --git a/Content.Client/Atmos/Monitor/AtmosAlarmableVisualsComponent.cs b/Content.Client/Atmos/Monitor/AtmosAlarmableVisualsComponent.cs index 4aed944d92..57b713e9b7 100644 --- a/Content.Client/Atmos/Monitor/AtmosAlarmableVisualsComponent.cs +++ b/Content.Client/Atmos/Monitor/AtmosAlarmableVisualsComponent.cs @@ -9,7 +9,7 @@ public sealed class AtmosAlarmableVisualsComponent : Component public string LayerMap { get; } = string.Empty; [DataField("alarmStates")] - public readonly Dictionary AlarmStates = new(); + public readonly Dictionary AlarmStates = new(); [DataField("hideOnDepowered")] public readonly List? HideOnDepowered; diff --git a/Content.Client/Atmos/Monitor/AtmosAlarmableVisualsSystem.cs b/Content.Client/Atmos/Monitor/AtmosAlarmableVisualsSystem.cs index cbe4ea3c0d..019f25f376 100644 --- a/Content.Client/Atmos/Monitor/AtmosAlarmableVisualsSystem.cs +++ b/Content.Client/Atmos/Monitor/AtmosAlarmableVisualsSystem.cs @@ -14,27 +14,39 @@ public sealed class AtmosAlarmableVisualsSystem : VisualizerSystem()) + { _modes.AddItem($"{mode}", (int) mode); + } _modes.OnItemSelected += args => { diff --git a/Content.Client/Atmos/Monitor/UI/Widgets/PumpControl.xaml.cs b/Content.Client/Atmos/Monitor/UI/Widgets/PumpControl.xaml.cs index e8844918c6..457bc6e535 100644 --- a/Content.Client/Atmos/Monitor/UI/Widgets/PumpControl.xaml.cs +++ b/Content.Client/Atmos/Monitor/UI/Widgets/PumpControl.xaml.cs @@ -29,7 +29,7 @@ public sealed partial class PumpControl : BoxContainer { RobustXamlLoader.Load(this); - this.Name = address; + Name = address; _data = data; _address = address; @@ -60,7 +60,9 @@ public sealed partial class PumpControl : BoxContainer _externalBound.IsValid += value => value >= 0; foreach (var value in Enum.GetValues()) + { _pumpDirection.AddItem(Loc.GetString($"{value}"), (int) value); + } _pumpDirection.SelectId((int) _data.PumpDirection); _pumpDirection.OnItemSelected += args => @@ -71,7 +73,9 @@ public sealed partial class PumpControl : BoxContainer }; foreach (var value in Enum.GetValues()) + { _pressureCheck.AddItem(Loc.GetString($"{value}"), (int) value); + } _pressureCheck.SelectId((int) _data.PressureChecks); _pressureCheck.OnItemSelected += args => diff --git a/Content.Client/Atmos/Monitor/UI/Widgets/ScrubberControl.xaml.cs b/Content.Client/Atmos/Monitor/UI/Widgets/ScrubberControl.xaml.cs index 2f9187ab00..edad94cf55 100644 --- a/Content.Client/Atmos/Monitor/UI/Widgets/ScrubberControl.xaml.cs +++ b/Content.Client/Atmos/Monitor/UI/Widgets/ScrubberControl.xaml.cs @@ -34,7 +34,7 @@ public sealed partial class ScrubberControl : BoxContainer { RobustXamlLoader.Load(this); - this.Name = address; + Name = address; _data = data; _address = address; @@ -64,7 +64,9 @@ public sealed partial class ScrubberControl : BoxContainer _volumeRate.IsValid += value => value >= 0; foreach (var value in Enum.GetValues()) + { _pumpDirection.AddItem(Loc.GetString($"{value}"), (int) value); + } _pumpDirection.SelectId((int) _data.PumpDirection); _pumpDirection.OnItemSelected += args => @@ -116,7 +118,9 @@ public sealed partial class ScrubberControl : BoxContainer var intersect = _data.FilterGases.Intersect(data.FilterGases); foreach (var value in Enum.GetValues()) + { if (!intersect.Contains(value)) _gasControls[value].Pressed = false; + } } } \ No newline at end of file diff --git a/Content.Client/Atmos/Monitor/UI/Widgets/ThresholdControl.xaml.cs b/Content.Client/Atmos/Monitor/UI/Widgets/ThresholdControl.xaml.cs index 138f1234df..54672f995a 100644 --- a/Content.Client/Atmos/Monitor/UI/Widgets/ThresholdControl.xaml.cs +++ b/Content.Client/Atmos/Monitor/UI/Widgets/ThresholdControl.xaml.cs @@ -208,18 +208,18 @@ public sealed partial class ThresholdControl : BoxContainer _modifier = modifier > 0 ? modifier : 1; _value = value; - this.HorizontalExpand = true; - this.Orientation = LayoutOrientation.Vertical; + HorizontalExpand = true; + 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); - this.AddChild(_bound); + AddChild(_bound); _boundEnabled = new CheckBox { Text = Loc.GetString("Enabled") }; - this.AddChild(_boundEnabled); + AddChild(_boundEnabled); _bound.Value = ModifiedValue ?? 0; _lastValue = _value ?? 0; @@ -289,7 +289,9 @@ public sealed partial class ThresholdControl : BoxContainer OnValidBoundChanged!.Invoke(); } - private bool ValidateThreshold(float value) => (_value != null) && (value >= 0); - + private bool ValidateThreshold(float value) + { + return _value != null && value >= 0; + } } } diff --git a/Content.Server/Atmos/Monitor/Components/AtmosAlarmableComponent.cs b/Content.Server/Atmos/Monitor/Components/AtmosAlarmableComponent.cs index 0e007798ca..a28a06e279 100644 --- a/Content.Server/Atmos/Monitor/Components/AtmosAlarmableComponent.cs +++ b/Content.Server/Atmos/Monitor/Components/AtmosAlarmableComponent.cs @@ -29,9 +29,9 @@ namespace Content.Server.Atmos.Monitor.Components; public sealed class AtmosAlarmableComponent : Component { [ViewVariables] - public readonly Dictionary NetworkAlarmStates = new(); + public readonly Dictionary NetworkAlarmStates = new(); - [ViewVariables] public AtmosMonitorAlarmType LastAlarmState = AtmosMonitorAlarmType.Normal; + [ViewVariables] public AtmosAlarmType LastAlarmState = AtmosAlarmType.Normal; [ViewVariables] public bool IgnoreAlarms { get; set; } = false; diff --git a/Content.Server/Atmos/Monitor/Components/AtmosMonitorComponent.cs b/Content.Server/Atmos/Monitor/Components/AtmosMonitorComponent.cs index db2f5302c1..a229544d03 100644 --- a/Content.Server/Atmos/Monitor/Components/AtmosMonitorComponent.cs +++ b/Content.Server/Atmos/Monitor/Components/AtmosMonitorComponent.cs @@ -57,7 +57,7 @@ public sealed class AtmosMonitorComponent : Component // Stores the last alarm state of this alarm. [ViewVariables] - public AtmosMonitorAlarmType LastAlarmState = AtmosMonitorAlarmType.Normal; + public AtmosAlarmType LastAlarmState = AtmosAlarmType.Normal; [ViewVariables] public HashSet TrippedThresholds = new(); diff --git a/Content.Server/Atmos/Monitor/Systems/AirAlarmModes.cs b/Content.Server/Atmos/Monitor/Systems/AirAlarmModes.cs index 6a5a25ec51..dbc5bebbca 100644 --- a/Content.Server/Atmos/Monitor/Systems/AirAlarmModes.cs +++ b/Content.Server/Atmos/Monitor/Systems/AirAlarmModes.cs @@ -62,14 +62,17 @@ public sealed class AirAlarmModeFactory // still not a fan since ReplaceMode must have an allocation // but it's whatever - public static IAirAlarmMode? ModeToExecutor(AirAlarmMode mode) => mode switch + public static IAirAlarmMode? ModeToExecutor(AirAlarmMode mode) { - AirAlarmMode.Filtering => _filterMode, - AirAlarmMode.Fill => _fillMode, - AirAlarmMode.Panic => _panicMode, - AirAlarmMode.None => _noneMode, - _ => null - }; + return mode switch + { + AirAlarmMode.Filtering => _filterMode, + AirAlarmMode.Fill => _fillMode, + AirAlarmMode.Panic => _panicMode, + AirAlarmMode.None => _noneMode, + _ => null + }; + } } // like a tiny little EntitySystem diff --git a/Content.Server/Atmos/Monitor/Systems/AirAlarmSystem.cs b/Content.Server/Atmos/Monitor/Systems/AirAlarmSystem.cs index 4fc027d374..47129d70db 100644 --- a/Content.Server/Atmos/Monitor/Systems/AirAlarmSystem.cs +++ b/Content.Server/Atmos/Monitor/Systems/AirAlarmSystem.cs @@ -81,7 +81,7 @@ public sealed class AirAlarmSystem : EntitySystem /// on this network. /// /// - public void SyncRegisterAllDevices(EntityUid uid) + private void SyncRegisterAllDevices(EntityUid uid) { _atmosDevNetSystem.Register(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. /// /// The mode to sync with the rest of the network. - public void SyncMode(EntityUid uid, AirAlarmMode mode) + private void SyncMode(EntityUid uid, AirAlarmMode mode) { if (EntityManager.TryGetComponent(uid, out AtmosMonitorComponent? monitor) && !monitor.NetEnabled) @@ -231,20 +231,22 @@ public sealed class AirAlarmSystem : EntitySystem 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(); - component.VentData.Clear(); - component.ScrubberData.Clear(); - component.SensorData.Clear(); - - SyncRegisterAllDevices(uid); + return; } + + component.KnownDevices.Clear(); + component.VentData.Clear(); + component.ScrubberData.Clear(); + component.SensorData.Clear(); + + SyncRegisterAllDevices(uid); } 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 (AccessCheck(uid, args.Session.AttachedEntity, component)) SetMode(uid, addr, args.Mode, true, false); @@ -292,15 +294,15 @@ public sealed class AirAlarmSystem : EntitySystem SyncAllDevices(uid); } - string addr = string.Empty; + var addr = string.Empty; 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); } - else if (args.AlarmType == AtmosMonitorAlarmType.Normal) + else if (args.AlarmType == AtmosAlarmType.Normal) { SetMode(uid, addr, AirAlarmMode.Filtering, true, false); } @@ -324,7 +326,7 @@ public sealed class AirAlarmSystem : EntitySystem if (!Resolve(uid, ref controller)) return; 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 // alarm mode executors if (!uiOnly) @@ -344,12 +346,14 @@ public sealed class AirAlarmSystem : EntitySystem } // only one air alarm in a network can use an air alarm mode // 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 // invalid mode else if (controller.CurrentModeUpdater != null && controller.CurrentModeUpdater.NetOwner != origin) + { controller.CurrentModeUpdater = null; + } UpdateUI(uid, controller); @@ -364,9 +368,12 @@ public sealed class AirAlarmSystem : EntitySystem /// /// The address to send the new data to. /// The device data to be sent. - 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; SetData(uid, address, devData); @@ -421,32 +428,35 @@ public sealed class AirAlarmSystem : EntitySystem #region UI // List of active user interfaces. - private HashSet _activeUserInterfaces = new(); + private readonly HashSet _activeUserInterfaces = new(); /// /// Adds an active interface to be updated. /// - public void AddActiveInterface(EntityUid uid) => + private void AddActiveInterface(EntityUid uid) + { _activeUserInterfaces.Add(uid); + } /// /// Removes an active interface from the system update loop. /// - public void RemoveActiveInterface(EntityUid uid) => + private void RemoveActiveInterface(EntityUid uid) + { _activeUserInterfaces.Remove(uid); + } /// /// Force closes all interfaces currently open related to this air alarm. /// - public void ForceCloseAllInterfaces(EntityUid uid) + private void ForceCloseAllInterfaces(EntityUid uid) { _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) @@ -506,7 +516,7 @@ public sealed class AirAlarmSystem : EntitySystem if (!_atmosAlarmable.TryGetHighestAlert(uid, out var highestAlarm)) { - highestAlarm = AtmosMonitorAlarmType.Normal; + highestAlarm = AtmosAlarmType.Normal; } _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)); } - private const float _delay = 8f; - private float _timer = 0f; + private const float Delay = 8f; + private float _timer; public override void Update(float frameTime) { _timer += frameTime; - if (_timer >= _delay) + if (_timer >= Delay) { _timer = 0f; foreach (var uid in _activeUserInterfaces) diff --git a/Content.Server/Atmos/Monitor/Systems/AtmosAlarmableSystem.cs b/Content.Server/Atmos/Monitor/Systems/AtmosAlarmableSystem.cs index 8d62ebead4..5075fcb0e4 100644 --- a/Content.Server/Atmos/Monitor/Systems/AtmosAlarmableSystem.cs +++ b/Content.Server/Atmos/Monitor/Systems/AtmosAlarmableSystem.cs @@ -55,7 +55,7 @@ public sealed class AtmosAlarmableSystem : EntitySystem { TryUpdateAlert( uid, - TryGetHighestAlert(uid, out var alarm) ? alarm.Value : AtmosMonitorAlarmType.Normal, + TryGetHighestAlert(uid, out var alarm) ? alarm.Value : AtmosAlarmType.Normal, component, false); } @@ -86,7 +86,7 @@ public sealed class AtmosAlarmableSystem : EntitySystem case AlertCmd: // Set the alert state, and then cache it so we can calculate // 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; } @@ -111,12 +111,12 @@ public sealed class AtmosAlarmableSystem : EntitySystem // it may mean that the threshold we need to look at has // been removed from the threshold types passed: // 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)) { - netMax = AtmosMonitorAlarmType.Normal; + netMax = AtmosAlarmType.Normal; } TryUpdateAlert(uid, netMax.Value, component); @@ -127,7 +127,7 @@ public sealed class AtmosAlarmableSystem : EntitySystem break; case SyncAlerts: if (!args.Data.TryGetValue(SyncAlerts, - out IReadOnlyDictionary? alarms)) + out IReadOnlyDictionary? alarms)) { 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) { @@ -191,7 +191,7 @@ public sealed class AtmosAlarmableSystem : EntitySystem /// /// /// - public void ForceAlert(EntityUid uid, AtmosMonitorAlarmType alarmType, + public void ForceAlert(EntityUid uid, AtmosAlarmType alarmType, AtmosAlarmableComponent? alarmable = null, DeviceNetworkComponent? devNet = null, TagComponent? tags = null) { if (!Resolve(uid, ref alarmable, ref devNet, ref tags)) @@ -233,7 +233,7 @@ public sealed class AtmosAlarmableSystem : EntitySystem return; } - TryUpdateAlert(uid, AtmosMonitorAlarmType.Normal, alarmable, false); + TryUpdateAlert(uid, AtmosAlarmType.Normal, alarmable, false); alarmable.NetworkAlarmStates.Clear(); } @@ -263,7 +263,7 @@ public sealed class AtmosAlarmableSystem : EntitySystem /// /// /// - public bool TryGetHighestAlert(EntityUid uid, [NotNullWhen(true)] out AtmosMonitorAlarmType? alarm, + public bool TryGetHighestAlert(EntityUid uid, [NotNullWhen(true)] out AtmosAlarmType? alarm, AtmosAlarmableComponent? alarmable = null) { alarm = null; @@ -281,15 +281,15 @@ public sealed class AtmosAlarmableSystem : EntitySystem 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)); } } - private void UpdateAppearance(EntityUid uid, AtmosMonitorAlarmType alarm) + private void UpdateAppearance(EntityUid uid, AtmosAlarmType alarm) { _appearance.SetData(uid, AtmosMonitorVisuals.AlarmType, alarm); } @@ -297,9 +297,9 @@ public sealed class AtmosAlarmableSystem : EntitySystem public sealed class AtmosAlarmEvent : EntityEventArgs { - public AtmosMonitorAlarmType AlarmType { get; } + public AtmosAlarmType AlarmType { get; } - public AtmosAlarmEvent(AtmosMonitorAlarmType netMax) + public AtmosAlarmEvent(AtmosAlarmType netMax) { AlarmType = netMax; } diff --git a/Content.Server/Atmos/Monitor/Systems/AtmosMonitoringSystem.cs b/Content.Server/Atmos/Monitor/Systems/AtmosMonitoringSystem.cs index ab21b45ca0..18e2862bcc 100644 --- a/Content.Server/Atmos/Monitor/Systems/AtmosMonitoringSystem.cs +++ b/Content.Server/Atmos/Monitor/Systems/AtmosMonitoringSystem.cs @@ -62,8 +62,10 @@ public sealed class AtmosMonitorSystem : EntitySystem { component.GasThresholds = new(); foreach (var (gas, id) in component.GasThresholdIds) + { if (_prototypeManager.TryIndex(id, out var gasThreshold)) component.GasThresholds.Add(gas, new(gasThreshold)); + } } } @@ -73,7 +75,6 @@ public sealed class AtmosMonitorSystem : EntitySystem && TryComp(uid, out var atmosDeviceComponent)) { _atmosDeviceSystem.LeaveAtmosphere(atmosDeviceComponent); - return; } } @@ -174,10 +175,10 @@ public sealed class AtmosMonitorSystem : EntitySystem // // somebody else can reset it :sunglasses: if (component.MonitorFire - && component.LastAlarmState != AtmosMonitorAlarmType.Danger) + && component.LastAlarmState != AtmosAlarmType.Danger) { 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, @@ -188,7 +189,7 @@ public sealed class AtmosMonitorSystem : EntitySystem && temperatureState > component.LastAlarmState) { 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; - AtmosMonitorAlarmType state = AtmosMonitorAlarmType.Normal; + var state = AtmosAlarmType.Normal; HashSet alarmTypes = new(monitor.TrippedThresholds); if (monitor.TemperatureThreshold != null @@ -238,7 +239,7 @@ public sealed class AtmosMonitorSystem : EntitySystem state = temperatureState; alarmTypes.Add(AtmosMonitorThresholdType.Temperature); } - else if (temperatureState == AtmosMonitorAlarmType.Normal) + else if (temperatureState == AtmosAlarmType.Normal) { alarmTypes.Remove(AtmosMonitorThresholdType.Temperature); } @@ -253,7 +254,7 @@ public sealed class AtmosMonitorSystem : EntitySystem state = pressureState; alarmTypes.Add(AtmosMonitorThresholdType.Pressure); } - else if (pressureState == AtmosMonitorAlarmType.Normal) + else if (pressureState == AtmosAlarmType.Normal) { alarmTypes.Remove(AtmosMonitorThresholdType.Pressure); } @@ -296,7 +297,7 @@ public sealed class AtmosMonitorSystem : EntitySystem /// /// The alarm state to set this monitor to. /// The alarms that caused this alarm state. - public void Alert(EntityUid uid, AtmosMonitorAlarmType state, HashSet? alarms = null, AtmosMonitorComponent? monitor = null) + public void Alert(EntityUid uid, AtmosAlarmType state, HashSet? alarms = null, AtmosMonitorComponent? monitor = null) { if (!Resolve(uid, ref monitor)) return; @@ -313,7 +314,7 @@ public sealed class AtmosMonitorSystem : EntitySystem /// private void Reset(EntityUid uid) { - Alert(uid, AtmosMonitorAlarmType.Normal); + Alert(uid, AtmosAlarmType.Normal); } /// diff --git a/Content.Server/Atmos/Monitor/Systems/FireAlarmSystem.cs b/Content.Server/Atmos/Monitor/Systems/FireAlarmSystem.cs index e2e2341a3f..190d8ea2c5 100644 --- a/Content.Server/Atmos/Monitor/Systems/FireAlarmSystem.cs +++ b/Content.Server/Atmos/Monitor/Systems/FireAlarmSystem.cs @@ -39,12 +39,12 @@ public sealed class FireAlarmSystem : EntitySystem { 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 { @@ -58,7 +58,7 @@ public sealed class FireAlarmSystem : EntitySystem if (TryComp(uid, out var alarmable)) { // Remove the atmos alarmable component permanently from this device. - _atmosAlarmable.ForceAlert(uid, AtmosMonitorAlarmType.Emagged, alarmable); + _atmosAlarmable.ForceAlert(uid, AtmosAlarmType.Emagged, alarmable); RemCompDeferred(uid); } } diff --git a/Content.Server/Atmos/Monitor/WireActions/AirAlarmPanicWire.cs b/Content.Server/Atmos/Monitor/WireActions/AirAlarmPanicWire.cs index 6394e7216a..6a5a5a4e38 100644 --- a/Content.Server/Atmos/Monitor/WireActions/AirAlarmPanicWire.cs +++ b/Content.Server/Atmos/Monitor/WireActions/AirAlarmPanicWire.cs @@ -37,7 +37,7 @@ public sealed class AirAlarmPanicWire : BaseWireAction { base.Initialize(); - _airAlarmSystem = EntitySystem.Get(); + _airAlarmSystem = EntityManager.System(); } public override bool Cut(EntityUid user, Wire wire) diff --git a/Content.Server/Atmos/Monitor/WireActions/AtmosMonitorAlarmWire.cs b/Content.Server/Atmos/Monitor/WireActions/AtmosAlarmableAlarmWire.cs similarity index 75% rename from Content.Server/Atmos/Monitor/WireActions/AtmosMonitorAlarmWire.cs rename to Content.Server/Atmos/Monitor/WireActions/AtmosAlarmableAlarmWire.cs index b3c3247749..70d0b80f96 100644 --- a/Content.Server/Atmos/Monitor/WireActions/AtmosMonitorAlarmWire.cs +++ b/Content.Server/Atmos/Monitor/WireActions/AtmosAlarmableAlarmWire.cs @@ -29,10 +29,10 @@ public sealed class AtmosMonitorDeviceNetWire : BaseWireAction { 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.On; } @@ -47,14 +47,14 @@ public sealed class AtmosMonitorDeviceNetWire : BaseWireAction { base.Initialize(); - _atmosAlarmableSystem = EntitySystem.Get(); + _atmosAlarmableSystem = EntityManager.System(); } public override bool Cut(EntityUid user, Wire wire) { - if (EntityManager.TryGetComponent(wire.Owner, out var monitor)) + if (EntityManager.TryGetComponent(wire.Owner, out var monitor)) { - monitor.NetEnabled = false; + monitor.IgnoreAlarms = true; } return true; @@ -62,9 +62,9 @@ public sealed class AtmosMonitorDeviceNetWire : BaseWireAction public override bool Mend(EntityUid user, Wire wire) { - if (EntityManager.TryGetComponent(wire.Owner, out var monitor)) + if (EntityManager.TryGetComponent(wire.Owner, out var monitor)) { - monitor.NetEnabled = true; + monitor.IgnoreAlarms = false; } return true; @@ -74,7 +74,7 @@ public sealed class AtmosMonitorDeviceNetWire : BaseWireAction { if (_alarmOnPulse) { - _atmosAlarmableSystem.ForceAlert(wire.Owner, AtmosMonitorAlarmType.Danger); + _atmosAlarmableSystem.ForceAlert(wire.Owner, AtmosAlarmType.Danger); } return true; diff --git a/Content.Server/Atmos/Piping/Unary/EntitySystems/GasVentPumpSystem.cs b/Content.Server/Atmos/Piping/Unary/EntitySystems/GasVentPumpSystem.cs index ce64e2cd35..7165904267 100644 --- a/Content.Server/Atmos/Piping/Unary/EntitySystems/GasVentPumpSystem.cs +++ b/Content.Server/Atmos/Piping/Unary/EntitySystems/GasVentPumpSystem.cs @@ -160,11 +160,11 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems private void OnAtmosAlarm(EntityUid uid, GasVentPumpComponent component, AtmosAlarmEvent args) { - if (args.AlarmType == AtmosMonitorAlarmType.Danger) + if (args.AlarmType == AtmosAlarmType.Danger) { component.Enabled = false; } - else if (args.AlarmType == AtmosMonitorAlarmType.Normal) + else if (args.AlarmType == AtmosAlarmType.Normal) { component.Enabled = true; } diff --git a/Content.Server/Atmos/Piping/Unary/EntitySystems/GasVentScrubberSystem.cs b/Content.Server/Atmos/Piping/Unary/EntitySystems/GasVentScrubberSystem.cs index 1c7e27ea16..9b36d8111d 100644 --- a/Content.Server/Atmos/Piping/Unary/EntitySystems/GasVentScrubberSystem.cs +++ b/Content.Server/Atmos/Piping/Unary/EntitySystems/GasVentScrubberSystem.cs @@ -126,11 +126,11 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems private void OnAtmosAlarm(EntityUid uid, GasVentScrubberComponent component, AtmosAlarmEvent args) { - if (args.AlarmType == AtmosMonitorAlarmType.Danger) + if (args.AlarmType == AtmosAlarmType.Danger) { component.Enabled = false; } - else if (args.AlarmType == AtmosMonitorAlarmType.Normal) + else if (args.AlarmType == AtmosAlarmType.Normal) { component.Enabled = true; } diff --git a/Content.Server/Doors/Systems/FirelockSystem.cs b/Content.Server/Doors/Systems/FirelockSystem.cs index b8af3d184e..a836ad8c2d 100644 --- a/Content.Server/Doors/Systems/FirelockSystem.cs +++ b/Content.Server/Doors/Systems/FirelockSystem.cs @@ -83,7 +83,7 @@ namespace Content.Server.Doors.Systems // Make firelocks autoclose, but only if the last alarm type it // remembers was a danger. This is to prevent people from // 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(); } @@ -91,12 +91,12 @@ namespace Content.Server.Doors.Systems { if (!TryComp(uid, out var doorComponent)) return; - if (args.AlarmType == AtmosMonitorAlarmType.Normal) + if (args.AlarmType == AtmosAlarmType.Normal) { if (doorComponent.State == DoorState.Closed) _doorSystem.TryOpen(uid); } - else if (args.AlarmType == AtmosMonitorAlarmType.Danger) + else if (args.AlarmType == AtmosAlarmType.Danger) { component.EmergencyPressureStop(); } diff --git a/Content.Shared/Atmos/Monitor/AtmosAlarmThreshold.cs b/Content.Shared/Atmos/Monitor/AtmosAlarmThreshold.cs index 442fac084b..f83a90343b 100644 --- a/Content.Shared/Atmos/Monitor/AtmosAlarmThreshold.cs +++ b/Content.Shared/Atmos/Monitor/AtmosAlarmThreshold.cs @@ -9,11 +9,11 @@ namespace Content.Shared.Atmos.Monitor; [Serializable, NetSerializable] public sealed class AtmosAlarmThreshold : IPrototype, ISerializationHooks { - [IdDataFieldAttribute] + [IdDataField] public string ID { get; } = default!; [ViewVariables] [DataField("ignore")] - public bool Ignore = false; + public bool Ignore; // zero bounds are not allowed - just // set the bound to null if you want @@ -41,19 +41,14 @@ public sealed class AtmosAlarmThreshold : IPrototype, ISerializationHooks public float? LowerWarningPercentage { get; private set; } [ViewVariables] - public float? UpperWarningBound - { - get => CalculateWarningBound(AtmosMonitorThresholdBound.Upper); - } + public float? UpperWarningBound => CalculateWarningBound(AtmosMonitorThresholdBound.Upper); [ViewVariables] - public float? LowerWarningBound - { - get => CalculateWarningBound(AtmosMonitorThresholdBound.Lower); - } + public float? LowerWarningBound => CalculateWarningBound(AtmosMonitorThresholdBound.Lower); public AtmosAlarmThreshold() - {} + { + } public AtmosAlarmThreshold(AtmosAlarmThreshold other) { @@ -80,19 +75,22 @@ public sealed class AtmosAlarmThreshold : IPrototype, ISerializationHooks } // 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; - if (Ignore) return false; + state = AtmosAlarmType.Normal; + if (Ignore) + { + return false; + } if (value >= UpperBound || value <= LowerBound) { - state = AtmosMonitorAlarmType.Danger; + state = AtmosAlarmType.Danger; return true; } if (value >= UpperWarningBound || value <= LowerWarningBound) { - state = AtmosMonitorAlarmType.Warning; + state = AtmosAlarmType.Warning; return true; } @@ -117,7 +115,7 @@ public sealed class AtmosAlarmThreshold : IPrototype, ISerializationHooks return true; } - float value = (float) input; + var value = (float) input; if (value <= 0f || float.IsNaN(value)) return false; @@ -141,7 +139,7 @@ public sealed class AtmosAlarmThreshold : IPrototype, ISerializationHooks break; } - bool isValid = true; + var isValid = true; if (targetValue != null) { var result = targetValue.Value.target.CompareTo(value); @@ -191,8 +189,8 @@ public sealed class AtmosAlarmThreshold : IPrototype, ISerializationHooks if (UpperBound == null) return false; - float upperWarning = (float) (input / UpperBound); - float upperTestValue = (upperWarning * (float) UpperBound); + var upperWarning = (float) (input / UpperBound); + var upperTestValue = upperWarning * (float) UpperBound; if (upperWarning > 1f || upperTestValue < LowerWarningBound @@ -206,8 +204,8 @@ public sealed class AtmosAlarmThreshold : IPrototype, ISerializationHooks if (LowerBound == null) return false; - float lowerWarning = (float) (input / LowerBound); - float testValue = (lowerWarning * (float) LowerBound); + var lowerWarning = (float) (input / LowerBound); + var testValue = lowerWarning * (float) LowerBound; if (lowerWarning < 1f || testValue > UpperWarningBound @@ -265,6 +263,5 @@ public enum AtmosMonitorThresholdType [Serializable, NetSerializable] public enum AtmosMonitorVisuals : byte { - Offset, AlarmType, } diff --git a/Content.Shared/Atmos/Monitor/AtmosMonitorAlarmType.cs b/Content.Shared/Atmos/Monitor/AtmosAlarmType.cs similarity index 85% rename from Content.Shared/Atmos/Monitor/AtmosMonitorAlarmType.cs rename to Content.Shared/Atmos/Monitor/AtmosAlarmType.cs index c0cd58a48d..c51106f8d2 100644 --- a/Content.Shared/Atmos/Monitor/AtmosMonitorAlarmType.cs +++ b/Content.Shared/Atmos/Monitor/AtmosAlarmType.cs @@ -3,10 +3,10 @@ using Robust.Shared.Serialization; namespace Content.Shared.Atmos.Monitor; [Serializable, NetSerializable] -public enum AtmosMonitorAlarmType : sbyte +public enum AtmosAlarmType : sbyte { Normal = 0, Warning = 1, Danger = 2, // 1 << 1 is the exact same thing and we're not really doing **bitmasking** are we? Emagged = 3, -} \ No newline at end of file +} diff --git a/Content.Shared/Atmos/Monitor/AtmosSensorData.cs b/Content.Shared/Atmos/Monitor/AtmosSensorData.cs index 435b538d64..041c386b5f 100644 --- a/Content.Shared/Atmos/Monitor/AtmosSensorData.cs +++ b/Content.Shared/Atmos/Monitor/AtmosSensorData.cs @@ -6,7 +6,7 @@ namespace Content.Shared.Atmos.Monitor; [Serializable, NetSerializable] public sealed class AtmosSensorData : IAtmosDeviceData { - public AtmosSensorData(float pressure, float temperature, float totalMoles, AtmosMonitorAlarmType alarmState, Dictionary gases, AtmosAlarmThreshold pressureThreshold, AtmosAlarmThreshold temperatureThreshold, Dictionary gasThresholds) + public AtmosSensorData(float pressure, float temperature, float totalMoles, AtmosAlarmType alarmState, Dictionary gases, AtmosAlarmThreshold pressureThreshold, AtmosAlarmThreshold temperatureThreshold, Dictionary gasThresholds) { Pressure = pressure; Temperature = temperature; @@ -39,7 +39,7 @@ public sealed class AtmosSensorData : IAtmosDeviceData /// /// Current alarm state of this sensor. Does not reflect the highest alarm state on the network. /// - public AtmosMonitorAlarmType AlarmState { get; } + public AtmosAlarmType AlarmState { get; } /// /// Current number of gases on this sensor. /// diff --git a/Content.Shared/Atmos/Monitor/Components/SharedAirAlarmComponent.cs b/Content.Shared/Atmos/Monitor/Components/SharedAirAlarmComponent.cs index b103904d0b..371d051fbc 100644 --- a/Content.Shared/Atmos/Monitor/Components/SharedAirAlarmComponent.cs +++ b/Content.Shared/Atmos/Monitor/Components/SharedAirAlarmComponent.cs @@ -36,7 +36,7 @@ public interface IAtmosDeviceData [Serializable, NetSerializable] public sealed class AirAlarmUIState : BoundUserInterfaceState { - public AirAlarmUIState(string address, int deviceCount, float pressureAverage, float temperatureAverage, Dictionary deviceData, AirAlarmMode mode, AirAlarmTab tab, AtmosMonitorAlarmType alarmType) + public AirAlarmUIState(string address, int deviceCount, float pressureAverage, float temperatureAverage, Dictionary deviceData, AirAlarmMode mode, AirAlarmTab tab, AtmosAlarmType alarmType) { Address = address; DeviceCount = deviceCount; @@ -61,7 +61,7 @@ public sealed class AirAlarmUIState : BoundUserInterfaceState public Dictionary DeviceData { get; } public AirAlarmMode Mode { get; } public AirAlarmTab Tab { get; } - public AtmosMonitorAlarmType AlarmType { get; } + public AtmosAlarmType AlarmType { get; } } [Serializable, NetSerializable] diff --git a/Content.Shared/Atmos/Monitor/Components/SharedFireAlarmComponent.cs b/Content.Shared/Atmos/Monitor/Components/SharedFireAlarmComponent.cs deleted file mode 100644 index c837f920aa..0000000000 --- a/Content.Shared/Atmos/Monitor/Components/SharedFireAlarmComponent.cs +++ /dev/null @@ -1,10 +0,0 @@ -using Robust.Shared.Serialization; - -namespace Content.Shared.Atmos.Monitor.Components; - -[Serializable, NetSerializable] -public enum FireAlarmWireStatus -{ - Power, - Alarm -}