Files
wwdpublic/Content.IntegrationTests/Tests/Wires/WireLayoutTest.cs
SimpleStation14 5c2cff0022 Mirror: Fix wire layout inheritance. (#284)
## Mirror of PR #26289: [Fix wire layout
inheritance.](https://github.com/space-wizards/space-station-14/pull/26289)
from <img src="https://avatars.githubusercontent.com/u/10567778?v=4"
alt="space-wizards" width="22"/>
[space-wizards](https://github.com/space-wizards)/[space-station-14](https://github.com/space-wizards/space-station-14)

###### `a4692004de978cda6761d4090e13ed4d8bc1fa11`

PR opened by <img
src="https://avatars.githubusercontent.com/u/8107459?v=4" width="16"/><a
href="https://github.com/PJB3005"> PJB3005</a> at 2024-03-20 14:42:55
UTC

---

PR changed 2 files with 105 additions and 0 deletions.

The PR had the following labels:


---

<details open="true"><summary><h1>Original Body</h1></summary>

> Wire layouts manually navigate the inheritance hierarchy, but the data
fields on the prototypes were also automatically inherited already. This
meant that inheriting a wire layout prototype and changing nothing would
cause the wires to be duplicated unless they were manually modified on
top.
> 
> Fix is easy: just disable inheritance on the data fields.
> 
> Also, integration test for it.
> 


</details>

Co-authored-by: SimpleStation14 <Unknown>
Co-authored-by: Danger Revolution! <142105406+DangerRevolution@users.noreply.github.com>
2024-05-29 00:19:32 -04:00

104 lines
4.0 KiB
C#

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<IEntitySystemManager>().GetEntitySystem<WiresSystem>();
// Need to spawn these entities to make sure the wire layouts are initialized.
var ent1 = SpawnWithComp<WiresComponent>(server.EntMan, "WireLayoutTest", testMap.MapCoords);
var ent2 = SpawnWithComp<WiresComponent>(server.EntMan, "WireLayoutTest2", testMap.MapCoords);
var ent3 = SpawnWithComp<WiresComponent>(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<PowerWireAction>(), "1 power wire");
Assert.That(ent1.Comp.WiresList, Has.One.With.Property("Action").InstanceOf<DoorBoltWireAction>(), "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<PowerWireAction>(), "2 power wire");
Assert.That(ent2.Comp.WiresList, Has.One.With.Property("Action").InstanceOf<DoorBoltWireAction>(), "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<PowerWireAction>(), "1 power wire");
Assert.That(ent3.Comp.WiresList, Has.One.With.Property("Action").InstanceOf<DoorBoltWireAction>(), "1 door bolt wire");
});
});
await pair.CleanReturnAsync();
}
private static Entity<T> SpawnWithComp<T>(IEntityManager entityManager, string prototype, MapCoordinates coords)
where T : IComponent, new()
{
var ent = entityManager.Spawn(prototype, coords);
var comp = entityManager.EnsureComponent<T>(ent);
return new Entity<T>(ent, comp);
}
}