file-scoped namespaces

This commit is contained in:
vulppine
2022-08-23 10:55:46 -07:00
parent df25715ed3
commit b3a4ef9997
20 changed files with 2503 additions and 2525 deletions

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

View File

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

View File

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

View File

@@ -1,131 +1,130 @@
using Robust.Shared.Serialization;
namespace Content.Shared.Atmos.Monitor.Components
namespace Content.Shared.Atmos.Monitor.Components;
[Serializable, NetSerializable]
public enum SharedAirAlarmInterfaceKey
{
[Serializable, NetSerializable]
public enum SharedAirAlarmInterfaceKey
Key
}
[Serializable, NetSerializable]
public enum AirAlarmMode
{
None,
Filtering,
Fill,
Panic,
Replace
}
[Serializable, NetSerializable]
public enum AirAlarmWireStatus
{
Power,
Access,
Panic,
DeviceSync
}
public interface IAtmosDeviceData
{
public bool Enabled { get; set; }
public bool Dirty { get; set; }
public bool IgnoreAlarms { get; set; }
}
[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)
{
Key
Address = address;
DeviceCount = deviceCount;
PressureAverage = pressureAverage;
TemperatureAverage = temperatureAverage;
DeviceData = deviceData;
Mode = mode;
Tab = tab;
AlarmType = alarmType;
}
[Serializable, NetSerializable]
public enum AirAlarmMode
public string Address { get; }
public int DeviceCount { get; }
public float PressureAverage { get; }
public float TemperatureAverage { get; }
/// <summary>
/// Every single device data that can be seen from this
/// air alarm. This includes vents, scrubbers, and sensors.
/// The device data you get, however, depends on the current
/// selected tab.
/// </summary>
public Dictionary<string, IAtmosDeviceData> DeviceData { get; }
public AirAlarmMode Mode { get; }
public AirAlarmTab Tab { get; }
public AtmosMonitorAlarmType AlarmType { get; }
}
[Serializable, NetSerializable]
public sealed class AirAlarmTabSetMessage : BoundUserInterfaceMessage
{
public AirAlarmTabSetMessage(AirAlarmTab tab)
{
None,
Filtering,
Fill,
Panic,
Replace
Tab = tab;
}
[Serializable, NetSerializable]
public enum AirAlarmWireStatus
public AirAlarmTab Tab { get; }
}
[Serializable, NetSerializable]
public sealed class AirAlarmResyncAllDevicesMessage : BoundUserInterfaceMessage
{}
[Serializable, NetSerializable]
public sealed class AirAlarmUpdateAlarmModeMessage : BoundUserInterfaceMessage
{
public AirAlarmMode Mode { get; }
public AirAlarmUpdateAlarmModeMessage(AirAlarmMode mode)
{
Power,
Access,
Panic,
DeviceSync
}
public interface IAtmosDeviceData
{
public bool Enabled { get; set; }
public bool Dirty { get; set; }
public bool IgnoreAlarms { get; set; }
}
[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)
{
Address = address;
DeviceCount = deviceCount;
PressureAverage = pressureAverage;
TemperatureAverage = temperatureAverage;
DeviceData = deviceData;
Mode = mode;
Tab = tab;
AlarmType = alarmType;
}
public string Address { get; }
public int DeviceCount { get; }
public float PressureAverage { get; }
public float TemperatureAverage { get; }
/// <summary>
/// Every single device data that can be seen from this
/// air alarm. This includes vents, scrubbers, and sensors.
/// The device data you get, however, depends on the current
/// selected tab.
/// </summary>
public Dictionary<string, IAtmosDeviceData> DeviceData { get; }
public AirAlarmMode Mode { get; }
public AirAlarmTab Tab { get; }
public AtmosMonitorAlarmType AlarmType { get; }
}
[Serializable, NetSerializable]
public sealed class AirAlarmTabSetMessage : BoundUserInterfaceMessage
{
public AirAlarmTabSetMessage(AirAlarmTab tab)
{
Tab = tab;
}
public AirAlarmTab Tab { get; }
}
[Serializable, NetSerializable]
public sealed class AirAlarmResyncAllDevicesMessage : BoundUserInterfaceMessage
{}
[Serializable, NetSerializable]
public sealed class AirAlarmUpdateAlarmModeMessage : BoundUserInterfaceMessage
{
public AirAlarmMode Mode { get; }
public AirAlarmUpdateAlarmModeMessage(AirAlarmMode mode)
{
Mode = mode;
}
}
[Serializable, NetSerializable]
public sealed class AirAlarmUpdateDeviceDataMessage : BoundUserInterfaceMessage
{
public string Address { get; }
public IAtmosDeviceData Data { get; }
public AirAlarmUpdateDeviceDataMessage(string addr, IAtmosDeviceData data)
{
Address = addr;
Data = data;
}
}
[Serializable, NetSerializable]
public sealed class AirAlarmUpdateAlarmThresholdMessage : BoundUserInterfaceMessage
{
public string Address { get; }
public AtmosAlarmThreshold Threshold { get; }
public AtmosMonitorThresholdType Type { get; }
public Gas? Gas { get; }
public AirAlarmUpdateAlarmThresholdMessage(string address, AtmosMonitorThresholdType type, AtmosAlarmThreshold threshold, Gas? gas = null)
{
Address = address;
Threshold = threshold;
Type = type;
Gas = gas;
}
}
public enum AirAlarmTab
{
Vent,
Scrubber,
Sensors,
Settings
Mode = mode;
}
}
[Serializable, NetSerializable]
public sealed class AirAlarmUpdateDeviceDataMessage : BoundUserInterfaceMessage
{
public string Address { get; }
public IAtmosDeviceData Data { get; }
public AirAlarmUpdateDeviceDataMessage(string addr, IAtmosDeviceData data)
{
Address = addr;
Data = data;
}
}
[Serializable, NetSerializable]
public sealed class AirAlarmUpdateAlarmThresholdMessage : BoundUserInterfaceMessage
{
public string Address { get; }
public AtmosAlarmThreshold Threshold { get; }
public AtmosMonitorThresholdType Type { get; }
public Gas? Gas { get; }
public AirAlarmUpdateAlarmThresholdMessage(string address, AtmosMonitorThresholdType type, AtmosAlarmThreshold threshold, Gas? gas = null)
{
Address = address;
Threshold = threshold;
Type = type;
Gas = gas;
}
}
public enum AirAlarmTab
{
Vent,
Scrubber,
Sensors,
Settings
}

View File

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