RoboticsConsoleUi.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. using Robust.Shared.Prototypes;
  2. using Robust.Shared.Serialization;
  3. using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
  4. using Robust.Shared.Utility;
  5. namespace Content.Shared.Robotics;
  6. [Serializable, NetSerializable]
  7. public enum RoboticsConsoleUiKey : byte
  8. {
  9. Key
  10. }
  11. [Serializable, NetSerializable]
  12. public sealed class RoboticsConsoleState : BoundUserInterfaceState
  13. {
  14. /// <summary>
  15. /// Map of device network addresses to cyborg data.
  16. /// </summary>
  17. public Dictionary<string, CyborgControlData> Cyborgs;
  18. public RoboticsConsoleState(Dictionary<string, CyborgControlData> cyborgs)
  19. {
  20. Cyborgs = cyborgs;
  21. }
  22. }
  23. /// <summary>
  24. /// Message to disable the selected cyborg.
  25. /// </summary>
  26. [Serializable, NetSerializable]
  27. public sealed class RoboticsConsoleDisableMessage : BoundUserInterfaceMessage
  28. {
  29. public readonly string Address;
  30. public RoboticsConsoleDisableMessage(string address)
  31. {
  32. Address = address;
  33. }
  34. }
  35. /// <summary>
  36. /// Message to destroy the selected cyborg.
  37. /// </summary>
  38. [Serializable, NetSerializable]
  39. public sealed class RoboticsConsoleDestroyMessage : BoundUserInterfaceMessage
  40. {
  41. public readonly string Address;
  42. public RoboticsConsoleDestroyMessage(string address)
  43. {
  44. Address = address;
  45. }
  46. }
  47. /// <summary>
  48. /// All data a client needs to render the console UI for a single cyborg.
  49. /// Created by <c>BorgTransponderComponent</c> and sent to clients by <c>RoboticsConsoleComponent</c>.
  50. /// </summary>
  51. [DataRecord, Serializable, NetSerializable]
  52. public partial record struct CyborgControlData
  53. {
  54. /// <summary>
  55. /// Texture of the borg chassis.
  56. /// </summary>
  57. [DataField(required: true)]
  58. public SpriteSpecifier? ChassisSprite;
  59. /// <summary>
  60. /// Name of the borg chassis.
  61. /// </summary>
  62. [DataField(required: true)]
  63. public string ChassisName = string.Empty;
  64. /// <summary>
  65. /// Name of the borg's entity, including its silicon id.
  66. /// </summary>
  67. [DataField(required: true)]
  68. public string Name = string.Empty;
  69. /// <summary>
  70. /// Battery charge from 0 to 1.
  71. /// </summary>
  72. [DataField]
  73. public float Charge;
  74. /// <summary>
  75. /// How many modules this borg has, just useful information for roboticists.
  76. /// Lets them keep track of the latejoin borgs that need new modules and stuff.
  77. /// </summary>
  78. [DataField]
  79. public int ModuleCount;
  80. /// <summary>
  81. /// Whether the borg has a brain installed or not.
  82. /// </summary>
  83. [DataField]
  84. public bool HasBrain;
  85. /// <summary>
  86. /// Whether the borg can currently be disabled if the brain is installed,
  87. /// if on cooldown then can't queue up multiple disables.
  88. /// </summary>
  89. [DataField]
  90. public bool CanDisable;
  91. /// <summary>
  92. /// When this cyborg's data will be deleted.
  93. /// Set by the console when receiving the packet.
  94. /// </summary>
  95. [DataField(customTypeSerializer: typeof(TimeOffsetSerializer))]
  96. public TimeSpan Timeout = TimeSpan.Zero;
  97. public CyborgControlData(SpriteSpecifier? chassisSprite, string chassisName, string name, float charge, int moduleCount, bool hasBrain, bool canDisable)
  98. {
  99. ChassisSprite = chassisSprite;
  100. ChassisName = chassisName;
  101. Name = name;
  102. Charge = charge;
  103. ModuleCount = moduleCount;
  104. HasBrain = hasBrain;
  105. CanDisable = canDisable;
  106. }
  107. }
  108. public static class RoboticsConsoleConstants
  109. {
  110. // broadcast by cyborgs on Robotics Console frequency
  111. public const string NET_CYBORG_DATA = "cyborg-data";
  112. // sent by robotics console to cyborgs on Cyborg Control frequency
  113. public const string NET_DISABLE_COMMAND = "cyborg-disable";
  114. public const string NET_DESTROY_COMMAND = "cyborg-destroy";
  115. }