2020-09-21 00:13:17 +01:00
|
|
|
using System.Collections.Generic;
|
2021-06-19 13:25:05 +02:00
|
|
|
using Content.Client.Atmos.Overlays;
|
2020-11-28 13:45:52 +00:00
|
|
|
using Content.Shared.Atmos;
|
2021-06-19 13:25:05 +02:00
|
|
|
using Content.Shared.Atmos.EntitySystems;
|
2020-11-15 04:16:02 +01:00
|
|
|
using Content.Shared.GameTicking;
|
2020-09-21 00:13:17 +01:00
|
|
|
using JetBrains.Annotations;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Client.Graphics;
|
2020-09-21 00:13:17 +01:00
|
|
|
using Robust.Shared.IoC;
|
|
|
|
|
using Robust.Shared.Map;
|
|
|
|
|
using Robust.Shared.Maths;
|
|
|
|
|
|
2021-06-19 13:25:05 +02:00
|
|
|
namespace Content.Client.Atmos.EntitySystems
|
2020-09-21 00:13:17 +01:00
|
|
|
{
|
|
|
|
|
[UsedImplicitly]
|
2021-06-29 15:56:07 +02:00
|
|
|
internal sealed class AtmosDebugOverlaySystem : SharedAtmosDebugOverlaySystem
|
2020-09-21 00:13:17 +01:00
|
|
|
{
|
|
|
|
|
|
2022-06-11 18:54:41 -07:00
|
|
|
private readonly Dictionary<EntityUid, AtmosDebugOverlayMessage> _tileData =
|
2020-11-27 11:00:49 +01:00
|
|
|
new();
|
2020-09-21 00:13:17 +01:00
|
|
|
|
2020-11-28 13:45:52 +00:00
|
|
|
// Configuration set by debug commands and used by AtmosDebugOverlay {
|
|
|
|
|
/// <summary>Value source for display</summary>
|
|
|
|
|
public AtmosDebugOverlayMode CfgMode;
|
|
|
|
|
/// <summary>This is subtracted from value (applied before CfgScale)</summary>
|
|
|
|
|
public float CfgBase = 0;
|
|
|
|
|
/// <summary>The value is divided by this (applied after CfgBase)</summary>
|
|
|
|
|
public float CfgScale = Atmospherics.MolesCellStandard * 2;
|
|
|
|
|
/// <summary>Gas ID used by GasMoles mode</summary>
|
|
|
|
|
public int CfgSpecificGas = 0;
|
|
|
|
|
/// <summary>Uses black-to-white interpolation (as opposed to red-green-blue) for colourblind users</summary>
|
|
|
|
|
public bool CfgCBM = false;
|
|
|
|
|
// }
|
|
|
|
|
|
2020-09-21 00:13:17 +01:00
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
2020-11-18 08:18:04 +01:00
|
|
|
|
2021-06-29 15:56:07 +02:00
|
|
|
SubscribeNetworkEvent<RoundRestartCleanupEvent>(Reset);
|
2020-09-21 00:13:17 +01:00
|
|
|
SubscribeNetworkEvent<AtmosDebugOverlayMessage>(HandleAtmosDebugOverlayMessage);
|
2020-11-18 08:18:04 +01:00
|
|
|
SubscribeNetworkEvent<AtmosDebugOverlayDisableMessage>(HandleAtmosDebugOverlayDisableMessage);
|
2020-09-21 00:13:17 +01:00
|
|
|
|
2022-03-09 07:39:03 +01:00
|
|
|
SubscribeLocalEvent<GridRemovalEvent>(OnGridRemoved);
|
2020-09-21 00:13:17 +01:00
|
|
|
|
|
|
|
|
var overlayManager = IoCManager.Resolve<IOverlayManager>();
|
2021-03-09 04:33:41 -06:00
|
|
|
if(!overlayManager.HasOverlay<AtmosDebugOverlay>())
|
2020-09-21 00:13:17 +01:00
|
|
|
overlayManager.AddOverlay(new AtmosDebugOverlay());
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-09 07:39:03 +01:00
|
|
|
private void OnGridRemoved(GridRemovalEvent ev)
|
|
|
|
|
{
|
2022-06-29 00:56:02 +12:00
|
|
|
if (_tileData.ContainsKey(ev.EntityUid))
|
2022-03-09 07:39:03 +01:00
|
|
|
{
|
2022-06-29 00:56:02 +12:00
|
|
|
_tileData.Remove(ev.EntityUid);
|
2022-03-09 07:39:03 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-21 00:13:17 +01:00
|
|
|
private void HandleAtmosDebugOverlayMessage(AtmosDebugOverlayMessage message)
|
|
|
|
|
{
|
|
|
|
|
_tileData[message.GridId] = message;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-18 08:18:04 +01:00
|
|
|
private void HandleAtmosDebugOverlayDisableMessage(AtmosDebugOverlayDisableMessage ev)
|
|
|
|
|
{
|
|
|
|
|
_tileData.Clear();
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-21 00:13:17 +01:00
|
|
|
public override void Shutdown()
|
|
|
|
|
{
|
|
|
|
|
base.Shutdown();
|
|
|
|
|
var overlayManager = IoCManager.Resolve<IOverlayManager>();
|
2021-11-01 00:40:57 +11:00
|
|
|
if (overlayManager.HasOverlay<AtmosDebugOverlay>())
|
|
|
|
|
overlayManager.RemoveOverlay<AtmosDebugOverlay>();
|
2020-09-21 00:13:17 +01:00
|
|
|
}
|
|
|
|
|
|
2021-06-29 15:56:07 +02:00
|
|
|
public void Reset(RoundRestartCleanupEvent ev)
|
2020-11-15 04:16:02 +01:00
|
|
|
{
|
|
|
|
|
_tileData.Clear();
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-11 18:54:41 -07:00
|
|
|
public bool HasData(EntityUid gridId)
|
2020-09-21 00:13:17 +01:00
|
|
|
{
|
|
|
|
|
return _tileData.ContainsKey(gridId);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-11 18:54:41 -07:00
|
|
|
public AtmosDebugOverlayData? GetData(EntityUid gridIndex, Vector2i indices)
|
2020-09-21 00:13:17 +01:00
|
|
|
{
|
|
|
|
|
if (!_tileData.TryGetValue(gridIndex, out var srcMsg))
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
var relative = indices - srcMsg.BaseIdx;
|
|
|
|
|
if (relative.X < 0 || relative.Y < 0 || relative.X >= LocalViewRange || relative.Y >= LocalViewRange)
|
|
|
|
|
return null;
|
|
|
|
|
|
2022-03-09 07:39:03 +01:00
|
|
|
return srcMsg.OverlayData[relative.X + relative.Y * LocalViewRange];
|
2020-09-21 00:13:17 +01:00
|
|
|
}
|
|
|
|
|
}
|
2020-11-28 13:45:52 +00:00
|
|
|
|
2020-12-04 11:57:33 +01:00
|
|
|
internal enum AtmosDebugOverlayMode : byte
|
2020-11-28 13:45:52 +00:00
|
|
|
{
|
|
|
|
|
TotalMoles,
|
|
|
|
|
GasMoles,
|
|
|
|
|
Temperature
|
|
|
|
|
}
|
2020-09-21 00:13:17 +01:00
|
|
|
}
|