WeatherComponent.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using Robust.Shared.GameStates;
  2. using Robust.Shared.Prototypes;
  3. using Robust.Shared.Serialization;
  4. using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
  5. namespace Content.Shared.Weather;
  6. [RegisterComponent, NetworkedComponent]
  7. public sealed partial class WeatherComponent : Component
  8. {
  9. /// <summary>
  10. /// Currently running weathers
  11. /// </summary>
  12. [DataField]
  13. public Dictionary<ProtoId<WeatherPrototype>, WeatherData> Weather = new();
  14. public static readonly TimeSpan StartupTime = TimeSpan.FromSeconds(15);
  15. public static readonly TimeSpan ShutdownTime = TimeSpan.FromSeconds(15);
  16. }
  17. [DataDefinition, Serializable, NetSerializable]
  18. public sealed partial class WeatherData
  19. {
  20. // Client audio stream.
  21. [NonSerialized]
  22. public EntityUid? Stream;
  23. /// <summary>
  24. /// When the weather started if relevant.
  25. /// </summary>
  26. [DataField(customTypeSerializer: typeof(TimeOffsetSerializer))] //TODO: Remove Custom serializer
  27. public TimeSpan StartTime = TimeSpan.Zero;
  28. /// <summary>
  29. /// When the applied weather will end.
  30. /// </summary>
  31. [DataField(customTypeSerializer: typeof(TimeOffsetSerializer))] //TODO: Remove Custom serializer
  32. public TimeSpan? EndTime;
  33. [ViewVariables]
  34. public TimeSpan Duration => EndTime == null ? TimeSpan.MaxValue : EndTime.Value - StartTime;
  35. [DataField]
  36. public WeatherState State = WeatherState.Invalid;
  37. }
  38. public enum WeatherState : byte
  39. {
  40. Invalid = 0,
  41. Starting,
  42. Running,
  43. Ending,
  44. }