Add extension methods for getting adjacent tiles randomly and to offset coordinates in a direction

This commit is contained in:
DrSmugleaf
2020-09-01 23:28:59 +02:00
parent 9398f90e7c
commit 8a14725539
3 changed files with 109 additions and 40 deletions

View File

@@ -1,5 +1,6 @@
#nullable enable
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using Content.Shared.Physics;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Map;
@@ -59,6 +60,11 @@ namespace Content.Shared.Maps
return tile;
}
public static bool TryGetTileRef(this GridCoordinates coordinates, [NotNullWhen(true)] out TileRef? turf)
{
return (turf = coordinates.GetTileRef()) != null;
}
/// <summary>
/// Helper that returns all entities in a turf.
/// </summary>
@@ -92,6 +98,11 @@ namespace Content.Shared.Maps
return false;
}
public static GridCoordinates GridPosition(this TileRef turf)
{
return new GridCoordinates(turf.X, turf.Y, turf.GridIndex);
}
/// <summary>
/// Creates a box the size of a tile, at the same position in the world as the tile.
/// </summary>