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

64 lines
1.8 KiB
C#
Raw Normal View History

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)
{
Dictionary<Vector2i, int[]> modifiedChunks;
Dictionary<NetEntity, NavMapBeacon> beacons;
2023-04-13 16:21:24 +10:00
switch (args.Current)
2023-04-13 16:21:24 +10:00
{
case NavMapDeltaState delta:
2023-04-13 16:21:24 +10:00
{
modifiedChunks = delta.ModifiedChunks;
beacons = delta.Beacons;
foreach (var index in component.Chunks.Keys)
{
if (!delta.AllChunks!.Contains(index))
component.Chunks.Remove(index);
}
break;
}
case NavMapState state:
2023-04-13 16:21:24 +10:00
{
modifiedChunks = state.Chunks;
beacons = state.Beacons;
foreach (var index in component.Chunks.Keys)
{
if (!state.Chunks.ContainsKey(index))
component.Chunks.Remove(index);
}
break;
}
default:
return;
}
2023-04-13 16:21:24 +10:00
foreach (var (origin, chunk) in modifiedChunks)
{
var newChunk = new NavMapChunk(origin);
Array.Copy(chunk, newChunk.TileData, chunk.Length);
component.Chunks[origin] = newChunk;
2023-04-13 16:21:24 +10:00
}
component.Beacons.Clear();
foreach (var (nuid, beacon) in beacons)
{
component.Beacons[nuid] = beacon;
}
2023-04-13 16:21:24 +10:00
}
}