Files
crystall-punk-14/Content.Shared/Atmos/Consoles/SharedAtmosMonitoringConsoleSystem.cs

116 lines
3.9 KiB
C#
Raw Normal View History

Atmospheric network monitor (#32294) * Updated to latest master version * Added gas pipe analyzer * Completed prototype * Playing with UI display * Refinement of the main UI * Renamed gas pipe analyzer to gas pipe sensor * Added focus network highlighting and map icons for gas pipe sensors * Added construction graph for gas pipe sensor * Improved efficiency of atmos pipe and focus pipe network data storage * Added gas pipe sensor variants * Fixed gas pipe sensor nav map icon not highlighting on focus * Rendered pipe lines now get merged together * Set up appearance handling for the gas pipe sensor, but setting the layers is bugged * Gas pipe sensor lights turn off when the device is unpowered * Renamed console * The gas pipe sensor is now a pipe. Redistributed components between it and its assembly * AtmosMonitors can now optionally monitor their internal pipe network instead of the surrounding atmosphere * Massive code clean up * Added delta states to handle pipe net updates, fixed entity deletion handling * Nav map blip data has been replaced with prototypes * Nav map blip fixes * Nav map colors are now set by the console component * Made the nav map more responsive to changes in focus * Updated nav map icons * Reverted unnecessary namespace changes * Code tidy up * Updated sprites and construction graph for gas pipe sensor * Updated localization files * Misc bug fixes * Added missing comment * Fixed issue with the circuit board for the monitor * Embellished the background of the console network entries * Updated console to account for PR #32273 * Removed gas pipe sensor * Fixing merge conflict * Update * Addressing reviews part 1 * Addressing review part 2 * Addressing reviews part 3 * Removed unnecessary references * Side panel values will be grayed out if there is no gas present in the pipe network * Declaring colors at the start of some files * Added a colored stripe to the side of the atmos network entries * Fixed an issue with pipe sensor blip coloration * Fixed delay that occurs when toggling gas sensors on/off
2024-12-16 21:53:17 -06:00
using Content.Shared.Atmos.Components;
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;
namespace Content.Shared.Atmos.Consoles;
public abstract class SharedAtmosMonitoringConsoleSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<AtmosMonitoringConsoleComponent, ComponentGetState>(OnGetState);
}
private void OnGetState(EntityUid uid, AtmosMonitoringConsoleComponent component, ref ComponentGetState args)
{
Dictionary<Vector2i, Dictionary<(int, string), ulong>> chunks;
// Should this be a full component state or a delta-state?
if (args.FromTick <= component.CreationTick || component.ForceFullUpdate)
{
component.ForceFullUpdate = false;
// Full state
chunks = new(component.AtmosPipeChunks.Count);
foreach (var (origin, chunk) in component.AtmosPipeChunks)
{
chunks.Add(origin, chunk.AtmosPipeData);
}
args.State = new AtmosMonitoringConsoleState(chunks, component.AtmosDevices);
return;
}
chunks = new();
foreach (var (origin, chunk) in component.AtmosPipeChunks)
{
if (chunk.LastUpdate < args.FromTick)
continue;
chunks.Add(origin, chunk.AtmosPipeData);
}
args.State = new AtmosMonitoringConsoleDeltaState(chunks, component.AtmosDevices, new(component.AtmosPipeChunks.Keys));
}
#region: System messages
[Serializable, NetSerializable]
protected sealed class AtmosMonitoringConsoleState(
Dictionary<Vector2i, Dictionary<(int, string), ulong>> chunks,
Dictionary<NetEntity, AtmosDeviceNavMapData> atmosDevices)
: ComponentState
{
public Dictionary<Vector2i, Dictionary<(int, string), ulong>> Chunks = chunks;
public Dictionary<NetEntity, AtmosDeviceNavMapData> AtmosDevices = atmosDevices;
}
[Serializable, NetSerializable]
protected sealed class AtmosMonitoringConsoleDeltaState(
Dictionary<Vector2i, Dictionary<(int, string), ulong>> modifiedChunks,
Dictionary<NetEntity, AtmosDeviceNavMapData> atmosDevices,
HashSet<Vector2i> allChunks)
: ComponentState, IComponentDeltaState<AtmosMonitoringConsoleState>
{
public Dictionary<Vector2i, Dictionary<(int, string), ulong>> ModifiedChunks = modifiedChunks;
public Dictionary<NetEntity, AtmosDeviceNavMapData> AtmosDevices = atmosDevices;
public HashSet<Vector2i> AllChunks = allChunks;
public void ApplyToFullState(AtmosMonitoringConsoleState state)
{
foreach (var key in state.Chunks.Keys)
{
if (!AllChunks!.Contains(key))
state.Chunks.Remove(key);
}
foreach (var (index, data) in ModifiedChunks)
{
state.Chunks[index] = new Dictionary<(int, string), ulong>(data);
}
state.AtmosDevices.Clear();
foreach (var (nuid, atmosDevice) in AtmosDevices)
{
state.AtmosDevices.Add(nuid, atmosDevice);
}
}
public AtmosMonitoringConsoleState CreateNewFullState(AtmosMonitoringConsoleState state)
{
var chunks = new Dictionary<Vector2i, Dictionary<(int, string), ulong>>(state.Chunks.Count);
foreach (var (index, data) in state.Chunks)
{
if (!AllChunks!.Contains(index))
continue;
if (ModifiedChunks.ContainsKey(index))
chunks[index] = new Dictionary<(int, string), ulong>(ModifiedChunks[index]);
else
chunks[index] = new Dictionary<(int, string), ulong>(state.Chunks[index]);
}
return new AtmosMonitoringConsoleState(chunks, new(AtmosDevices));
}
}
#endregion
}