AtmosMonitoringConsoleComponent.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. using Content.Shared.Atmos.Consoles;
  2. using Content.Shared.Pinpointer;
  3. using Content.Shared.Prototypes;
  4. using Robust.Shared.GameStates;
  5. using Robust.Shared.Map;
  6. using Robust.Shared.Prototypes;
  7. using Robust.Shared.Serialization;
  8. using Robust.Shared.Timing;
  9. namespace Content.Shared.Atmos.Components;
  10. /// <summary>
  11. /// Entities capable of opening the atmos monitoring console UI
  12. /// require this component to function correctly
  13. /// </summary>
  14. [RegisterComponent, NetworkedComponent]
  15. [Access(typeof(SharedAtmosMonitoringConsoleSystem))]
  16. public sealed partial class AtmosMonitoringConsoleComponent : Component
  17. {
  18. /*
  19. * Don't need DataFields as this can be reconstructed
  20. */
  21. /// <summary>
  22. /// A dictionary of the all the nav map chunks that contain anchored atmos pipes
  23. /// </summary>
  24. [ViewVariables]
  25. public Dictionary<Vector2i, AtmosPipeChunk> AtmosPipeChunks = new();
  26. /// <summary>
  27. /// A list of all the atmos devices that will be used to populate the nav map
  28. /// </summary>
  29. [ViewVariables]
  30. public Dictionary<NetEntity, AtmosDeviceNavMapData> AtmosDevices = new();
  31. /// <summary>
  32. /// Color of the floor tiles on the nav map screen
  33. /// </summary>
  34. [DataField, ViewVariables]
  35. public Color NavMapTileColor;
  36. /// <summary>
  37. /// Color of the wall lines on the nav map screen
  38. /// </summary>
  39. [DataField, ViewVariables]
  40. public Color NavMapWallColor;
  41. /// <summary>
  42. /// The next time this component is dirtied, it will force the full state
  43. /// to be sent to the client, instead of just the delta state
  44. /// </summary>
  45. [ViewVariables]
  46. public bool ForceFullUpdate = false;
  47. }
  48. [Serializable, NetSerializable]
  49. public struct AtmosPipeChunk(Vector2i origin)
  50. {
  51. /// <summary>
  52. /// Chunk position
  53. /// </summary>
  54. [ViewVariables]
  55. public readonly Vector2i Origin = origin;
  56. /// <summary>
  57. /// Bitmask look up for atmos pipes, 1 for occupied and 0 for empty.
  58. /// Indexed by the color hexcode of the pipe
  59. /// </summary>
  60. [ViewVariables]
  61. public Dictionary<(int, string), ulong> AtmosPipeData = new();
  62. /// <summary>
  63. /// The last game tick that the chunk was updated
  64. /// </summary>
  65. [NonSerialized]
  66. public GameTick LastUpdate;
  67. }
  68. [Serializable, NetSerializable]
  69. public struct AtmosDeviceNavMapData
  70. {
  71. /// <summary>
  72. /// The entity in question
  73. /// </summary>
  74. public NetEntity NetEntity;
  75. /// <summary>
  76. /// Location of the entity
  77. /// </summary>
  78. public NetCoordinates NetCoordinates;
  79. /// <summary>
  80. /// The associated pipe network ID
  81. /// </summary>
  82. public int NetId = -1;
  83. /// <summary>
  84. /// Prototype ID for the nav map blip
  85. /// </summary>
  86. public ProtoId<NavMapBlipPrototype> NavMapBlip;
  87. /// <summary>
  88. /// Direction of the entity
  89. /// </summary>
  90. public Direction Direction;
  91. /// <summary>
  92. /// Color of the attached pipe
  93. /// </summary>
  94. public Color PipeColor;
  95. /// <summary>
  96. /// Populate the atmos monitoring console nav map with a single entity
  97. /// </summary>
  98. public AtmosDeviceNavMapData(NetEntity netEntity, NetCoordinates netCoordinates, int netId, ProtoId<NavMapBlipPrototype> navMapBlip, Direction direction, Color pipeColor)
  99. {
  100. NetEntity = netEntity;
  101. NetCoordinates = netCoordinates;
  102. NetId = netId;
  103. NavMapBlip = navMapBlip;
  104. Direction = direction;
  105. PipeColor = pipeColor;
  106. }
  107. }
  108. [Serializable, NetSerializable]
  109. public sealed class AtmosMonitoringConsoleBoundInterfaceState : BoundUserInterfaceState
  110. {
  111. /// <summary>
  112. /// A list of all entries to populate the UI with
  113. /// </summary>
  114. public AtmosMonitoringConsoleEntry[] AtmosNetworks;
  115. /// <summary>
  116. /// Sends data from the server to the client to populate the atmos monitoring console UI
  117. /// </summary>
  118. public AtmosMonitoringConsoleBoundInterfaceState(AtmosMonitoringConsoleEntry[] atmosNetworks)
  119. {
  120. AtmosNetworks = atmosNetworks;
  121. }
  122. }
  123. [Serializable, NetSerializable]
  124. public struct AtmosMonitoringConsoleEntry
  125. {
  126. /// <summary>
  127. /// The entity in question
  128. /// </summary>
  129. public NetEntity NetEntity;
  130. /// <summary>
  131. /// Location of the entity
  132. /// </summary>
  133. public NetCoordinates Coordinates;
  134. /// <summary>
  135. /// The associated pipe network ID
  136. /// </summary>
  137. public int NetId = -1;
  138. /// <summary>
  139. /// Localised device name
  140. /// </summary>
  141. public string EntityName;
  142. /// <summary>
  143. /// Device network address
  144. /// </summary>
  145. public string Address;
  146. /// <summary>
  147. /// Temperature (K)
  148. /// </summary>
  149. public float TemperatureData;
  150. /// <summary>
  151. /// Pressure (kPA)
  152. /// </summary>
  153. public float PressureData;
  154. /// <summary>
  155. /// Total number of mols of gas
  156. /// </summary>
  157. public float TotalMolData;
  158. /// <summary>
  159. /// Mol and percentage for all detected gases
  160. /// </summary>
  161. public Dictionary<Gas, float> GasData = new();
  162. /// <summary>
  163. /// The color to be associated with the pipe network
  164. /// </summary>
  165. public Color Color;
  166. /// <summary>
  167. /// Indicates whether the entity is powered
  168. /// </summary>
  169. public bool IsPowered = true;
  170. /// <summary>
  171. /// Used to populate the atmos monitoring console UI with data from a single air alarm
  172. /// </summary>
  173. public AtmosMonitoringConsoleEntry
  174. (NetEntity entity,
  175. NetCoordinates coordinates,
  176. int netId,
  177. string entityName,
  178. string address)
  179. {
  180. NetEntity = entity;
  181. Coordinates = coordinates;
  182. NetId = netId;
  183. EntityName = entityName;
  184. Address = address;
  185. }
  186. }
  187. public enum AtmosPipeChunkDataFacing : byte
  188. {
  189. // Values represent bit shift offsets when retrieving data in the tile array.
  190. North = 0,
  191. South = SharedNavMapSystem.ArraySize,
  192. East = SharedNavMapSystem.ArraySize * 2,
  193. West = SharedNavMapSystem.ArraySize * 3,
  194. }
  195. /// <summary>
  196. /// UI key associated with the atmos monitoring console
  197. /// </summary>
  198. [Serializable, NetSerializable]
  199. public enum AtmosMonitoringConsoleUiKey
  200. {
  201. Key
  202. }