mirror of
https://github.com/space-wizards/space-station-14.git
synced 2026-02-14 19:29:53 +01:00
Atmos GetAirflowDirections API (#42668)
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
using Content.Server.Atmos.EntitySystems;
|
||||
using Content.Shared.Atmos;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.IntegrationTests.Tests.Atmos;
|
||||
|
||||
/// <summary>
|
||||
/// Class for testing some airflow retrieval API methods.
|
||||
/// </summary>
|
||||
public sealed class GetAirflowDirectionsTest : AtmosTest
|
||||
{
|
||||
// i will keep using this test map until it has been drained
|
||||
// of all use
|
||||
protected override ResPath? TestMapPath => new("Maps/Test/Atmospherics/DeltaPressure/deltapressuretest.yml");
|
||||
|
||||
[Test]
|
||||
[TestCase(0, 0, AtmosDirection.All)]
|
||||
[TestCase(0, 1, AtmosDirection.South)]
|
||||
[TestCase(0, -1, AtmosDirection.North)]
|
||||
[TestCase(1, 0, AtmosDirection.West)]
|
||||
[TestCase(-1, 0, AtmosDirection.East)]
|
||||
[TestCase(1, 1, AtmosDirection.Invalid)]
|
||||
[TestCase(100, 100, AtmosDirection.Invalid)]
|
||||
public async Task TestLookup(int x, int y, AtmosDirection expectedDirections)
|
||||
{
|
||||
await Server.WaitPost(delegate
|
||||
{
|
||||
// yea
|
||||
var coords = new Vector2i(x, y);
|
||||
var directions = SAtmos.GetAirflowDirections(RelevantAtmos, coords);
|
||||
Assert.That(directions, Is.EqualTo(expectedDirections));
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests that a grident with no atmosphere will return <see cref="AtmosDirection.Invalid"/>.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task TestLookup_BadEnt()
|
||||
{
|
||||
await Server.WaitPost(delegate
|
||||
{
|
||||
var directions = SAtmos.GetAirflowDirections(EntityUid.Invalid, Vector2i.Zero);
|
||||
Assert.That(directions, Is.EqualTo(AtmosDirection.Invalid));
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -350,6 +350,29 @@ public partial class AtmosphereSystem
|
||||
return atmosTile.AirtightData.BlockedDirections.IsFlagSet(directions);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the <see cref="TileAtmosphere.AdjacentBits"/> for a tile on a grid.
|
||||
/// This represents the directions that the air can currently flow to.
|
||||
/// </summary>
|
||||
/// <param name="grid">The grid entity that the tile belongs to.</param>
|
||||
/// <param name="tile">The <see cref="Vector2i"/> coordinates to check.</param>
|
||||
/// <returns>The <see cref="TileAtmosphere.AdjacentBits"/> of the tile,
|
||||
/// <see cref="AtmosDirection.Invalid"/> if the grid or tile couldn't be found.</returns>
|
||||
/// <remarks>Note that this data is cached and is updated at the beginning of every atmostick.
|
||||
/// As such, any airtight changes that were made may not be reflected in this value until
|
||||
/// the cache is refreshed in the next processing tick.</remarks>
|
||||
[PublicAPI]
|
||||
public AtmosDirection GetAirflowDirections(Entity<GridAtmosphereComponent?> grid, Vector2i tile)
|
||||
{
|
||||
if (!_atmosQuery.Resolve(grid, ref grid.Comp, false))
|
||||
return AtmosDirection.Invalid;
|
||||
|
||||
if (!grid.Comp.Tiles.TryGetValue(tile, out var atmosTile))
|
||||
return AtmosDirection.Invalid;
|
||||
|
||||
return atmosTile.AdjacentBits;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a tile on a grid or map is space as defined by a tile's definition of space.
|
||||
/// Some tiles can hold back space and others cannot - for example, plating can hold
|
||||
|
||||
Reference in New Issue
Block a user