Add InvalidateTileAir Transform extension method (#2687)
* Add InvalidateTileAir Transform extension method * Add extension method for EntityCoordinates as well
This commit is contained in:
@@ -3,6 +3,7 @@ using System.Diagnostics.CodeAnalysis;
|
|||||||
using Content.Server.GameObjects.EntitySystems;
|
using Content.Server.GameObjects.EntitySystems;
|
||||||
using Robust.Shared.GameObjects.Systems;
|
using Robust.Shared.GameObjects.Systems;
|
||||||
using Robust.Shared.Interfaces.GameObjects;
|
using Robust.Shared.Interfaces.GameObjects;
|
||||||
|
using Robust.Shared.Interfaces.GameObjects.Components;
|
||||||
using Robust.Shared.IoC;
|
using Robust.Shared.IoC;
|
||||||
using Robust.Shared.Map;
|
using Robust.Shared.Map;
|
||||||
using Robust.Shared.Maths;
|
using Robust.Shared.Maths;
|
||||||
@@ -11,18 +12,18 @@ namespace Content.Server.Atmos
|
|||||||
{
|
{
|
||||||
public static class AtmosHelpers
|
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<IEntityManager>();
|
entityManager ??= IoCManager.Resolve<IEntityManager>();
|
||||||
|
|
||||||
var gridAtmos = EntitySystem.Get<AtmosphereSystem>().GetGridAtmosphere(coordinates.GetGridId(entityManager));
|
var gridAtmos = EntitySystem.Get<AtmosphereSystem>().GetGridAtmosphere(coordinates.GetGridId(entityManager));
|
||||||
|
|
||||||
return gridAtmos?.GetTile(coordinates);
|
return gridAtmos.GetTile(coordinates);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static GasMixture? GetTileAir(this EntityCoordinates coordinates, IEntityManager? entityManager = null)
|
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)
|
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);
|
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<AtmosphereSystem>().GetGridAtmosphere(gridId);
|
var gridAtmos = EntitySystem.Get<AtmosphereSystem>().GetGridAtmosphere(gridId);
|
||||||
|
|
||||||
return gridAtmos?.GetTile(indices);
|
return gridAtmos.GetTile(indices);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static GasMixture? GetTileAir(this Vector2i indices, GridId gridId)
|
public static GasMixture? GetTileAir(this Vector2i indices, GridId gridId)
|
||||||
@@ -61,5 +62,33 @@ namespace Content.Server.Atmos
|
|||||||
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
|
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
|
||||||
return !Equals(air = indices.GetTileAir(gridId)!, default);
|
return !Equals(air = indices.GetTileAir(gridId)!, default);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool InvalidateTileAir(this ITransformComponent transform, AtmosphereSystem? atmosSystem = null)
|
||||||
|
{
|
||||||
|
atmosSystem ??= EntitySystem.Get<AtmosphereSystem>();
|
||||||
|
|
||||||
|
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<AtmosphereSystem>();
|
||||||
|
entityManager ??= IoCManager.Resolve<IEntityManager>();
|
||||||
|
|
||||||
|
if (!coordinates.TryGetTileAtmosphere(out var tileAtmos))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var gridId = coordinates.GetGridId(entityManager);
|
||||||
|
atmosSystem.GetGridAtmosphere(gridId).Invalidate(tileAtmos.GridIndices);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ namespace Content.Server.GameObjects.Components.Atmos
|
|||||||
return true;
|
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);
|
return new(this, GridId.Invalid, indices, new GasMixture(2500, AtmosphereSystem), true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ namespace Content.Server.GameObjects.EntitySystems
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IGridAtmosphereComponent? GetGridAtmosphere(GridId gridId)
|
public IGridAtmosphereComponent GetGridAtmosphere(GridId gridId)
|
||||||
{
|
{
|
||||||
if (!gridId.IsValid())
|
if (!gridId.IsValid())
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user