From de0975c228b927da74f5a651cf462a56fa2819fd Mon Sep 17 00:00:00 2001 From: DrSmugleaf Date: Fri, 4 Dec 2020 12:21:57 +0100 Subject: [PATCH] Add InvalidateTileAir Transform extension method (#2687) * Add InvalidateTileAir Transform extension method * Add extension method for EntityCoordinates as well --- Content.Server/Atmos/AtmosHelpers.cs | 39 ++++++++++++++++--- .../Atmos/SpaceGridAtmosphereComponent.cs | 2 +- .../EntitySystems/AtmosphereSystem.cs | 2 +- 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/Content.Server/Atmos/AtmosHelpers.cs b/Content.Server/Atmos/AtmosHelpers.cs index 9f01f8090a..21d85a0b08 100644 --- a/Content.Server/Atmos/AtmosHelpers.cs +++ b/Content.Server/Atmos/AtmosHelpers.cs @@ -3,6 +3,7 @@ using System.Diagnostics.CodeAnalysis; using Content.Server.GameObjects.EntitySystems; using Robust.Shared.GameObjects.Systems; using Robust.Shared.Interfaces.GameObjects; +using Robust.Shared.Interfaces.GameObjects.Components; using Robust.Shared.IoC; using Robust.Shared.Map; using Robust.Shared.Maths; @@ -11,18 +12,18 @@ namespace Content.Server.Atmos { public static class AtmosHelpers { - public static TileAtmosphere? GetTileAtmosphere(this EntityCoordinates coordinates, IEntityManager? entityManager = null) + public static TileAtmosphere GetTileAtmosphere(this EntityCoordinates coordinates, IEntityManager? entityManager = null) { entityManager ??= IoCManager.Resolve(); var gridAtmos = EntitySystem.Get().GetGridAtmosphere(coordinates.GetGridId(entityManager)); - return gridAtmos?.GetTile(coordinates); + return gridAtmos.GetTile(coordinates); } public static GasMixture? GetTileAir(this EntityCoordinates coordinates, IEntityManager? entityManager = null) { - return coordinates.GetTileAtmosphere(entityManager)?.Air; + return coordinates.GetTileAtmosphere(entityManager).Air; } public static bool TryGetTileAtmosphere(this EntityCoordinates coordinates, [MaybeNullWhen(false)] out TileAtmosphere atmosphere) @@ -37,11 +38,11 @@ namespace Content.Server.Atmos return !Equals(air = coordinates.GetTileAir(entityManager)!, default); } - public static TileAtmosphere? GetTileAtmosphere(this Vector2i indices, GridId gridId) + public static TileAtmosphere GetTileAtmosphere(this Vector2i indices, GridId gridId) { var gridAtmos = EntitySystem.Get().GetGridAtmosphere(gridId); - return gridAtmos?.GetTile(indices); + return gridAtmos.GetTile(indices); } public static GasMixture? GetTileAir(this Vector2i indices, GridId gridId) @@ -61,5 +62,33 @@ namespace Content.Server.Atmos // ReSharper disable once ConditionIsAlwaysTrueOrFalse return !Equals(air = indices.GetTileAir(gridId)!, default); } + + public static bool InvalidateTileAir(this ITransformComponent transform, AtmosphereSystem? atmosSystem = null) + { + atmosSystem ??= EntitySystem.Get(); + + if (!transform.Coordinates.TryGetTileAtmosphere(out var tileAtmos)) + { + return false; + } + + atmosSystem.GetGridAtmosphere(transform.GridID).Invalidate(tileAtmos.GridIndices); + return true; + } + + public static bool InvalidateTileAir(this EntityCoordinates coordinates, AtmosphereSystem? atmosSystem = null, IEntityManager? entityManager = null) + { + atmosSystem ??= EntitySystem.Get(); + entityManager ??= IoCManager.Resolve(); + + if (!coordinates.TryGetTileAtmosphere(out var tileAtmos)) + { + return false; + } + + var gridId = coordinates.GetGridId(entityManager); + atmosSystem.GetGridAtmosphere(gridId).Invalidate(tileAtmos.GridIndices); + return true; + } } } diff --git a/Content.Server/GameObjects/Components/Atmos/SpaceGridAtmosphereComponent.cs b/Content.Server/GameObjects/Components/Atmos/SpaceGridAtmosphereComponent.cs index 8d67afc946..69edf093d7 100644 --- a/Content.Server/GameObjects/Components/Atmos/SpaceGridAtmosphereComponent.cs +++ b/Content.Server/GameObjects/Components/Atmos/SpaceGridAtmosphereComponent.cs @@ -18,7 +18,7 @@ namespace Content.Server.GameObjects.Components.Atmos return true; } - public override TileAtmosphere? GetTile(Vector2i indices, bool createSpace = true) + public override TileAtmosphere GetTile(Vector2i indices, bool createSpace = true) { return new(this, GridId.Invalid, indices, new GasMixture(2500, AtmosphereSystem), true); } diff --git a/Content.Server/GameObjects/EntitySystems/AtmosphereSystem.cs b/Content.Server/GameObjects/EntitySystems/AtmosphereSystem.cs index ef7359e8e5..2864d813b0 100644 --- a/Content.Server/GameObjects/EntitySystems/AtmosphereSystem.cs +++ b/Content.Server/GameObjects/EntitySystems/AtmosphereSystem.cs @@ -125,7 +125,7 @@ namespace Content.Server.GameObjects.EntitySystems } } - public IGridAtmosphereComponent? GetGridAtmosphere(GridId gridId) + public IGridAtmosphereComponent GetGridAtmosphere(GridId gridId) { if (!gridId.IsValid()) {