1
0

SharedWiresComponent.cs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. using System.Diagnostics.CodeAnalysis;
  2. using Content.Shared.DoAfter;
  3. using JetBrains.Annotations;
  4. using Robust.Shared.Serialization;
  5. namespace Content.Shared.Wires
  6. {
  7. [Serializable, NetSerializable]
  8. public sealed partial class WirePanelDoAfterEvent : SimpleDoAfterEvent
  9. {
  10. }
  11. [Serializable, NetSerializable]
  12. public enum WiresVisuals : byte
  13. {
  14. MaintenancePanelState
  15. }
  16. [Serializable, NetSerializable]
  17. public enum WiresUiKey : byte
  18. {
  19. Key,
  20. }
  21. [Serializable, NetSerializable]
  22. public enum WiresAction : byte
  23. {
  24. Mend,
  25. Cut,
  26. Pulse,
  27. }
  28. [Serializable, NetSerializable]
  29. public enum StatusLightState : byte
  30. {
  31. Off,
  32. On,
  33. BlinkingFast,
  34. BlinkingSlow
  35. }
  36. [Serializable, NetSerializable]
  37. public sealed class WiresActionMessage : BoundUserInterfaceMessage
  38. {
  39. public readonly int Id;
  40. public readonly WiresAction Action;
  41. public WiresActionMessage(int id, WiresAction action)
  42. {
  43. Id = id;
  44. Action = action;
  45. }
  46. }
  47. [SuppressMessage("ReSharper", "InconsistentNaming")]
  48. [PublicAPI]
  49. [Serializable, NetSerializable]
  50. public enum WireLetter : byte
  51. {
  52. α,
  53. β,
  54. γ,
  55. δ,
  56. ε,
  57. ζ,
  58. η,
  59. θ,
  60. ι,
  61. κ,
  62. λ,
  63. μ,
  64. ν,
  65. ξ,
  66. ο,
  67. π,
  68. ρ,
  69. σ,
  70. τ,
  71. υ,
  72. φ,
  73. χ,
  74. ψ,
  75. ω
  76. }
  77. [PublicAPI]
  78. [Serializable, NetSerializable]
  79. public enum WireColor : byte
  80. {
  81. Red,
  82. Blue,
  83. Green,
  84. Orange,
  85. Brown,
  86. Gold,
  87. Gray,
  88. Cyan,
  89. Navy,
  90. Purple,
  91. Pink,
  92. Fuchsia
  93. }
  94. [Serializable, NetSerializable]
  95. public struct StatusLightData
  96. {
  97. public StatusLightData(Color color, StatusLightState state, string text)
  98. {
  99. Color = color;
  100. State = state;
  101. Text = text;
  102. }
  103. public Color Color { get; }
  104. public StatusLightState State { get; }
  105. public string Text { get; }
  106. public override string ToString()
  107. {
  108. return $"Color: {Color}, State: {State}, Text: {Text}";
  109. }
  110. }
  111. [Serializable, NetSerializable]
  112. public sealed class WiresBoundUserInterfaceState : BoundUserInterfaceState
  113. {
  114. public string BoardName { get; }
  115. public string? SerialNumber { get; }
  116. public ClientWire[] WiresList { get; }
  117. public StatusEntry[] Statuses { get; }
  118. public int WireSeed { get; }
  119. public WiresBoundUserInterfaceState(ClientWire[] wiresList, StatusEntry[] statuses, string boardName, string? serialNumber, int wireSeed)
  120. {
  121. BoardName = boardName;
  122. SerialNumber = serialNumber;
  123. WireSeed = wireSeed;
  124. WiresList = wiresList;
  125. Statuses = statuses;
  126. }
  127. }
  128. [Serializable, NetSerializable]
  129. public struct StatusEntry
  130. {
  131. /// <summary>
  132. /// The key of this status, according to the status dictionary
  133. /// server side.
  134. /// </summary>
  135. public readonly object Key;
  136. /// <summary>
  137. /// The value of this status, according to the status dictionary
  138. /// server side..
  139. /// </summary>
  140. public readonly object Value;
  141. public StatusEntry(object key, object value)
  142. {
  143. Key = key;
  144. Value = value;
  145. }
  146. public override string ToString()
  147. {
  148. return $"{Key}, {Value}";
  149. }
  150. }
  151. /// <summary>
  152. /// ClientWire, sent by the server so that the client knows
  153. /// what wires there are on an entity.
  154. /// </summary>
  155. [Serializable, NetSerializable]
  156. public sealed class ClientWire
  157. {
  158. /// <summary>
  159. /// ID of this wire, which corresponds to
  160. /// the ID server side.
  161. /// </summary>
  162. public int Id;
  163. /// <summary>
  164. /// Whether this wire is cut or not.
  165. /// </summary>
  166. public bool IsCut;
  167. /// <summary>
  168. /// Current color of the wire.
  169. /// </summary>
  170. public WireColor Color;
  171. /// <summary>
  172. /// Current letter of the wire.
  173. /// </summary>
  174. public WireLetter Letter;
  175. public ClientWire(int id, bool isCut, WireColor color, WireLetter letter)
  176. {
  177. Id = id;
  178. IsCut = isCut;
  179. Letter = letter;
  180. Color = color;
  181. }
  182. }
  183. public static class HackingWiresExt
  184. {
  185. public static string Name(this WireColor color)
  186. {
  187. return Loc.GetString(color switch
  188. {
  189. WireColor.Red => "Red",
  190. WireColor.Blue => "Blue",
  191. WireColor.Green => "Green",
  192. WireColor.Orange => "Orange",
  193. WireColor.Brown => "Brown",
  194. WireColor.Gold => "Gold",
  195. WireColor.Gray => "Gray",
  196. WireColor.Cyan => "Cyan",
  197. WireColor.Navy => "Navy",
  198. WireColor.Purple => "Purple",
  199. WireColor.Pink => "Pink",
  200. WireColor.Fuchsia => "Fuchsia",
  201. _ => throw new InvalidOperationException()
  202. });
  203. }
  204. public static Color ColorValue(this WireColor color)
  205. {
  206. return color switch
  207. {
  208. WireColor.Red => Color.Red,
  209. WireColor.Blue => Color.Blue,
  210. WireColor.Green => Color.LimeGreen,
  211. WireColor.Orange => Color.Orange,
  212. WireColor.Brown => Color.Brown,
  213. WireColor.Gold => Color.Gold,
  214. WireColor.Gray => Color.Gray,
  215. WireColor.Cyan => Color.Cyan,
  216. WireColor.Navy => Color.Navy,
  217. WireColor.Purple => Color.Purple,
  218. WireColor.Pink => Color.Pink,
  219. WireColor.Fuchsia => Color.Fuchsia,
  220. _ => throw new InvalidOperationException()
  221. };
  222. }
  223. public static string Name(this WireLetter letter)
  224. {
  225. return Loc.GetString(letter switch
  226. {
  227. WireLetter.α => "Alpha",
  228. WireLetter.β => "Beta",
  229. WireLetter.γ => "Gamma",
  230. WireLetter.δ => "Delta",
  231. WireLetter.ε => "Epsilon",
  232. WireLetter.ζ => "Zeta",
  233. WireLetter.η => "Eta",
  234. WireLetter.θ => "Theta",
  235. WireLetter.ι => "Iota",
  236. WireLetter.κ => "Kappa",
  237. WireLetter.λ => "Lambda",
  238. WireLetter.μ => "Mu",
  239. WireLetter.ν => "Nu",
  240. WireLetter.ξ => "Xi",
  241. WireLetter.ο => "Omicron",
  242. WireLetter.π => "Pi",
  243. WireLetter.ρ => "Rho",
  244. WireLetter.σ => "Sigma",
  245. WireLetter.τ => "Tau",
  246. WireLetter.υ => "Upsilon",
  247. WireLetter.φ => "Phi",
  248. WireLetter.χ => "Chi",
  249. WireLetter.ψ => "Psi",
  250. WireLetter.ω => "Omega",
  251. _ => throw new InvalidOperationException()
  252. });
  253. }
  254. public static char Letter(this WireLetter letter)
  255. {
  256. return letter switch
  257. {
  258. WireLetter.α => 'α',
  259. WireLetter.β => 'β',
  260. WireLetter.γ => 'γ',
  261. WireLetter.δ => 'δ',
  262. WireLetter.ε => 'ε',
  263. WireLetter.ζ => 'ζ',
  264. WireLetter.η => 'η',
  265. WireLetter.θ => 'θ',
  266. WireLetter.ι => 'ι',
  267. WireLetter.κ => 'κ',
  268. WireLetter.λ => 'λ',
  269. WireLetter.μ => 'μ',
  270. WireLetter.ν => 'ν',
  271. WireLetter.ξ => 'ξ',
  272. WireLetter.ο => 'ο',
  273. WireLetter.π => 'π',
  274. WireLetter.ρ => 'ρ',
  275. WireLetter.σ => 'σ',
  276. WireLetter.τ => 'τ',
  277. WireLetter.υ => 'υ',
  278. WireLetter.φ => 'φ',
  279. WireLetter.χ => 'χ',
  280. WireLetter.ψ => 'ψ',
  281. WireLetter.ω => 'ω',
  282. _ => throw new InvalidOperationException()
  283. };
  284. }
  285. }
  286. }