Skip to content
This repository has been archived by the owner on Nov 1, 2024. It is now read-only.

Map fix #161

Merged
merged 2 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Content.Client/Shuttles/Systems/ShuttleSystem.Console.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public Texture GetTexture(Entity<ShuttleMapParallaxComponent?> entity)
/// <summary>
/// Gets the map coordinates of a map object.
/// </summary>
public MapCoordinates GetMapCoordinates(IMapObject mapObj)
public MapCoordinates? GetMapCoordinates(IMapObject mapObj)
{
switch (mapObj)
{
Expand All @@ -39,7 +39,8 @@ public MapCoordinates GetMapCoordinates(IMapObject mapObj)
case ShuttleExclusionObject exclusion:
return GetCoordinates(exclusion.Coordinates).ToMap(EntityManager, XformSystem);
case GridMapObject grid:
var gridXform = Transform(grid.Entity);
if (!TryComp<TransformComponent>(grid.Entity, out var gridXform))
return null;

if (HasComp<MapComponent>(grid.Entity))
{
Expand Down
16 changes: 14 additions & 2 deletions Content.Client/Shuttles/UI/MapScreen.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,16 @@ private void RebuildMapObjects()
var yMapPos = _shuttles.GetMapCoordinates(y.mapobj);
var xMapPos = _shuttles.GetMapCoordinates(x.mapobj);

return (yMapPos.Position - shuttlePos).Length().CompareTo((xMapPos.Position - shuttlePos).Length());
if (xMapPos is not null && yMapPos is null)
return 1;

if (yMapPos is not null && xMapPos is null)
return -1;

if (xMapPos is null && yMapPos is null)
return 0;

return (yMapPos!.Value.Position - shuttlePos).Length().CompareTo((xMapPos!.Value.Position - shuttlePos).Length());
});
}

Expand Down Expand Up @@ -418,8 +427,11 @@ private void OnMapObjectPress(IMapObject mapObject)

var coordinates = _shuttles.GetMapCoordinates(mapObject);

if (coordinates is null)
return;

// If it's our map then scroll, otherwise just set position there.
MapRadar.SetMap(coordinates.MapId, coordinates.Position, recentering: true);
MapRadar.SetMap(coordinates.Value.MapId, coordinates.Value.Position, recentering: true);
}

public void SetMap(MapId mapId, Vector2 position)
Expand Down
5 changes: 4 additions & 1 deletion Content.Client/Shuttles/UI/ShuttleMapControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,10 @@ private List<IMapObject> GetViewportMapObjects(Matrix3 matty, List<IMapObject> m

var mapCoords = _shuttles.GetMapCoordinates(mapObj);

var relativePos = matty.Transform(mapCoords.Position);
if (mapCoords is null)
continue;

var relativePos = matty.Transform(mapCoords.Value.Position);
relativePos = relativePos with { Y = -relativePos.Y };
var uiPosition = ScalePosition(relativePos);

Expand Down
Loading