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

51 lines
1.4 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)
{
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);
}
}
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 (origin, chunk) in state.Chunks)
{
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 state.Beacons)
{
component.Beacons[nuid] = beacon;
}
2023-04-13 16:21:24 +10:00
}
}