Files
crystall-punk-14/Content.Client/Pinpointer/NavMapSystem.cs

73 lines
1.9 KiB
C#
Raw Normal View History

using Content.Shared.Atmos;
2023-04-13 16:21:24 +10:00
using Content.Shared.Pinpointer;
using Robust.Shared.GameStates;
namespace Content.Client.Pinpointer;
public sealed partial class NavMapSystem : SharedNavMapSystem
2023-04-13 16:21:24 +10:00
{
public override void Initialize()
{
base.Initialize();
2023-04-13 16:21:24 +10:00
SubscribeLocalEvent<NavMapComponent, ComponentHandleState>(OnHandleState);
}
private void OnHandleState(EntityUid uid, NavMapComponent component, ref ComponentHandleState args)
{
if (args.Current is not NavMapComponentState state)
return;
if (!state.FullState)
2023-04-13 16:21:24 +10:00
{
foreach (var index in component.Chunks.Keys)
2023-04-13 16:21:24 +10:00
{
if (!state.AllChunks!.Contains(index))
component.Chunks.Remove(index);
}
2023-04-13 16:21:24 +10:00
foreach (var beacon in component.Beacons)
{
if (!state.AllBeacons!.Contains(beacon))
component.Beacons.Remove(beacon);
}
}
else
2023-04-13 16:21:24 +10:00
{
foreach (var index in component.Chunks.Keys)
2023-04-13 16:21:24 +10:00
{
if (!state.Chunks.ContainsKey(index))
component.Chunks.Remove(index);
}
2023-04-13 16:21:24 +10:00
foreach (var beacon in component.Beacons)
{
if (!state.Beacons.Contains(beacon))
component.Beacons.Remove(beacon);
}
}
2023-04-13 16:21:24 +10:00
foreach (var (origin, chunk) in state.Chunks)
{
var newChunk = new NavMapChunk(origin);
2023-04-13 16:21:24 +10:00
for (var i = 0; i < NavMapComponent.Categories; i++)
{
var newData = chunk[i];
if (newData == null)
continue;
2023-04-13 16:21:24 +10:00
newChunk.TileData[i] = new(newData);
}
component.Chunks[origin] = newChunk;
2023-04-13 16:21:24 +10:00
}
foreach (var beacon in state.Beacons)
{
component.Beacons.Add(beacon);
}
2023-04-13 16:21:24 +10:00
}
}