From 4b388c20387ff9e84c2556dc0335f40ff062f72b Mon Sep 17 00:00:00 2001 From: FoxxoTrystan Date: Tue, 5 Nov 2024 14:15:48 +0100 Subject: [PATCH] port --- .../Tests/Atmos/GridJoinTest.cs | 49 +++++++++++++++++++ .../Piping/EntitySystems/AtmosDeviceSystem.cs | 5 +- 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 Content.IntegrationTests/Tests/Atmos/GridJoinTest.cs diff --git a/Content.IntegrationTests/Tests/Atmos/GridJoinTest.cs b/Content.IntegrationTests/Tests/Atmos/GridJoinTest.cs new file mode 100644 index 00000000000..3e39c3de5aa --- /dev/null +++ b/Content.IntegrationTests/Tests/Atmos/GridJoinTest.cs @@ -0,0 +1,49 @@ +using Content.Server.Atmos.Components; +using Content.Server.Atmos.EntitySystems; +using Content.Server.Atmos.Piping.Components; +using Content.Server.Atmos.Piping.EntitySystems; +using Robust.Shared.GameObjects; + +namespace Content.IntegrationTests.Tests.Atmos; + +[TestFixture] +public sealed class GridJoinTest +{ + private const string CanisterProtoId = "AirCanister"; + + [Test] + public async Task TestGridJoinAtmosphere() + { + await using var pair = await PoolManager.GetServerClient(); + var server = pair.Server; + + var entMan = server.EntMan; + var protoMan = server.ProtoMan; + var atmosSystem = entMan.System(); + var atmosDeviceSystem = entMan.System(); + var transformSystem = entMan.System(); + + var testMap = await pair.CreateTestMap(); + + await server.WaitPost(() => + { + // Spawn an atmos device on the grid + var canister = entMan.Spawn(CanisterProtoId); + transformSystem.SetCoordinates(canister, testMap.GridCoords); + var deviceComp = entMan.GetComponent(canister); + var canisterEnt = (canister, deviceComp); + // Make sure the canister is tracked as an off-grid device + Assert.That(atmosDeviceSystem.IsJoinedOffGrid(canisterEnt)); + // Add an atmosphere to the grid + entMan.AddComponent(testMap.Grid); + // Force AtmosDeviceSystem to update off-grid devices + // This means the canister is now considered on-grid, + // but it's still tracked as off-grid! + Assert.DoesNotThrow(() => atmosDeviceSystem.Update(atmosSystem.AtmosTime)); + // Make sure that the canister is now properly tracked as on-grid + Assert.That(atmosDeviceSystem.IsJoinedOffGrid(canisterEnt), Is.False); + }); + + await pair.CleanReturnAsync(); + } +} diff --git a/Content.Server/Atmos/Piping/EntitySystems/AtmosDeviceSystem.cs b/Content.Server/Atmos/Piping/EntitySystems/AtmosDeviceSystem.cs index 3c73a8f64ee..421d4da5e34 100644 --- a/Content.Server/Atmos/Piping/EntitySystems/AtmosDeviceSystem.cs +++ b/Content.Server/Atmos/Piping/EntitySystems/AtmosDeviceSystem.cs @@ -132,7 +132,10 @@ public override void Update(float frameTime) var ev = new AtmosDeviceUpdateEvent(_atmosphereSystem.AtmosTime, null, null); foreach (var device in _joinedDevices) { - DebugTools.Assert(!HasComp(Transform(device).GridUid)); + var deviceGrid = Transform(device).GridUid; + if (HasComp(deviceGrid)) + RejoinAtmosphere(device); + RaiseLocalEvent(device, ref ev); device.Comp.LastProcess = time; }