Re-organize all projects (#4166)
This commit is contained in:
34
Content.Server/Coordinates/Helpers/GridTileLookupHelpers.cs
Normal file
34
Content.Server/Coordinates/Helpers/GridTileLookupHelpers.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
#nullable enable
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
|
||||
namespace Content.Server.Coordinates.Helpers
|
||||
{
|
||||
public static class GridTileLookupHelpers
|
||||
{
|
||||
/// <summary>
|
||||
/// Helper that returns all entities in a turf very fast.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static IEnumerable<IEntity> GetEntitiesInTileFast(this TileRef turf, GridTileLookupSystem? gridTileLookup = null)
|
||||
{
|
||||
gridTileLookup ??= EntitySystem.Get<GridTileLookupSystem>();
|
||||
|
||||
return gridTileLookup.GetEntitiesIntersecting(turf.GridIndex, turf.GridIndices);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper that returns all entities in a turf.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static IEnumerable<IEntity> GetEntitiesInTileFast(this Vector2i indices, GridId gridId, GridTileLookupSystem? gridTileLookup = null)
|
||||
{
|
||||
gridTileLookup ??= EntitySystem.Get<GridTileLookupSystem>();
|
||||
return gridTileLookup.GetEntitiesIntersecting(gridId, indices);
|
||||
}
|
||||
}
|
||||
}
|
||||
50
Content.Server/Coordinates/Helpers/SnapgridHelper.cs
Normal file
50
Content.Server/Coordinates/Helpers/SnapgridHelper.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
|
||||
namespace Content.Server.Coordinates.Helpers
|
||||
{
|
||||
public static class SnapgridHelper
|
||||
{
|
||||
public static void SnapToGrid(this IEntity entity, IEntityManager? entityManager = null, IMapManager? mapManager = null)
|
||||
{
|
||||
entity.Transform.Coordinates = entity.Transform.Coordinates.SnapToGrid(entityManager, mapManager);
|
||||
}
|
||||
|
||||
public static EntityCoordinates SnapToGrid(this EntityCoordinates coordinates, IEntityManager? entityManager = null, IMapManager? mapManager = null)
|
||||
{
|
||||
entityManager ??= IoCManager.Resolve<IEntityManager>();
|
||||
mapManager ??= IoCManager.Resolve<IMapManager>();
|
||||
|
||||
var gridId = coordinates.GetGridId(entityManager);
|
||||
|
||||
var tileSize = 1f;
|
||||
|
||||
if (gridId.IsValid())
|
||||
{
|
||||
var grid = mapManager.GetGrid(gridId);
|
||||
tileSize = grid.TileSize;
|
||||
}
|
||||
|
||||
var localPos = coordinates.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);
|
||||
}
|
||||
|
||||
public static EntityCoordinates SnapToGrid(this EntityCoordinates coordinates, IMapGrid grid)
|
||||
{
|
||||
var tileSize = grid.TileSize;
|
||||
|
||||
var localPos = coordinates.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user