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

64 lines
1.7 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);
}
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 ((category, origin), chunk) in state.Chunks)
{
var newChunk = new NavMapChunk(origin);
2023-04-13 16:21:24 +10:00
foreach (var (atmosDirection, value) in chunk)
newChunk.TileData[atmosDirection] = value;
2023-04-13 16:21:24 +10:00
component.Chunks[(category, 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
}
}