ThrusterSystem.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using Content.Shared.Shuttles.Components;
  2. using Robust.Client.GameObjects;
  3. namespace Content.Client.Shuttles;
  4. /// <summary>
  5. /// Handles making a thruster visibly turn on/emit an exhaust plume according to its state.
  6. /// </summary>
  7. public sealed class ThrusterSystem : VisualizerSystem<ThrusterComponent>
  8. {
  9. /// <summary>
  10. /// Updates whether or not the thruster is visibly active/thrusting.
  11. /// </summary>
  12. protected override void OnAppearanceChange(EntityUid uid, ThrusterComponent comp, ref AppearanceChangeEvent args)
  13. {
  14. if (args.Sprite == null
  15. || !AppearanceSystem.TryGetData<bool>(uid, ThrusterVisualState.State, out var state, args.Component))
  16. return;
  17. args.Sprite.LayerSetVisible(ThrusterVisualLayers.ThrustOn, state);
  18. SetThrusting(
  19. uid,
  20. state && AppearanceSystem.TryGetData<bool>(uid, ThrusterVisualState.Thrusting, out var thrusting, args.Component) && thrusting,
  21. args.Sprite
  22. );
  23. }
  24. /// <summary>
  25. /// Sets whether or not the exhaust plume of the thruster is visible or not.
  26. /// </summary>
  27. private static void SetThrusting(EntityUid _, bool value, SpriteComponent sprite)
  28. {
  29. if (sprite.LayerMapTryGet(ThrusterVisualLayers.Thrusting, out var thrustingLayer))
  30. {
  31. sprite.LayerSetVisible(thrustingLayer, value);
  32. }
  33. if (sprite.LayerMapTryGet(ThrusterVisualLayers.ThrustingUnshaded, out var unshadedLayer))
  34. {
  35. sprite.LayerSetVisible(unshadedLayer, value);
  36. }
  37. }
  38. }
  39. public enum ThrusterVisualLayers : byte
  40. {
  41. Base,
  42. ThrustOn,
  43. Thrusting,
  44. ThrustingUnshaded,
  45. }