Fix mime wall & turf/tile helper issues. (#17844)

This commit is contained in:
Leon Friedrich
2023-07-06 16:43:49 +12:00
committed by GitHub
parent 88f9d2b6b8
commit 126f5d6dae
10 changed files with 55 additions and 38 deletions

View File

@@ -9,22 +9,25 @@ namespace Content.Shared.Coordinates.Helpers
{
IoCManager.Resolve(ref entMan, ref mapManager);
var gridIdOpt = coordinates.GetGridUid(entMan);
var gridId = coordinates.GetGridUid(entMan);
var tileSize = 1f;
if (gridIdOpt is EntityUid gridId && gridId.IsValid())
if (gridId == null)
{
var grid = mapManager.GetGrid(gridId);
tileSize = grid.TileSize;
var xformSys = entMan.System<SharedTransformSystem>();
var mapPos = coordinates.ToMap(entMan, xformSys);
var mapX = (int)Math.Floor(mapPos.X) + 0.5f;
var mapY = (int)Math.Floor(mapPos.Y) + 0.5f;
mapPos = new MapCoordinates(new Vector2(mapX, mapY), mapPos.MapId);
return EntityCoordinates.FromMap(coordinates.EntityId, mapPos, xformSys);
}
var localPos = coordinates.Position;
var grid = mapManager.GetGrid(gridId.Value);
var tileSize = grid.TileSize;
var localPos = coordinates.WithEntityId(gridId.Value).Position;
var x = (int)Math.Floor(localPos.X / tileSize) + tileSize / 2f;
var y = (int)Math.Floor(localPos.Y / tileSize) + tileSize / 2f;
return new EntityCoordinates(coordinates.EntityId, x, y);
var gridPos = new EntityCoordinates(gridId.Value, new Vector2(x, y));
return gridPos.WithEntityId(coordinates.EntityId);
}
public static EntityCoordinates SnapToGrid(this EntityCoordinates coordinates, MapGridComponent grid)

View File

@@ -140,13 +140,6 @@ namespace Content.Shared.Maps
return IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<TurfSystem>().IsTileBlocked(turf, mask);
}
public static EntityCoordinates GridPosition(this TileRef turf, IMapManager? mapManager = null)
{
mapManager ??= IoCManager.Resolve<IMapManager>();
return turf.GridIndices.ToEntityCoordinates(turf.GridUid, mapManager);
}
/// <summary>
/// Creates a box the size of a tile, at the same position in the world as the tile.
/// </summary>

View File

@@ -12,6 +12,7 @@ public sealed class TurfSystem : EntitySystem
{
[Dependency] private readonly EntityLookupSystem _entityLookup = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;
[Dependency] private readonly IMapManager _mapMan = default!;
/// <summary>
/// Returns true if a given tile is blocked by physics-enabled entities.
@@ -84,4 +85,14 @@ public sealed class TurfSystem : EntitySystem
return false;
}
/// <summary>
/// Returns the location of the centre of the tile in grid coordinates.
/// </summary>
public EntityCoordinates GetTileCenter(TileRef turf)
{
var grid = _mapMan.GetGrid(turf.GridUid);
var center = (turf.GridIndices + new Vector2(0.5f, 0.5f)) * grid.TileSize;
return new EntityCoordinates(turf.GridUid, center);
}
}