GasVentScrubberComponent.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using System.Linq;
  2. using Content.Server.Atmos.Piping.Unary.EntitySystems;
  3. using Content.Shared.Atmos;
  4. using Content.Shared.Atmos.Piping.Unary.Components;
  5. namespace Content.Server.Atmos.Piping.Unary.Components
  6. {
  7. [RegisterComponent]
  8. [Access(typeof(GasVentScrubberSystem))]
  9. public sealed partial class GasVentScrubberComponent : Component
  10. {
  11. /// <summary>
  12. /// Identifies if the device is enabled by an air alarm. Does not indicate if the device is powered.
  13. /// By default, all air scrubbers start enabled, whether linked to an alarm or not.
  14. /// </summary>
  15. [DataField]
  16. public bool Enabled { get; set; } = true;
  17. [DataField]
  18. public bool IsDirty { get; set; } = false;
  19. [DataField("outlet")]
  20. public string OutletName { get; set; } = "pipe";
  21. [DataField]
  22. public HashSet<Gas> FilterGases = new(GasVentScrubberData.DefaultFilterGases);
  23. [DataField]
  24. public ScrubberPumpDirection PumpDirection { get; set; } = ScrubberPumpDirection.Scrubbing;
  25. /// <summary>
  26. /// Target volume to transfer. If <see cref="WideNet"/> is enabled, actual transfer rate will be much higher.
  27. /// </summary>
  28. [DataField]
  29. public float TransferRate
  30. {
  31. get => _transferRate;
  32. set => _transferRate = Math.Clamp(value, 0f, MaxTransferRate);
  33. }
  34. private float _transferRate = Atmospherics.MaxTransferRate;
  35. [DataField]
  36. public float MaxTransferRate = Atmospherics.MaxTransferRate;
  37. /// <summary>
  38. /// As pressure difference approaches this number, the effective volume rate may be smaller than <see
  39. /// cref="TransferRate"/>
  40. /// </summary>
  41. [DataField]
  42. public float MaxPressure = Atmospherics.MaxOutputPressure;
  43. [DataField]
  44. public bool WideNet { get; set; } = false;
  45. public GasVentScrubberData ToAirAlarmData()
  46. {
  47. return new GasVentScrubberData
  48. {
  49. Enabled = Enabled,
  50. Dirty = IsDirty,
  51. FilterGases = FilterGases,
  52. PumpDirection = PumpDirection,
  53. VolumeRate = TransferRate,
  54. WideNet = WideNet
  55. };
  56. }
  57. public void FromAirAlarmData(GasVentScrubberData data)
  58. {
  59. Enabled = data.Enabled;
  60. IsDirty = data.Dirty;
  61. PumpDirection = data.PumpDirection;
  62. TransferRate = data.VolumeRate;
  63. WideNet = data.WideNet;
  64. if (!data.FilterGases.SequenceEqual(FilterGases))
  65. {
  66. FilterGases.Clear();
  67. foreach (var gas in data.FilterGases)
  68. FilterGases.Add(gas);
  69. }
  70. }
  71. }
  72. }