file-scoped namespaces
This commit is contained in:
@@ -8,8 +8,8 @@ using Robust.Shared.IoC;
|
|||||||
using Robust.Shared.Maths;
|
using Robust.Shared.Maths;
|
||||||
using Robust.Shared.Serialization.Manager.Attributes;
|
using Robust.Shared.Serialization.Manager.Attributes;
|
||||||
|
|
||||||
namespace Content.Client.Atmos.Monitor
|
namespace Content.Client.Atmos.Monitor;
|
||||||
{
|
|
||||||
public sealed class AtmosMonitorVisualizer : AppearanceVisualizer
|
public sealed class AtmosMonitorVisualizer : AppearanceVisualizer
|
||||||
{
|
{
|
||||||
[Dependency] IEntityManager _entityManager = default!;
|
[Dependency] IEntityManager _entityManager = default!;
|
||||||
@@ -67,4 +67,3 @@ namespace Content.Client.Atmos.Monitor
|
|||||||
sprite.LayerSetState(layer, new RSI.StateId(state));
|
sprite.LayerSetState(layer, new RSI.StateId(state));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ using Robust.Shared.GameObjects;
|
|||||||
using Robust.Shared.IoC;
|
using Robust.Shared.IoC;
|
||||||
using Robust.Shared.Log;
|
using Robust.Shared.Log;
|
||||||
|
|
||||||
namespace Content.Client.Atmos.Monitor.UI
|
namespace Content.Client.Atmos.Monitor.UI;
|
||||||
{
|
|
||||||
public sealed class AirAlarmBoundUserInterface : BoundUserInterface
|
public sealed class AirAlarmBoundUserInterface : BoundUserInterface
|
||||||
{
|
{
|
||||||
private AirAlarmWindow? _window;
|
private AirAlarmWindow? _window;
|
||||||
@@ -77,4 +77,3 @@ namespace Content.Client.Atmos.Monitor.UI
|
|||||||
if (disposing) _window?.Dispose();
|
if (disposing) _window?.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -13,8 +13,8 @@ using Robust.Client.UserInterface.CustomControls;
|
|||||||
using Robust.Client.UserInterface.XAML;
|
using Robust.Client.UserInterface.XAML;
|
||||||
using Robust.Shared.Localization;
|
using Robust.Shared.Localization;
|
||||||
|
|
||||||
namespace Content.Client.Atmos.Monitor.UI
|
namespace Content.Client.Atmos.Monitor.UI;
|
||||||
{
|
|
||||||
[GenerateTypedNameReferences]
|
[GenerateTypedNameReferences]
|
||||||
public sealed partial class AirAlarmWindow : DefaultWindow
|
public sealed partial class AirAlarmWindow : DefaultWindow
|
||||||
{
|
{
|
||||||
@@ -149,4 +149,3 @@ namespace Content.Client.Atmos.Monitor.UI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ using Robust.Client.UserInterface.CustomControls;
|
|||||||
using Robust.Client.UserInterface.XAML;
|
using Robust.Client.UserInterface.XAML;
|
||||||
using Robust.Shared.Localization;
|
using Robust.Shared.Localization;
|
||||||
|
|
||||||
namespace Content.Client.Atmos.Monitor.UI.Widgets
|
namespace Content.Client.Atmos.Monitor.UI.Widgets;
|
||||||
{
|
|
||||||
[GenerateTypedNameReferences]
|
[GenerateTypedNameReferences]
|
||||||
public sealed partial class PumpControl : BoxContainer
|
public sealed partial class PumpControl : BoxContainer
|
||||||
{
|
{
|
||||||
@@ -100,4 +100,3 @@ namespace Content.Client.Atmos.Monitor.UI.Widgets
|
|||||||
_internalBound.Value = _data.InternalPressureBound;
|
_internalBound.Value = _data.InternalPressureBound;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ using Robust.Client.UserInterface.CustomControls;
|
|||||||
using Robust.Client.UserInterface.XAML;
|
using Robust.Client.UserInterface.XAML;
|
||||||
using Robust.Shared.Localization;
|
using Robust.Shared.Localization;
|
||||||
|
|
||||||
namespace Content.Client.Atmos.Monitor.UI.Widgets
|
namespace Content.Client.Atmos.Monitor.UI.Widgets;
|
||||||
{
|
|
||||||
[GenerateTypedNameReferences]
|
[GenerateTypedNameReferences]
|
||||||
public sealed partial class ScrubberControl : BoxContainer
|
public sealed partial class ScrubberControl : BoxContainer
|
||||||
{
|
{
|
||||||
@@ -120,4 +120,3 @@ namespace Content.Client.Atmos.Monitor.UI.Widgets
|
|||||||
_gasControls[value].Pressed = false;
|
_gasControls[value].Pressed = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ using Robust.Shared.Localization;
|
|||||||
// holy FUCK
|
// holy FUCK
|
||||||
// this technically works because some of this you can *not* do in XAML but holy FUCK
|
// this technically works because some of this you can *not* do in XAML but holy FUCK
|
||||||
|
|
||||||
namespace Content.Client.Atmos.Monitor.UI.Widgets
|
namespace Content.Client.Atmos.Monitor.UI.Widgets;
|
||||||
{
|
|
||||||
[GenerateTypedNameReferences]
|
[GenerateTypedNameReferences]
|
||||||
public sealed partial class ThresholdControl : BoxContainer
|
public sealed partial class ThresholdControl : BoxContainer
|
||||||
{
|
{
|
||||||
@@ -293,4 +293,3 @@ namespace Content.Client.Atmos.Monitor.UI.Widgets
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ using Content.Shared.Atmos.Monitor.Components;
|
|||||||
using Content.Shared.Atmos.Piping.Unary.Components;
|
using Content.Shared.Atmos.Piping.Unary.Components;
|
||||||
using Robust.Shared.Network;
|
using Robust.Shared.Network;
|
||||||
|
|
||||||
namespace Content.Server.Atmos.Monitor.Components
|
namespace Content.Server.Atmos.Monitor.Components;
|
||||||
{
|
|
||||||
[RegisterComponent]
|
[RegisterComponent]
|
||||||
public sealed class AirAlarmComponent : Component
|
public sealed class AirAlarmComponent : Component
|
||||||
{
|
{
|
||||||
@@ -24,4 +24,3 @@ namespace Content.Server.Atmos.Monitor.Components
|
|||||||
|
|
||||||
public bool CanSync = true;
|
public bool CanSync = true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -3,8 +3,7 @@ using Content.Shared.Tag;
|
|||||||
using Robust.Shared.Audio;
|
using Robust.Shared.Audio;
|
||||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Set;
|
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Set;
|
||||||
|
|
||||||
namespace Content.Server.Atmos.Monitor.Components
|
namespace Content.Server.Atmos.Monitor.Components;
|
||||||
{
|
|
||||||
// AtmosAlarmables are entities that can be alarmed
|
// AtmosAlarmables are entities that can be alarmed
|
||||||
// by a linked AtmosMonitor (alarmer?) if a threshold
|
// by a linked AtmosMonitor (alarmer?) if a threshold
|
||||||
// is passed in some way. The intended use is to
|
// is passed in some way. The intended use is to
|
||||||
@@ -59,4 +58,3 @@ namespace Content.Server.Atmos.Monitor.Components
|
|||||||
[DataField("receiveOnly")]
|
[DataField("receiveOnly")]
|
||||||
public bool ReceiveOnly { get; }
|
public bool ReceiveOnly { get; }
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ using Content.Shared.Atmos.Monitor;
|
|||||||
using Robust.Shared.Audio;
|
using Robust.Shared.Audio;
|
||||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||||
|
|
||||||
namespace Content.Server.Atmos.Monitor.Components
|
namespace Content.Server.Atmos.Monitor.Components;
|
||||||
{
|
|
||||||
[RegisterComponent]
|
[RegisterComponent]
|
||||||
public sealed class AtmosMonitorComponent : Component
|
public sealed class AtmosMonitorComponent : Component
|
||||||
{
|
{
|
||||||
@@ -67,4 +67,3 @@ namespace Content.Server.Atmos.Monitor.Components
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
[ViewVariables] public HashSet<string> RegisteredDevices = new();
|
[ViewVariables] public HashSet<string> RegisteredDevices = new();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
namespace Content.Server.Atmos.Monitor.Components
|
namespace Content.Server.Atmos.Monitor.Components;
|
||||||
{
|
|
||||||
[RegisterComponent]
|
[RegisterComponent]
|
||||||
public sealed class FireAlarmComponent : Component
|
public sealed class FireAlarmComponent : Component
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ using Content.Shared.Atmos;
|
|||||||
using Content.Shared.Atmos.Monitor.Components;
|
using Content.Shared.Atmos.Monitor.Components;
|
||||||
using Content.Shared.Atmos.Piping.Unary.Components;
|
using Content.Shared.Atmos.Piping.Unary.Components;
|
||||||
|
|
||||||
namespace Content.Server.Atmos.Monitor
|
namespace Content.Server.Atmos.Monitor;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This is an interface that air alarm modes use
|
/// This is an interface that air alarm modes use
|
||||||
/// in order to execute the defined modes.
|
/// in order to execute the defined modes.
|
||||||
@@ -211,4 +211,3 @@ namespace Content.Server.Atmos.Monitor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -18,8 +18,8 @@ using Content.Shared.Interaction;
|
|||||||
using Robust.Server.GameObjects;
|
using Robust.Server.GameObjects;
|
||||||
using Robust.Shared.Player;
|
using Robust.Shared.Player;
|
||||||
|
|
||||||
namespace Content.Server.Atmos.Monitor.Systems
|
namespace Content.Server.Atmos.Monitor.Systems;
|
||||||
{
|
|
||||||
// AirAlarm system - specific for atmos devices, rather than
|
// AirAlarm system - specific for atmos devices, rather than
|
||||||
// atmos monitors.
|
// atmos monitors.
|
||||||
//
|
//
|
||||||
@@ -531,4 +531,3 @@ namespace Content.Server.Atmos.Monitor.Systems
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ using Robust.Server.GameObjects;
|
|||||||
using Robust.Shared.Audio;
|
using Robust.Shared.Audio;
|
||||||
using Robust.Shared.Utility;
|
using Robust.Shared.Utility;
|
||||||
|
|
||||||
namespace Content.Server.Atmos.Monitor.Systems
|
namespace Content.Server.Atmos.Monitor.Systems;
|
||||||
{
|
|
||||||
public sealed class AtmosAlarmableSystem : EntitySystem
|
public sealed class AtmosAlarmableSystem : EntitySystem
|
||||||
{
|
{
|
||||||
[Dependency] private readonly AppearanceSystem _appearance = default!;
|
[Dependency] private readonly AppearanceSystem _appearance = default!;
|
||||||
@@ -304,4 +304,3 @@ namespace Content.Server.Atmos.Monitor.Systems
|
|||||||
AlarmType = netMax;
|
AlarmType = netMax;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -16,8 +16,8 @@ using Robust.Shared.Audio;
|
|||||||
using Robust.Shared.Player;
|
using Robust.Shared.Player;
|
||||||
using Robust.Shared.Prototypes;
|
using Robust.Shared.Prototypes;
|
||||||
|
|
||||||
namespace Content.Server.Atmos.Monitor.Systems
|
namespace Content.Server.Atmos.Monitor.Systems;
|
||||||
{
|
|
||||||
// AtmosMonitorSystem. Grabs all the AtmosAlarmables connected
|
// AtmosMonitorSystem. Grabs all the AtmosAlarmables connected
|
||||||
// to it via local APC net, and starts sending updates of the
|
// to it via local APC net, and starts sending updates of the
|
||||||
// current atmosphere. Monitors fire (which always triggers as
|
// current atmosphere. Monitors fire (which always triggers as
|
||||||
@@ -33,8 +33,6 @@ namespace Content.Server.Atmos.Monitor.Systems
|
|||||||
public const string AtmosMonitorSetThresholdCmd = "atmos_monitor_set_threshold";
|
public const string AtmosMonitorSetThresholdCmd = "atmos_monitor_set_threshold";
|
||||||
|
|
||||||
// Packet data
|
// Packet data
|
||||||
public const string AlertTypes = "atmos_monitor_alert_types";
|
|
||||||
|
|
||||||
public const string AtmosMonitorThresholdData = "atmos_monitor_threshold_data";
|
public const string AtmosMonitorThresholdData = "atmos_monitor_threshold_data";
|
||||||
|
|
||||||
public const string AtmosMonitorThresholdDataType = "atmos_monitor_threshold_type";
|
public const string AtmosMonitorThresholdDataType = "atmos_monitor_threshold_type";
|
||||||
@@ -380,4 +378,3 @@ namespace Content.Server.Atmos.Monitor.Systems
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ using Content.Shared.Interaction;
|
|||||||
using Content.Shared.Emag.Systems;
|
using Content.Shared.Emag.Systems;
|
||||||
using Robust.Server.GameObjects;
|
using Robust.Server.GameObjects;
|
||||||
|
|
||||||
namespace Content.Server.Atmos.Monitor.Systems
|
namespace Content.Server.Atmos.Monitor.Systems;
|
||||||
{
|
|
||||||
public sealed class FireAlarmSystem : EntitySystem
|
public sealed class FireAlarmSystem : EntitySystem
|
||||||
{
|
{
|
||||||
[Dependency] private readonly AtmosDeviceNetworkSystem _atmosDevNet = default!;
|
[Dependency] private readonly AtmosDeviceNetworkSystem _atmosDevNet = default!;
|
||||||
@@ -66,4 +66,3 @@ namespace Content.Server.Atmos.Monitor.Systems
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
270
Content.Shared/Atmos/Monitor/AtmosAlarmThreshold.cs
Normal file
270
Content.Shared/Atmos/Monitor/AtmosAlarmThreshold.cs
Normal file
@@ -0,0 +1,270 @@
|
|||||||
|
using Robust.Shared.Prototypes;
|
||||||
|
using Robust.Shared.Serialization;
|
||||||
|
|
||||||
|
namespace Content.Shared.Atmos.Monitor;
|
||||||
|
|
||||||
|
// mostly based around floats and percentages, no literals
|
||||||
|
// except for the range boundaries
|
||||||
|
[Prototype("alarmThreshold")]
|
||||||
|
[Serializable, NetSerializable]
|
||||||
|
public sealed class AtmosAlarmThreshold : IPrototype, ISerializationHooks
|
||||||
|
{
|
||||||
|
[IdDataFieldAttribute]
|
||||||
|
public string ID { get; } = default!;
|
||||||
|
[ViewVariables]
|
||||||
|
[DataField("ignore")]
|
||||||
|
public bool Ignore = false;
|
||||||
|
|
||||||
|
// zero bounds are not allowed - just
|
||||||
|
// set the bound to null if you want
|
||||||
|
// to disable it
|
||||||
|
[ViewVariables]
|
||||||
|
[DataField("upperBound")]
|
||||||
|
public float? UpperBound { get; private set; }
|
||||||
|
|
||||||
|
[ViewVariables]
|
||||||
|
[DataField("lowerBound")]
|
||||||
|
public float? LowerBound { get; private set; }
|
||||||
|
|
||||||
|
// upper warning percentage
|
||||||
|
// must always cause UpperWarningBound
|
||||||
|
// to be smaller
|
||||||
|
[ViewVariables]
|
||||||
|
[DataField("upperWarnAround")]
|
||||||
|
public float? UpperWarningPercentage { get; private set; }
|
||||||
|
|
||||||
|
// lower warning percentage
|
||||||
|
// must always cause LowerWarningBound
|
||||||
|
// to be larger
|
||||||
|
[ViewVariables]
|
||||||
|
[DataField("lowerWarnAround")]
|
||||||
|
public float? LowerWarningPercentage { get; private set; }
|
||||||
|
|
||||||
|
[ViewVariables]
|
||||||
|
public float? UpperWarningBound
|
||||||
|
{
|
||||||
|
get => CalculateWarningBound(AtmosMonitorThresholdBound.Upper);
|
||||||
|
}
|
||||||
|
|
||||||
|
[ViewVariables]
|
||||||
|
public float? LowerWarningBound
|
||||||
|
{
|
||||||
|
get => CalculateWarningBound(AtmosMonitorThresholdBound.Lower);
|
||||||
|
}
|
||||||
|
|
||||||
|
public AtmosAlarmThreshold()
|
||||||
|
{}
|
||||||
|
|
||||||
|
public AtmosAlarmThreshold(AtmosAlarmThreshold other)
|
||||||
|
{
|
||||||
|
Ignore = other.Ignore;
|
||||||
|
UpperBound = other.UpperBound;
|
||||||
|
LowerBound = other.LowerBound;
|
||||||
|
UpperWarningPercentage = other.UpperWarningPercentage;
|
||||||
|
LowerWarningPercentage = other.LowerWarningPercentage;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ISerializationHooks.AfterDeserialization()
|
||||||
|
{
|
||||||
|
if (UpperBound <= LowerBound)
|
||||||
|
UpperBound = null;
|
||||||
|
|
||||||
|
if (LowerBound >= UpperBound)
|
||||||
|
LowerBound = null;
|
||||||
|
|
||||||
|
if (UpperWarningPercentage != null)
|
||||||
|
TrySetWarningBound(AtmosMonitorThresholdBound.Upper, UpperBound * UpperWarningPercentage);
|
||||||
|
|
||||||
|
if (LowerWarningPercentage != null)
|
||||||
|
TrySetWarningBound(AtmosMonitorThresholdBound.Lower, LowerBound * LowerWarningPercentage);
|
||||||
|
}
|
||||||
|
|
||||||
|
// utility function to check a threshold against some calculated value
|
||||||
|
public bool CheckThreshold(float value, out AtmosMonitorAlarmType state)
|
||||||
|
{
|
||||||
|
state = AtmosMonitorAlarmType.Normal;
|
||||||
|
if (Ignore) return false;
|
||||||
|
|
||||||
|
if (value >= UpperBound || value <= LowerBound)
|
||||||
|
{
|
||||||
|
state = AtmosMonitorAlarmType.Danger;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (value >= UpperWarningBound || value <= LowerWarningBound)
|
||||||
|
{
|
||||||
|
state = AtmosMonitorAlarmType.Warning;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// set the primary bound, takes a hard value
|
||||||
|
public bool TrySetPrimaryBound(AtmosMonitorThresholdBound bound, float? input)
|
||||||
|
{
|
||||||
|
if (input == null)
|
||||||
|
{
|
||||||
|
switch (bound)
|
||||||
|
{
|
||||||
|
case AtmosMonitorThresholdBound.Upper:
|
||||||
|
UpperBound = null;
|
||||||
|
break;
|
||||||
|
case AtmosMonitorThresholdBound.Lower:
|
||||||
|
LowerBound = null;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
float value = (float) input;
|
||||||
|
|
||||||
|
if (value <= 0f || float.IsNaN(value))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
(float target, int compare)? targetValue = null;
|
||||||
|
switch (bound)
|
||||||
|
{
|
||||||
|
case AtmosMonitorThresholdBound.Upper:
|
||||||
|
if (float.IsPositiveInfinity(value))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (LowerBound != null)
|
||||||
|
targetValue = ((float) LowerBound, -1);
|
||||||
|
break;
|
||||||
|
case AtmosMonitorThresholdBound.Lower:
|
||||||
|
if (float.IsNegativeInfinity(value))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (UpperBound != null)
|
||||||
|
targetValue = ((float) UpperBound, 1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isValid = true;
|
||||||
|
if (targetValue != null)
|
||||||
|
{
|
||||||
|
var result = targetValue.Value.target.CompareTo(value);
|
||||||
|
isValid = targetValue.Value.compare == result;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isValid)
|
||||||
|
{
|
||||||
|
switch (bound)
|
||||||
|
{
|
||||||
|
case AtmosMonitorThresholdBound.Upper:
|
||||||
|
UpperBound = value;
|
||||||
|
return true;
|
||||||
|
case AtmosMonitorThresholdBound.Lower:
|
||||||
|
LowerBound = value;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// set the warning bound, takes a hard value
|
||||||
|
//
|
||||||
|
// this will always set the percentage and
|
||||||
|
// the raw value at the same time
|
||||||
|
public bool TrySetWarningBound(AtmosMonitorThresholdBound bound, float? input)
|
||||||
|
{
|
||||||
|
if (input == null)
|
||||||
|
{
|
||||||
|
switch (bound)
|
||||||
|
{
|
||||||
|
case AtmosMonitorThresholdBound.Upper:
|
||||||
|
UpperWarningPercentage = null;
|
||||||
|
break;
|
||||||
|
case AtmosMonitorThresholdBound.Lower:
|
||||||
|
LowerWarningPercentage = null;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (bound)
|
||||||
|
{
|
||||||
|
case AtmosMonitorThresholdBound.Upper:
|
||||||
|
if (UpperBound == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
float upperWarning = (float) (input / UpperBound);
|
||||||
|
float upperTestValue = (upperWarning * (float) UpperBound);
|
||||||
|
|
||||||
|
if (upperWarning > 1f
|
||||||
|
|| upperTestValue < LowerWarningBound
|
||||||
|
|| upperTestValue < LowerBound)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
UpperWarningPercentage = upperWarning;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
case AtmosMonitorThresholdBound.Lower:
|
||||||
|
if (LowerBound == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
float lowerWarning = (float) (input / LowerBound);
|
||||||
|
float testValue = (lowerWarning * (float) LowerBound);
|
||||||
|
|
||||||
|
if (lowerWarning < 1f
|
||||||
|
|| testValue > UpperWarningBound
|
||||||
|
|| testValue > UpperBound)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
LowerWarningPercentage = lowerWarning;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float? CalculateWarningBound(AtmosMonitorThresholdBound bound)
|
||||||
|
{
|
||||||
|
float? value = null;
|
||||||
|
|
||||||
|
switch (bound)
|
||||||
|
{
|
||||||
|
case AtmosMonitorThresholdBound.Upper:
|
||||||
|
if (UpperBound == null || UpperWarningPercentage == null)
|
||||||
|
break;
|
||||||
|
|
||||||
|
value = UpperBound * UpperWarningPercentage;
|
||||||
|
break;
|
||||||
|
case AtmosMonitorThresholdBound.Lower:
|
||||||
|
if (LowerBound == null || LowerWarningPercentage == null)
|
||||||
|
break;
|
||||||
|
|
||||||
|
value = LowerBound * LowerWarningPercentage;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum AtmosMonitorThresholdBound
|
||||||
|
{
|
||||||
|
Upper,
|
||||||
|
Lower
|
||||||
|
}
|
||||||
|
|
||||||
|
// not really used in the prototype but in code,
|
||||||
|
// to differentiate between the different
|
||||||
|
// fields you can find this prototype in
|
||||||
|
public enum AtmosMonitorThresholdType
|
||||||
|
{
|
||||||
|
Temperature,
|
||||||
|
Pressure,
|
||||||
|
Gas
|
||||||
|
}
|
||||||
|
|
||||||
|
[Serializable, NetSerializable]
|
||||||
|
public enum AtmosMonitorVisuals : byte
|
||||||
|
{
|
||||||
|
Offset,
|
||||||
|
AlarmType,
|
||||||
|
}
|
||||||
@@ -1,271 +0,0 @@
|
|||||||
using Robust.Shared.Prototypes;
|
|
||||||
using Robust.Shared.Serialization;
|
|
||||||
|
|
||||||
namespace Content.Shared.Atmos.Monitor
|
|
||||||
{
|
|
||||||
// mostly based around floats and percentages, no literals
|
|
||||||
// except for the range boundaries
|
|
||||||
[Prototype("alarmThreshold")]
|
|
||||||
[Serializable, NetSerializable]
|
|
||||||
public sealed class AtmosAlarmThreshold : IPrototype, ISerializationHooks
|
|
||||||
{
|
|
||||||
[IdDataFieldAttribute]
|
|
||||||
public string ID { get; } = default!;
|
|
||||||
[ViewVariables]
|
|
||||||
[DataField("ignore")]
|
|
||||||
public bool Ignore = false;
|
|
||||||
|
|
||||||
// zero bounds are not allowed - just
|
|
||||||
// set the bound to null if you want
|
|
||||||
// to disable it
|
|
||||||
[ViewVariables]
|
|
||||||
[DataField("upperBound")]
|
|
||||||
public float? UpperBound { get; private set; }
|
|
||||||
|
|
||||||
[ViewVariables]
|
|
||||||
[DataField("lowerBound")]
|
|
||||||
public float? LowerBound { get; private set; }
|
|
||||||
|
|
||||||
// upper warning percentage
|
|
||||||
// must always cause UpperWarningBound
|
|
||||||
// to be smaller
|
|
||||||
[ViewVariables]
|
|
||||||
[DataField("upperWarnAround")]
|
|
||||||
public float? UpperWarningPercentage { get; private set; }
|
|
||||||
|
|
||||||
// lower warning percentage
|
|
||||||
// must always cause LowerWarningBound
|
|
||||||
// to be larger
|
|
||||||
[ViewVariables]
|
|
||||||
[DataField("lowerWarnAround")]
|
|
||||||
public float? LowerWarningPercentage { get; private set; }
|
|
||||||
|
|
||||||
[ViewVariables]
|
|
||||||
public float? UpperWarningBound
|
|
||||||
{
|
|
||||||
get => CalculateWarningBound(AtmosMonitorThresholdBound.Upper);
|
|
||||||
}
|
|
||||||
|
|
||||||
[ViewVariables]
|
|
||||||
public float? LowerWarningBound
|
|
||||||
{
|
|
||||||
get => CalculateWarningBound(AtmosMonitorThresholdBound.Lower);
|
|
||||||
}
|
|
||||||
|
|
||||||
public AtmosAlarmThreshold()
|
|
||||||
{}
|
|
||||||
|
|
||||||
public AtmosAlarmThreshold(AtmosAlarmThreshold other)
|
|
||||||
{
|
|
||||||
Ignore = other.Ignore;
|
|
||||||
UpperBound = other.UpperBound;
|
|
||||||
LowerBound = other.LowerBound;
|
|
||||||
UpperWarningPercentage = other.UpperWarningPercentage;
|
|
||||||
LowerWarningPercentage = other.LowerWarningPercentage;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ISerializationHooks.AfterDeserialization()
|
|
||||||
{
|
|
||||||
if (UpperBound <= LowerBound)
|
|
||||||
UpperBound = null;
|
|
||||||
|
|
||||||
if (LowerBound >= UpperBound)
|
|
||||||
LowerBound = null;
|
|
||||||
|
|
||||||
if (UpperWarningPercentage != null)
|
|
||||||
TrySetWarningBound(AtmosMonitorThresholdBound.Upper, UpperBound * UpperWarningPercentage);
|
|
||||||
|
|
||||||
if (LowerWarningPercentage != null)
|
|
||||||
TrySetWarningBound(AtmosMonitorThresholdBound.Lower, LowerBound * LowerWarningPercentage);
|
|
||||||
}
|
|
||||||
|
|
||||||
// utility function to check a threshold against some calculated value
|
|
||||||
public bool CheckThreshold(float value, out AtmosMonitorAlarmType state)
|
|
||||||
{
|
|
||||||
state = AtmosMonitorAlarmType.Normal;
|
|
||||||
if (Ignore) return false;
|
|
||||||
|
|
||||||
if (value >= UpperBound || value <= LowerBound)
|
|
||||||
{
|
|
||||||
state = AtmosMonitorAlarmType.Danger;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (value >= UpperWarningBound || value <= LowerWarningBound)
|
|
||||||
{
|
|
||||||
state = AtmosMonitorAlarmType.Warning;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// set the primary bound, takes a hard value
|
|
||||||
public bool TrySetPrimaryBound(AtmosMonitorThresholdBound bound, float? input)
|
|
||||||
{
|
|
||||||
if (input == null)
|
|
||||||
{
|
|
||||||
switch (bound)
|
|
||||||
{
|
|
||||||
case AtmosMonitorThresholdBound.Upper:
|
|
||||||
UpperBound = null;
|
|
||||||
break;
|
|
||||||
case AtmosMonitorThresholdBound.Lower:
|
|
||||||
LowerBound = null;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
float value = (float) input;
|
|
||||||
|
|
||||||
if (value <= 0f || float.IsNaN(value))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
(float target, int compare)? targetValue = null;
|
|
||||||
switch (bound)
|
|
||||||
{
|
|
||||||
case AtmosMonitorThresholdBound.Upper:
|
|
||||||
if (float.IsPositiveInfinity(value))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (LowerBound != null)
|
|
||||||
targetValue = ((float) LowerBound, -1);
|
|
||||||
break;
|
|
||||||
case AtmosMonitorThresholdBound.Lower:
|
|
||||||
if (float.IsNegativeInfinity(value))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (UpperBound != null)
|
|
||||||
targetValue = ((float) UpperBound, 1);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isValid = true;
|
|
||||||
if (targetValue != null)
|
|
||||||
{
|
|
||||||
var result = targetValue.Value.target.CompareTo(value);
|
|
||||||
isValid = targetValue.Value.compare == result;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isValid)
|
|
||||||
{
|
|
||||||
switch (bound)
|
|
||||||
{
|
|
||||||
case AtmosMonitorThresholdBound.Upper:
|
|
||||||
UpperBound = value;
|
|
||||||
return true;
|
|
||||||
case AtmosMonitorThresholdBound.Lower:
|
|
||||||
LowerBound = value;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// set the warning bound, takes a hard value
|
|
||||||
//
|
|
||||||
// this will always set the percentage and
|
|
||||||
// the raw value at the same time
|
|
||||||
public bool TrySetWarningBound(AtmosMonitorThresholdBound bound, float? input)
|
|
||||||
{
|
|
||||||
if (input == null)
|
|
||||||
{
|
|
||||||
switch (bound)
|
|
||||||
{
|
|
||||||
case AtmosMonitorThresholdBound.Upper:
|
|
||||||
UpperWarningPercentage = null;
|
|
||||||
break;
|
|
||||||
case AtmosMonitorThresholdBound.Lower:
|
|
||||||
LowerWarningPercentage = null;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (bound)
|
|
||||||
{
|
|
||||||
case AtmosMonitorThresholdBound.Upper:
|
|
||||||
if (UpperBound == null)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
float upperWarning = (float) (input / UpperBound);
|
|
||||||
float upperTestValue = (upperWarning * (float) UpperBound);
|
|
||||||
|
|
||||||
if (upperWarning > 1f
|
|
||||||
|| upperTestValue < LowerWarningBound
|
|
||||||
|| upperTestValue < LowerBound)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
UpperWarningPercentage = upperWarning;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
case AtmosMonitorThresholdBound.Lower:
|
|
||||||
if (LowerBound == null)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
float lowerWarning = (float) (input / LowerBound);
|
|
||||||
float testValue = (lowerWarning * (float) LowerBound);
|
|
||||||
|
|
||||||
if (lowerWarning < 1f
|
|
||||||
|| testValue > UpperWarningBound
|
|
||||||
|| testValue > UpperBound)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
LowerWarningPercentage = lowerWarning;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float? CalculateWarningBound(AtmosMonitorThresholdBound bound)
|
|
||||||
{
|
|
||||||
float? value = null;
|
|
||||||
|
|
||||||
switch (bound)
|
|
||||||
{
|
|
||||||
case AtmosMonitorThresholdBound.Upper:
|
|
||||||
if (UpperBound == null || UpperWarningPercentage == null)
|
|
||||||
break;
|
|
||||||
|
|
||||||
value = UpperBound * UpperWarningPercentage;
|
|
||||||
break;
|
|
||||||
case AtmosMonitorThresholdBound.Lower:
|
|
||||||
if (LowerBound == null || LowerWarningPercentage == null)
|
|
||||||
break;
|
|
||||||
|
|
||||||
value = LowerBound * LowerWarningPercentage;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum AtmosMonitorThresholdBound
|
|
||||||
{
|
|
||||||
Upper,
|
|
||||||
Lower
|
|
||||||
}
|
|
||||||
|
|
||||||
// not really used in the prototype but in code,
|
|
||||||
// to differentiate between the different
|
|
||||||
// fields you can find this prototype in
|
|
||||||
public enum AtmosMonitorThresholdType
|
|
||||||
{
|
|
||||||
Temperature,
|
|
||||||
Pressure,
|
|
||||||
Gas
|
|
||||||
}
|
|
||||||
|
|
||||||
[Serializable, NetSerializable]
|
|
||||||
public enum AtmosMonitorVisuals : byte
|
|
||||||
{
|
|
||||||
Offset,
|
|
||||||
AlarmType,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
using Robust.Shared.Serialization;
|
using Robust.Shared.Serialization;
|
||||||
|
|
||||||
namespace Content.Shared.Atmos.Monitor
|
namespace Content.Shared.Atmos.Monitor;
|
||||||
{
|
|
||||||
[Serializable, NetSerializable]
|
[Serializable, NetSerializable]
|
||||||
public enum AtmosMonitorAlarmType : sbyte
|
public enum AtmosMonitorAlarmType : sbyte
|
||||||
{
|
{
|
||||||
@@ -10,4 +10,3 @@ namespace Content.Shared.Atmos.Monitor
|
|||||||
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,
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using Robust.Shared.Serialization;
|
using Robust.Shared.Serialization;
|
||||||
|
|
||||||
namespace Content.Shared.Atmos.Monitor.Components
|
namespace Content.Shared.Atmos.Monitor.Components;
|
||||||
{
|
|
||||||
[Serializable, NetSerializable]
|
[Serializable, NetSerializable]
|
||||||
public enum SharedAirAlarmInterfaceKey
|
public enum SharedAirAlarmInterfaceKey
|
||||||
{
|
{
|
||||||
@@ -128,4 +128,3 @@ namespace Content.Shared.Atmos.Monitor.Components
|
|||||||
Sensors,
|
Sensors,
|
||||||
Settings
|
Settings
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
using Robust.Shared.Serialization;
|
using Robust.Shared.Serialization;
|
||||||
|
|
||||||
namespace Content.Shared.Atmos.Monitor.Components
|
namespace Content.Shared.Atmos.Monitor.Components;
|
||||||
{
|
|
||||||
[Serializable, NetSerializable]
|
[Serializable, NetSerializable]
|
||||||
public enum FireAlarmWireStatus
|
public enum FireAlarmWireStatus
|
||||||
{
|
{
|
||||||
Power,
|
Power,
|
||||||
Alarm
|
Alarm
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user