Atmos GetAirflowDirections API (#42668)

This commit is contained in:
ArtisticRoomba
2026-02-01 11:55:50 -08:00
committed by GitHub
parent 66615bf6aa
commit a0e6d0553a
2 changed files with 73 additions and 0 deletions

View File

@@ -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));
});
}
}

View File

@@ -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