Skip to content

Commit

Permalink
more
Browse files Browse the repository at this point in the history
  • Loading branch information
plykiya committed Jul 14, 2024
1 parent 545800b commit 6ba79ae
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Content.Shared/Coordinates/Helpers/SnapgridHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ public static class SnapgridHelper
public static EntityCoordinates SnapToGrid(this EntityCoordinates coordinates, IEntityManager? entMan = null, IMapManager? mapManager = null)
{
IoCManager.Resolve(ref entMan, ref mapManager);
var xformSys = entMan.System<SharedTransformSystem>();

var gridId = entMan.System<SharedTransformSystem>().GetGrid(coordinates);

if (gridId == null)
{
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;
Expand All @@ -24,11 +24,11 @@ public static EntityCoordinates SnapToGrid(this EntityCoordinates coordinates, I

var grid = entMan.GetComponent<MapGridComponent>(gridId.Value);
var tileSize = grid.TileSize;
var localPos = coordinates.WithEntityId(gridId.Value).Position;
var localPos = xformSys.WithEntityId(coordinates, gridId.Value).Position;
var x = (int)Math.Floor(localPos.X / tileSize) + tileSize / 2f;
var y = (int)Math.Floor(localPos.Y / tileSize) + tileSize / 2f;
var gridPos = new EntityCoordinates(gridId.Value, new Vector2(x, y));
return gridPos.WithEntityId(coordinates.EntityId);
return xformSys.WithEntityId(gridPos, coordinates.EntityId);
}

public static EntityCoordinates SnapToGrid(this EntityCoordinates coordinates, MapGridComponent grid)
Expand Down

0 comments on commit 6ba79ae

Please sign in to comment.