mirror of
https://github.com/wega-team/ss14-wega.git
synced 2026-02-14 19:30:01 +01:00
126 lines
4.7 KiB
C#
126 lines
4.7 KiB
C#
using Content.IntegrationTests.Tests.Interaction;
|
|
using Content.Server.Atmos.Components;
|
|
using Content.Server.Atmos.EntitySystems;
|
|
using Content.Shared.Atmos;
|
|
using Content.Shared.Atmos.Components;
|
|
using Content.Shared.Tests;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.Map.Components;
|
|
using Robust.Shared.Maths;
|
|
|
|
namespace Content.IntegrationTests.Tests.Atmos;
|
|
|
|
/// <summary>
|
|
/// Helper class for atmospherics tests.
|
|
/// See <see cref="TileAtmosphereTest"/> on how to add new tests with custom maps.
|
|
/// </summary>
|
|
[TestFixture]
|
|
public abstract class AtmosTest : InteractionTest
|
|
{
|
|
protected AtmosphereSystem SAtmos = default!;
|
|
protected Content.Client.Atmos.EntitySystems.AtmosphereSystem CAtmos = default!;
|
|
protected EntityLookupSystem LookupSystem = default!;
|
|
|
|
protected Entity<GridAtmosphereComponent> RelevantAtmos;
|
|
|
|
/// <summary>
|
|
/// Used in <see cref="AtmosphereSystem.RunProcessingFull"/>. Resolved during test setup.
|
|
/// </summary>
|
|
protected Entity<GridAtmosphereComponent, GasTileOverlayComponent, MapGridComponent, TransformComponent> ProcessEnt = default;
|
|
|
|
protected virtual float Moles => 1000.0f;
|
|
|
|
// 5% is a lot, but it can get this bad ATM...
|
|
protected virtual float Tolerance => 0.05f;
|
|
|
|
[SetUp]
|
|
public override async Task Setup()
|
|
{
|
|
await base.Setup();
|
|
|
|
SAtmos = SEntMan.System<AtmosphereSystem>();
|
|
CAtmos = CEntMan.System<Content.Client.Atmos.EntitySystems.AtmosphereSystem>();
|
|
LookupSystem = SEntMan.System<EntityLookupSystem>();
|
|
|
|
SEntMan.TryGetComponent<GridAtmosphereComponent>(MapData.Grid, out var gridAtmosComp);
|
|
SEntMan.TryGetComponent<GasTileOverlayComponent>(MapData.Grid, out var overlayComp);
|
|
SEntMan.TryGetComponent<MapGridComponent>(MapData.Grid, out var mapGridComp);
|
|
var xform = SEntMan.GetComponent<TransformComponent>(MapData.Grid);
|
|
|
|
using (Assert.EnterMultipleScope())
|
|
{
|
|
Assert.That(gridAtmosComp,
|
|
Is.Not.Null,
|
|
"Loaded map doesn't have a GridAtmosphereComponent on its grid. " +
|
|
"Did you forget to override TestMapPath with a proper atmospherics testing map?");
|
|
Assert.That(overlayComp,
|
|
Is.Not.Null,
|
|
"Loaded map doesn't have a GasTileOverlayComponent on its grid. " +
|
|
"Did you forget to override TestMapPath with a proper atmospherics testing map?");
|
|
Assert.That(mapGridComp,
|
|
Is.Not.Null,
|
|
"Loaded map doesn't have a MapGridComponent on its grid. " +
|
|
"Did you forget to override TestMapPath with a proper atmospherics testing map?");
|
|
}
|
|
|
|
RelevantAtmos = (MapData.Grid, gridAtmosComp);
|
|
|
|
ProcessEnt = new Entity<GridAtmosphereComponent, GasTileOverlayComponent, MapGridComponent, TransformComponent>(
|
|
MapData.Grid.Owner,
|
|
gridAtmosComp,
|
|
overlayComp,
|
|
mapGridComp,
|
|
xform);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tries to get a mapped <see cref="TestMarkerComponent"/> marker with a given name.
|
|
/// </summary>
|
|
/// <param name="markers">Marker entities to look through</param>
|
|
/// <param name="id">Marker name to look up (set during mapping)</param>
|
|
/// <param name="marker">Found marker EntityUid or Invalid</param>
|
|
/// <returns>True if found</returns>
|
|
protected static bool GetMarker(Entity<TestMarkerComponent>[] markers, string id, out EntityUid marker)
|
|
{
|
|
foreach (var ent in markers)
|
|
{
|
|
if (ent.Comp.Id == id)
|
|
{
|
|
marker = ent;
|
|
return true;
|
|
}
|
|
}
|
|
marker = EntityUid.Invalid;
|
|
return false;
|
|
}
|
|
|
|
protected static float GetGridMoles(Entity<GridAtmosphereComponent> grid)
|
|
{
|
|
var moles = 0.0f;
|
|
foreach (var tile in grid.Comp.Tiles.Values)
|
|
{
|
|
moles += tile.Air?.TotalMoles ?? 0.0f;
|
|
}
|
|
|
|
return moles;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Asserts that test grid has this many moles, within tolerance percentage.
|
|
/// </summary>
|
|
protected void AssertGridMoles(float moles, float tolerance)
|
|
{
|
|
var gridMoles = GetGridMoles(RelevantAtmos);
|
|
Assert.That(MathHelper.CloseToPercent(moles, gridMoles, tolerance), $"Grid has {gridMoles} moles, but {moles} was expected");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Asserts that provided GasMixtures have same total moles, within tolerance percentage.
|
|
/// </summary>
|
|
protected void AssertMixMoles(GasMixture mix1, GasMixture mix2, float tolerance)
|
|
{
|
|
Assert.That(MathHelper.CloseToPercent(mix1.TotalMoles, mix2.TotalMoles, tolerance),
|
|
$"GasMixtures do not match. Got {mix1.TotalMoles} and {mix2.TotalMoles} moles");
|
|
}
|
|
}
|