1
0

SharedApc.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. using Robust.Shared.Serialization;
  2. namespace Content.Shared.APC
  3. {
  4. [Serializable, NetSerializable]
  5. public enum ApcVisuals : byte
  6. {
  7. /// <summary>
  8. /// APC locks.
  9. /// </summary>
  10. LockState,
  11. /// <summary>
  12. /// APC channels.
  13. /// </summary>
  14. ChannelState,
  15. /// <summary>
  16. /// APC lights/HUD.
  17. /// </summary>
  18. ChargeState,
  19. }
  20. [Serializable, NetSerializable]
  21. public enum ApcPanelState : sbyte
  22. {
  23. /// <summary>
  24. /// APC is closed.
  25. /// </summary>
  26. Closed = 0,
  27. /// <summary>
  28. /// APC is opened.
  29. /// </summary>
  30. Open = 1,
  31. /// <summary>
  32. /// APC is oaisdoj.
  33. /// </summary>
  34. Error = -1,
  35. }
  36. /// <summary>
  37. /// The state of the APC interface lock.
  38. /// None of this is implemented.
  39. /// </summary>
  40. [Serializable, NetSerializable]
  41. public enum ApcLockState : sbyte
  42. {
  43. /// <summary>
  44. /// Empty bitmask.
  45. /// </summary>
  46. None = 0,
  47. /// <summary>
  48. /// Bitfield indicating status of APC lock indicator.
  49. /// </summary>
  50. Lock = (1<<0),
  51. /// <summary>
  52. /// Bit state indicating that the given APC lock is unlocked.
  53. /// </summary>
  54. Unlocked = None,
  55. /// <summary>
  56. /// Bit state indicating that the given APC lock is locked.
  57. /// </summary>
  58. Locked = (1<<0),
  59. /// <summary>
  60. /// Bitmask for the full state for a given APC lock indicator.
  61. /// </summary>
  62. All = (Lock),
  63. /// <summary>
  64. /// The log 2 width in bits of the bitfields indicating the status of an APC lock indicator.
  65. /// Used for bit shifting operations (Mask for the state for indicator i is (All << (i << LogWidth))).
  66. /// </summary>
  67. LogWidth = 0,
  68. }
  69. /// <summary>
  70. /// APC power channel states.
  71. /// None of this is implemented.
  72. /// </summary>
  73. public enum ApcChannelState : sbyte
  74. {
  75. /// <summary>
  76. /// Empty bitmask.
  77. /// </summary>
  78. None = 0,
  79. /// <summary>
  80. /// Bitfield indicating whether the APC is automatically regulating the given channel.
  81. /// </summary>
  82. Control = (1<<0),
  83. /// <summary>
  84. /// Bit state indicating that the APC has been set to automatically toggle the given channel depending on available power.
  85. /// </summary>
  86. Auto = None,
  87. /// <summary>
  88. /// Bit state indicating that the APC has been set to always provide/not provide power on the given channel if possible.
  89. /// </summary>
  90. Manual = Control,
  91. /// <summary>
  92. /// Bitfield indicating whether the APC is currently providing power on the given channel.
  93. /// </summary>
  94. Power = (1<<1),
  95. /// <summary>
  96. /// Bit state indicating that the APC is currently not providing power on the given channel.
  97. /// </summary>
  98. Off = None,
  99. /// <summary>
  100. /// Bit state indicating that the APC is currently providing power on the given channel.
  101. /// </summary>
  102. On = Power,
  103. /// <summary>
  104. /// Bitmask for the full state for a given APC power channel.
  105. /// </summary>
  106. All = Power | Control,
  107. /// <summary>
  108. /// State that indicates the given channel has been automatically disabled.
  109. /// </summary>
  110. AutoOff = (Off | Auto),
  111. /// <summary>
  112. /// State that indicates the given channel has been automatically enabled.
  113. /// </summary>
  114. AutoOn = (On | Auto),
  115. /// <summary>
  116. /// State that indicates the given channel has been manually disabled.
  117. /// </summary>
  118. ManualOff = (Off | Manual),
  119. /// <summary>
  120. /// State that indicates the given channel has been manually enabled.
  121. /// </summary>
  122. ManualOn = (On | Manual),
  123. /// <summary>
  124. /// The log 2 width in bits of the bitfields indicating the status of an APC power channel.
  125. /// Used for bit shifting operations (Mask for the state for channel i is (All << (i << LogWidth))).
  126. /// </summary>
  127. LogWidth = 1,
  128. }
  129. [Serializable, NetSerializable]
  130. public enum ApcChargeState : sbyte
  131. {
  132. /// <summary>
  133. /// APC does not have enough power to charge cell (if necessary) and keep powering the area.
  134. /// </summary>
  135. Lack = 0,
  136. /// <summary>
  137. /// APC is not full but has enough power.
  138. /// </summary>
  139. Charging = 1,
  140. /// <summary>
  141. /// APC battery is full and has enough power.
  142. /// </summary>
  143. Full = 2,
  144. /// <summary>
  145. /// APC is being remotely accessed.
  146. /// Currently unimplemented, though the corresponding sprite state exists in the RSI.
  147. /// </summary>
  148. Remote = 3,
  149. /// <summary>
  150. /// The number of valid states charge states the APC can be in.
  151. /// </summary>
  152. NumStates = 4,
  153. /// <summary>
  154. /// APC is emagged (and not displaying other useful power colors at a glance)
  155. /// </summary>
  156. Emag = -1,
  157. }
  158. [Serializable, NetSerializable]
  159. public sealed class ApcBoundInterfaceState : BoundUserInterfaceState, IEquatable<ApcBoundInterfaceState>
  160. {
  161. public readonly bool MainBreaker;
  162. public readonly int Power;
  163. public readonly ApcExternalPowerState ApcExternalPower;
  164. public readonly float Charge;
  165. public ApcBoundInterfaceState(bool mainBreaker, int power, ApcExternalPowerState apcExternalPower, float charge)
  166. {
  167. MainBreaker = mainBreaker;
  168. Power = power;
  169. ApcExternalPower = apcExternalPower;
  170. Charge = charge;
  171. }
  172. public bool Equals(ApcBoundInterfaceState? other)
  173. {
  174. if (ReferenceEquals(null, other)) return false;
  175. if (ReferenceEquals(this, other)) return true;
  176. return MainBreaker == other.MainBreaker &&
  177. Power == other.Power &&
  178. ApcExternalPower == other.ApcExternalPower &&
  179. MathHelper.CloseTo(Charge, other.Charge);
  180. }
  181. public override bool Equals(object? obj)
  182. {
  183. return ReferenceEquals(this, obj) || obj is ApcBoundInterfaceState other && Equals(other);
  184. }
  185. public override int GetHashCode()
  186. {
  187. return HashCode.Combine(MainBreaker, Power, (int) ApcExternalPower, Charge);
  188. }
  189. }
  190. [Serializable, NetSerializable]
  191. public sealed class ApcToggleMainBreakerMessage : BoundUserInterfaceMessage
  192. {
  193. }
  194. public enum ApcExternalPowerState : byte
  195. {
  196. None,
  197. Low,
  198. Good,
  199. }
  200. [NetSerializable, Serializable]
  201. public enum ApcUiKey : byte
  202. {
  203. Key,
  204. }
  205. }