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;
[DataField("alarmStates")]
public readonly Dictionary<AtmosMonitorAlarmType, string> AlarmStates = new();
public readonly Dictionary<AtmosAlarmType, string> AlarmStates = new();
[DataField("hideOnDepowered")]
public readonly List<string>? HideOnDepowered;

View File

@@ -14,26 +14,38 @@ public sealed class AtmosAlarmableVisualsSystem : VisualizerSystem<AtmosAlarmabl
{
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;
if (args.AppearanceData.TryGetValue(PowerDeviceVisuals.Powered, out var poweredObject)
&& poweredObject is bool powered)
if (!args.AppearanceData.TryGetValue(PowerDeviceVisuals.Powered, out var poweredObject) ||
poweredObject is not bool powered)
{
return;
}
if (component.HideOnDepowered != null)
{
foreach (var visLayer in component.HideOnDepowered)
{
if (args.Sprite.LayerMapTryGet(visLayer, out int powerVisibilityLayer))
args.Sprite.LayerSetVisible(powerVisibilityLayer, powered);
}
}
if (component.SetOnDepowered != null && !powered)
{
foreach (var (setLayer, powerState) in component.SetOnDepowered)
{
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 AtmosMonitorAlarmType alarmType
&& 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;
public AirAlarmBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey)
{}
{
}
protected override void Open()
{
@@ -21,7 +22,10 @@ public sealed class AirAlarmBoundUserInterface : BoundUserInterface
_window = new AirAlarmWindow();
if (State != null) UpdateState(State);
if (State != null)
{
UpdateState(State);
}
_window.OpenCentered();

View File

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

View File

@@ -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<VentPumpDirection>())
{
_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<VentPressureBound>())
{
_pressureCheck.AddItem(Loc.GetString($"{value}"), (int) value);
}
_pressureCheck.SelectId((int) _data.PressureChecks);
_pressureCheck.OnItemSelected += args =>

View File

@@ -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<ScrubberPumpDirection>())
{
_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<Gas>())
{
if (!intersect.Contains(value))
_gasControls[value].Pressed = false;
}
}
}

View File

@@ -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;
}
}
}

View File

@@ -29,9 +29,9 @@ namespace Content.Server.Atmos.Monitor.Components;
public sealed class AtmosAlarmableComponent : Component
{
[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;

View File

@@ -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<AtmosMonitorThresholdType> TrippedThresholds = new();

View File

@@ -62,7 +62,9 @@ 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)
{
return mode switch
{
AirAlarmMode.Filtering => _filterMode,
AirAlarmMode.Fill => _fillMode,
@@ -70,6 +72,7 @@ public sealed class AirAlarmModeFactory
AirAlarmMode.None => _noneMode,
_ => null
};
}
}
// like a tiny little EntitySystem

View File

@@ -81,7 +81,7 @@ public sealed class AirAlarmSystem : EntitySystem
/// on this network.
/// </summary>
/// <param name="uid"></param>
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.
/// </summary>
/// <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)
&& !monitor.NetEnabled)
@@ -231,8 +231,11 @@ 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))
{
return;
}
component.KnownDevices.Clear();
component.VentData.Clear();
component.ScrubberData.Clear();
@@ -240,11 +243,10 @@ public sealed class AirAlarmSystem : EntitySystem
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
/// </summary>
/// <param name="address">The address to send the new data to.</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;
SetData(uid, address, devData);
@@ -421,32 +428,35 @@ public sealed class AirAlarmSystem : EntitySystem
#region UI
// List of active user interfaces.
private HashSet<EntityUid> _activeUserInterfaces = new();
private readonly HashSet<EntityUid> _activeUserInterfaces = new();
/// <summary>
/// Adds an active interface to be updated.
/// </summary>
public void AddActiveInterface(EntityUid uid) =>
private void AddActiveInterface(EntityUid uid)
{
_activeUserInterfaces.Add(uid);
}
/// <summary>
/// Removes an active interface from the system update loop.
/// </summary>
public void RemoveActiveInterface(EntityUid uid) =>
private void RemoveActiveInterface(EntityUid uid)
{
_activeUserInterfaces.Remove(uid);
}
/// <summary>
/// Force closes all interfaces currently open related to this air alarm.
/// </summary>
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)

View File

@@ -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<string, AtmosMonitorAlarmType>? alarms))
out IReadOnlyDictionary<string, AtmosAlarmType>? 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
/// <param name="uid"></param>
/// <param name="alarmType"></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)
{
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
/// <param name="alarm"></param>
/// <param name="alarmable"></param>
/// <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)
{
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;
}

View File

@@ -62,10 +62,12 @@ public sealed class AtmosMonitorSystem : EntitySystem
{
component.GasThresholds = new();
foreach (var (gas, id) in component.GasThresholdIds)
{
if (_prototypeManager.TryIndex<AtmosAlarmThreshold>(id, out var gasThreshold))
component.GasThresholds.Add(gas, new(gasThreshold));
}
}
}
private void OnAtmosMonitorStartup(EntityUid uid, AtmosMonitorComponent component, ComponentStartup args)
{
@@ -73,7 +75,6 @@ public sealed class AtmosMonitorSystem : EntitySystem
&& TryComp<AtmosDeviceComponent>(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<AtmosMonitorThresholdType> 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
/// </summary>
/// <param name="state">The alarm state to set this monitor to.</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;
@@ -313,7 +314,7 @@ public sealed class AtmosMonitorSystem : EntitySystem
/// </summary>
private void Reset(EntityUid uid)
{
Alert(uid, AtmosMonitorAlarmType.Normal);
Alert(uid, AtmosAlarmType.Normal);
}
/// <summary>

View File

@@ -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<AtmosAlarmableComponent>(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<AtmosAlarmableComponent>(uid);
}
}

View File

@@ -37,7 +37,7 @@ public sealed class AirAlarmPanicWire : BaseWireAction
{
base.Initialize();
_airAlarmSystem = EntitySystem.Get<AirAlarmSystem>();
_airAlarmSystem = EntityManager.System<AirAlarmSystem>();
}
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))
{
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>();
_atmosAlarmableSystem = EntityManager.System<AtmosAlarmableSystem>();
}
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;
@@ -62,9 +62,9 @@ public sealed class AtmosMonitorDeviceNetWire : BaseWireAction
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;
@@ -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;

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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<DoorComponent>(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();
}

View File

@@ -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,
}

View File

@@ -3,7 +3,7 @@ using Robust.Shared.Serialization;
namespace Content.Shared.Atmos.Monitor;
[Serializable, NetSerializable]
public enum AtmosMonitorAlarmType : sbyte
public enum AtmosAlarmType : sbyte
{
Normal = 0,
Warning = 1,

View File

@@ -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<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;
Temperature = temperature;
@@ -39,7 +39,7 @@ public sealed class AtmosSensorData : IAtmosDeviceData
/// <summary>
/// Current alarm state of this sensor. Does not reflect the highest alarm state on the network.
/// </summary>
public AtmosMonitorAlarmType AlarmState { get; }
public AtmosAlarmType AlarmState { get; }
/// <summary>
/// Current number of gases on this sensor.
/// </summary>

View File

@@ -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<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;
DeviceCount = deviceCount;
@@ -61,7 +61,7 @@ public sealed class AirAlarmUIState : BoundUserInterfaceState
public Dictionary<string, IAtmosDeviceData> DeviceData { get; }
public AirAlarmMode Mode { get; }
public AirAlarmTab Tab { get; }
public AtmosMonitorAlarmType AlarmType { get; }
public AtmosAlarmType AlarmType { get; }
}
[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
}