Files
tbd-station-14/Content.Shared/Pinpointer/SharedNavMapSystem.cs
Errant efdc6f8d4c Beacon localization (#24138)
* localize beacons

* No not like that

* Tesla beacons were already depreciated, time to give the reaper their due

* Entity name fallback

* The real treasure was the far easier solution we missed along the way

* weh

* Shared mapinit

* fix RT version

* a single line break
2024-01-20 19:59:41 +11:00

64 lines
1.7 KiB
C#

using System.Numerics;
using Robust.Shared.Serialization;
using Robust.Shared.Utility;
namespace Content.Shared.Pinpointer;
public abstract class SharedNavMapSystem : EntitySystem
{
public const byte ChunkSize = 4;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<NavMapBeaconComponent, MapInitEvent>(OnNavMapBeaconMapInit);
}
/// <summary>
/// Converts the chunk's tile into a bitflag for the slot.
/// </summary>
public static int GetFlag(Vector2i relativeTile)
{
return 1 << (relativeTile.X * ChunkSize + relativeTile.Y);
}
/// <summary>
/// Converts the chunk's tile into a bitflag for the slot.
/// </summary>
public static Vector2i GetTile(int flag)
{
var value = Math.Log2(flag);
var x = (int) value / ChunkSize;
var y = (int) value % ChunkSize;
var result = new Vector2i(x, y);
DebugTools.Assert(GetFlag(result) == flag);
return new Vector2i(x, y);
}
private void OnNavMapBeaconMapInit(EntityUid uid, NavMapBeaconComponent component, MapInitEvent args)
{
component.Text ??= string.Empty;
component.Text = Loc.GetString(component.Text);
Dirty(uid, component);
}
[Serializable, NetSerializable]
protected sealed class NavMapComponentState : ComponentState
{
public Dictionary<Vector2i, int> TileData = new();
public List<NavMapBeacon> Beacons = new();
public List<NavMapAirlock> Airlocks = new();
}
[Serializable, NetSerializable]
public readonly record struct NavMapBeacon(Color Color, string Text, Vector2 Position);
[Serializable, NetSerializable]
public readonly record struct NavMapAirlock(Vector2 Position);
}