diff --git a/Content.Shared/GPS/Systems/HandheldGpsSystem.cs b/Content.Shared/GPS/Systems/HandheldGpsSystem.cs new file mode 100644 index 0000000000..6a8e4c08db --- /dev/null +++ b/Content.Shared/GPS/Systems/HandheldGpsSystem.cs @@ -0,0 +1,37 @@ +using Content.Shared.GPS.Components; +using Content.Shared.Examine; +using Robust.Shared.Map; + +namespace Content.Shared.GPS.Systems; + +public sealed class HandheldGpsSystem : EntitySystem +{ + [Dependency] private readonly SharedTransformSystem _transform = default!; + + /// + public override void Initialize() + { + base.Initialize(); + + SubscribeLocalEvent(OnExamine); + } + + /// + /// Handles showing the coordinates when a GPS is examined. + /// + private void OnExamine(Entity ent, ref ExaminedEvent args) + { + var posText = "Error"; + + var pos = _transform.GetMapCoordinates(ent); + + if (pos.MapId != MapId.Nullspace) + { + var x = (int) pos.Position.X; + var y = (int) pos.Position.Y; + posText = $"({x}, {y})"; + } + + args.PushMarkup(Loc.GetString("handheld-gps-coordinates-title", ("coordinates", posText))); + } +}