From 282989b3610c1655da446338c1da2bec2365c16c Mon Sep 17 00:00:00 2001 From: SimpleStation14 Date: Mon, 22 Apr 2024 05:47:02 -0400 Subject: [PATCH] Cherry-picked commit a4692004de978cda6761d4090e13ed4d8bc1fa11 from space-wizards/space-station-14/master --- .../Tests/Wires/WireLayoutTest.cs | 103 ++++++++++++++++++ Content.Server/Wires/WireLayout.cs | 2 + 2 files changed, 105 insertions(+) create mode 100644 Content.IntegrationTests/Tests/Wires/WireLayoutTest.cs diff --git a/Content.IntegrationTests/Tests/Wires/WireLayoutTest.cs b/Content.IntegrationTests/Tests/Wires/WireLayoutTest.cs new file mode 100644 index 00000000000..920dc088186 --- /dev/null +++ b/Content.IntegrationTests/Tests/Wires/WireLayoutTest.cs @@ -0,0 +1,103 @@ +using Content.Server.Doors; +using Content.Server.Power; +using Content.Server.Wires; +using Robust.Shared.GameObjects; +using Robust.Shared.IoC; +using Robust.Shared.Map; + +namespace Content.IntegrationTests.Tests.Wires; + +[TestFixture] +[Parallelizable(ParallelScope.All)] +[TestOf(typeof(WiresSystem))] +public sealed class WireLayoutTest +{ + [TestPrototypes] + public const string Prototypes = """ + - type: wireLayout + id: WireLayoutTest + dummyWires: 2 + wires: + - !type:PowerWireAction + - !type:DoorBoltWireAction + + - type: wireLayout + id: WireLayoutTest2 + parent: WireLayoutTest + wires: + - !type:PowerWireAction + + - type: wireLayout + id: WireLayoutTest3 + parent: WireLayoutTest + + - type: entity + id: WireLayoutTest + components: + - type: Wires + layoutId: WireLayoutTest + + - type: entity + id: WireLayoutTest2 + components: + - type: Wires + layoutId: WireLayoutTest2 + + - type: entity + id: WireLayoutTest3 + components: + - type: Wires + layoutId: WireLayoutTest3 + """; + + [Test] + public async Task TestLayoutInheritance() + { + await using var pair = await PoolManager.GetServerClient(); + var server = pair.Server; + var testMap = await pair.CreateTestMap(); + + await server.WaitAssertion(() => + { + var wires = IoCManager.Resolve().GetEntitySystem(); + + // Need to spawn these entities to make sure the wire layouts are initialized. + var ent1 = SpawnWithComp(server.EntMan, "WireLayoutTest", testMap.MapCoords); + var ent2 = SpawnWithComp(server.EntMan, "WireLayoutTest2", testMap.MapCoords); + var ent3 = SpawnWithComp(server.EntMan, "WireLayoutTest3", testMap.MapCoords); + + // Assert.That(wires.TryGetLayout("WireLayoutTest", out var layout1)); + // Assert.That(wires.TryGetLayout("WireLayoutTest2", out var layout2)); + // Assert.That(wires.TryGetLayout("WireLayoutTest3", out var layout3)); + + Assert.Multiple(() => + { + // Entity 1. + Assert.That(ent1.Comp.WiresList, Has.Count.EqualTo(4)); + Assert.That(ent1.Comp.WiresList, Has.Exactly(2).With.Property("Action").Null, "2 dummy wires"); + Assert.That(ent1.Comp.WiresList, Has.One.With.Property("Action").InstanceOf(), "1 power wire"); + Assert.That(ent1.Comp.WiresList, Has.One.With.Property("Action").InstanceOf(), "1 door bolt wire"); + + Assert.That(ent2.Comp.WiresList, Has.Count.EqualTo(5)); + Assert.That(ent2.Comp.WiresList, Has.Exactly(2).With.Property("Action").Null, "2 dummy wires"); + Assert.That(ent2.Comp.WiresList, Has.Exactly(2).With.Property("Action").InstanceOf(), "2 power wire"); + Assert.That(ent2.Comp.WiresList, Has.One.With.Property("Action").InstanceOf(), "1 door bolt wire"); + + Assert.That(ent3.Comp.WiresList, Has.Count.EqualTo(4)); + Assert.That(ent3.Comp.WiresList, Has.Exactly(2).With.Property("Action").Null, "2 dummy wires"); + Assert.That(ent3.Comp.WiresList, Has.One.With.Property("Action").InstanceOf(), "1 power wire"); + Assert.That(ent3.Comp.WiresList, Has.One.With.Property("Action").InstanceOf(), "1 door bolt wire"); + }); + }); + + await pair.CleanReturnAsync(); + } + + private static Entity SpawnWithComp(IEntityManager entityManager, string prototype, MapCoordinates coords) + where T : IComponent, new() + { + var ent = entityManager.Spawn(prototype, coords); + var comp = entityManager.EnsureComponent(ent); + return new Entity(ent, comp); + } +} diff --git a/Content.Server/Wires/WireLayout.cs b/Content.Server/Wires/WireLayout.cs index ecafba013e0..621992c915a 100644 --- a/Content.Server/Wires/WireLayout.cs +++ b/Content.Server/Wires/WireLayout.cs @@ -28,11 +28,13 @@ public sealed partial class WireLayoutPrototype : IPrototype, IInheritingPrototy /// initialization) /// [DataField("dummyWires")] + [NeverPushInheritance] public int DummyWires { get; private set; } = default!; /// /// All the valid IWireActions currently in this layout. /// [DataField("wires")] + [NeverPushInheritance] public List? Wires { get; private set; } }