PowerSensorComponent.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using Content.Server.DeviceLinking.Systems;
  2. using Content.Shared.DeviceLinking;
  3. using Content.Shared.Power.Generator;
  4. using Content.Shared.Tools;
  5. using Robust.Shared.Audio;
  6. using Robust.Shared.Prototypes;
  7. using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
  8. namespace Content.Server.DeviceLinking.Components;
  9. /// <summary>
  10. /// A power sensor checks the power network it's anchored to.
  11. /// Has 2 ports for when it is charging or discharging. They should never both be high.
  12. /// Requires <see cref="PowerSwitchableComponent"/> to function.
  13. /// </summary>
  14. [RegisterComponent, Access(typeof(PowerSensorSystem))]
  15. public sealed partial class PowerSensorComponent : Component
  16. {
  17. /// <summary>
  18. /// Whether to check the power network's input or output battery stats.
  19. /// Useful when working with SMESes where input and output can both be important.
  20. /// Or with APCs where there is no output and only input.
  21. /// </summary>
  22. [DataField, ViewVariables(VVAccess.ReadWrite)]
  23. public bool Output;
  24. /// <summary>
  25. /// Tool quality to use for switching between input and output.
  26. /// Cannot be pulsing since linking uses that.
  27. /// </summary>
  28. [DataField, ViewVariables(VVAccess.ReadWrite)]
  29. public ProtoId<ToolQualityPrototype> SwitchQuality = "Screwing";
  30. /// <summary>
  31. /// Sound played when switching between input and output.
  32. /// </summary>
  33. [DataField]
  34. public SoundSpecifier SwitchSound = new SoundPathSpecifier("/Audio/Machines/lightswitch.ogg");
  35. /// <summary>
  36. /// Name of the port set when the network is charging power.
  37. /// </summary>
  38. [DataField, ViewVariables(VVAccess.ReadWrite)]
  39. public ProtoId<SourcePortPrototype> ChargingPort = "PowerCharging";
  40. /// <summary>
  41. /// Name of the port set when the network is discharging power.
  42. /// </summary>
  43. [DataField, ViewVariables(VVAccess.ReadWrite)]
  44. public ProtoId<SourcePortPrototype> DischargingPort = "PowerDischarging";
  45. /// <summary>
  46. /// How long to wait before checking the power network.
  47. /// </summary>
  48. [DataField, ViewVariables(VVAccess.ReadWrite)]
  49. public TimeSpan CheckDelay = TimeSpan.FromSeconds(1);
  50. /// <summary>
  51. /// Time at which power will be checked.
  52. /// </summary>
  53. [DataField(customTypeSerializer: typeof(TimeOffsetSerializer)), ViewVariables(VVAccess.ReadWrite)]
  54. public TimeSpan NextCheck = TimeSpan.Zero;
  55. /// <summary>
  56. /// Charge the network was at, at the last check.
  57. /// Charging/discharging is derived from this.
  58. /// </summary>
  59. [DataField]
  60. public float LastCharge;
  61. // Initial state
  62. [DataField]
  63. public bool ChargingState;
  64. [DataField]
  65. public bool DischargingState;
  66. }