SharedPortableGeneratorComponent.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. using Robust.Shared.Audio;
  2. using Robust.Shared.Serialization;
  3. namespace Content.Shared.Power.Generator;
  4. /// <summary>
  5. /// Responsible for power output switching &amp; UI logic on portable generators.
  6. /// </summary>
  7. /// <remarks>
  8. /// A portable generator is expected to have the following components: <c>SolidFuelGeneratorAdapterComponent</c> <see cref="FuelGeneratorComponent"/>.
  9. /// </remarks>
  10. /// <seealso cref="SharedPortableGeneratorSystem"/>
  11. [RegisterComponent]
  12. [Access(typeof(SharedPortableGeneratorSystem))]
  13. public sealed partial class PortableGeneratorComponent : Component
  14. {
  15. /// <summary>
  16. /// Chance that this generator will start. If it fails, the user has to try again.
  17. /// </summary>
  18. [DataField("startChance")]
  19. [ViewVariables(VVAccess.ReadWrite)]
  20. public float StartChance { get; set; } = 1f;
  21. /// <summary>
  22. /// Amount of time it takes to attempt to start the generator.
  23. /// </summary>
  24. [DataField("startTime")]
  25. [ViewVariables(VVAccess.ReadWrite)]
  26. public TimeSpan StartTime { get; set; } = TimeSpan.FromSeconds(2);
  27. /// <summary>
  28. /// Sound that plays when attempting to start this generator.
  29. /// </summary>
  30. [DataField("startSound")]
  31. [ViewVariables(VVAccess.ReadWrite)]
  32. public SoundSpecifier? StartSound { get; set; }
  33. /// <summary>
  34. /// Sound that plays when attempting to start this generator.
  35. /// Plays instead of <see cref="StartSound"/> if the generator has no fuel (dumbass).
  36. /// </summary>
  37. [DataField("startSoundEmpty")]
  38. [ViewVariables(VVAccess.ReadWrite)]
  39. public SoundSpecifier? StartSoundEmpty { get; set; }
  40. }
  41. /// <summary>
  42. /// Sent to the server to adjust the targeted power level of a portable generator.
  43. /// </summary>
  44. [Serializable, NetSerializable]
  45. public sealed class PortableGeneratorSetTargetPowerMessage : BoundUserInterfaceMessage
  46. {
  47. public int TargetPower;
  48. public PortableGeneratorSetTargetPowerMessage(int targetPower)
  49. {
  50. TargetPower = targetPower;
  51. }
  52. }
  53. /// <summary>
  54. /// Sent to the server to try to start a portable generator.
  55. /// </summary>
  56. [Serializable, NetSerializable]
  57. public sealed class PortableGeneratorStartMessage : BoundUserInterfaceMessage
  58. {
  59. }
  60. /// <summary>
  61. /// Sent to the server to try to stop a portable generator.
  62. /// </summary>
  63. [Serializable, NetSerializable]
  64. public sealed class PortableGeneratorStopMessage : BoundUserInterfaceMessage
  65. {
  66. }
  67. /// <summary>
  68. /// Sent to the server to try to change the power output of a power-switchable portable generator.
  69. /// </summary>
  70. [Serializable, NetSerializable]
  71. public sealed class PortableGeneratorSwitchOutputMessage : BoundUserInterfaceMessage
  72. {
  73. }
  74. /// <summary>
  75. /// Sent to the server to try to eject all fuel stored in a portable generator.
  76. /// </summary>
  77. [Serializable, NetSerializable]
  78. public sealed class PortableGeneratorEjectFuelMessage : BoundUserInterfaceMessage
  79. {
  80. }
  81. /// <summary>
  82. /// Contains network state for the portable generator.
  83. /// </summary>
  84. [Serializable, NetSerializable]
  85. public sealed class PortableGeneratorComponentBuiState : BoundUserInterfaceState
  86. {
  87. public float RemainingFuel;
  88. public bool Clogged;
  89. public (float Load, float Supply)? NetworkStats;
  90. public float TargetPower;
  91. public float MaximumPower;
  92. public float OptimalPower;
  93. public bool On;
  94. public PortableGeneratorComponentBuiState(
  95. FuelGeneratorComponent component,
  96. float remainingFuel,
  97. bool clogged,
  98. (float Demand, float Supply)? networkStats)
  99. {
  100. RemainingFuel = remainingFuel;
  101. Clogged = clogged;
  102. TargetPower = component.TargetPower;
  103. MaximumPower = component.MaxTargetPower;
  104. OptimalPower = component.OptimalPower;
  105. On = component.On;
  106. NetworkStats = networkStats;
  107. }
  108. }
  109. [Serializable, NetSerializable]
  110. public enum GeneratorComponentUiKey
  111. {
  112. Key
  113. }
  114. /// <summary>
  115. /// Sprite layers for generator prototypes.
  116. /// </summary>
  117. [Serializable, NetSerializable]
  118. public enum GeneratorVisualLayers : byte
  119. {
  120. Body,
  121. Unlit
  122. }
  123. /// <summary>
  124. /// Appearance keys for generators.
  125. /// </summary>
  126. [Serializable, NetSerializable]
  127. public enum GeneratorVisuals : byte
  128. {
  129. /// <summary>
  130. /// Boolean: is the generator running?
  131. /// </summary>
  132. Running,
  133. }