AtmosDebugOverlaySystem.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using Content.Client.Atmos.Overlays;
  2. using Content.Shared.Atmos;
  3. using Content.Shared.Atmos.EntitySystems;
  4. using Content.Shared.GameTicking;
  5. using JetBrains.Annotations;
  6. using Robust.Client.Graphics;
  7. namespace Content.Client.Atmos.EntitySystems
  8. {
  9. [UsedImplicitly]
  10. internal sealed class AtmosDebugOverlaySystem : SharedAtmosDebugOverlaySystem
  11. {
  12. public readonly Dictionary<EntityUid, AtmosDebugOverlayMessage> TileData = new();
  13. // Configuration set by debug commands and used by AtmosDebugOverlay {
  14. /// <summary>Value source for display</summary>
  15. public AtmosDebugOverlayMode CfgMode;
  16. /// <summary>This is subtracted from value (applied before CfgScale)</summary>
  17. public float CfgBase = 0;
  18. /// <summary>The value is divided by this (applied after CfgBase)</summary>
  19. public float CfgScale = Atmospherics.MolesCellStandard * 2;
  20. /// <summary>Gas ID used by GasMoles mode</summary>
  21. public int CfgSpecificGas = 0;
  22. /// <summary>Uses black-to-white interpolation (as opposed to red-green-blue) for colourblind users</summary>
  23. public bool CfgCBM = false;
  24. // }
  25. public override void Initialize()
  26. {
  27. base.Initialize();
  28. SubscribeNetworkEvent<RoundRestartCleanupEvent>(Reset);
  29. SubscribeNetworkEvent<AtmosDebugOverlayMessage>(HandleAtmosDebugOverlayMessage);
  30. SubscribeNetworkEvent<AtmosDebugOverlayDisableMessage>(HandleAtmosDebugOverlayDisableMessage);
  31. SubscribeLocalEvent<GridRemovalEvent>(OnGridRemoved);
  32. var overlayManager = IoCManager.Resolve<IOverlayManager>();
  33. if(!overlayManager.HasOverlay<AtmosDebugOverlay>())
  34. overlayManager.AddOverlay(new AtmosDebugOverlay(this));
  35. }
  36. private void OnGridRemoved(GridRemovalEvent ev)
  37. {
  38. if (TileData.ContainsKey(ev.EntityUid))
  39. {
  40. TileData.Remove(ev.EntityUid);
  41. }
  42. }
  43. private void HandleAtmosDebugOverlayMessage(AtmosDebugOverlayMessage message)
  44. {
  45. TileData[GetEntity(message.GridId)] = message;
  46. }
  47. private void HandleAtmosDebugOverlayDisableMessage(AtmosDebugOverlayDisableMessage ev)
  48. {
  49. TileData.Clear();
  50. }
  51. public override void Shutdown()
  52. {
  53. base.Shutdown();
  54. var overlayManager = IoCManager.Resolve<IOverlayManager>();
  55. if (overlayManager.HasOverlay<AtmosDebugOverlay>())
  56. overlayManager.RemoveOverlay<AtmosDebugOverlay>();
  57. }
  58. public void Reset(RoundRestartCleanupEvent ev)
  59. {
  60. TileData.Clear();
  61. }
  62. public bool HasData(EntityUid gridId)
  63. {
  64. return TileData.ContainsKey(gridId);
  65. }
  66. }
  67. internal enum AtmosDebugOverlayMode : byte
  68. {
  69. TotalMoles,
  70. GasMoles,
  71. Temperature
  72. }
  73. }