From 9063379af97450c32a8fb2795a7a324dbee5a387 Mon Sep 17 00:00:00 2001 From: DrSmugleaf Date: Sat, 1 Aug 2020 01:20:41 +0200 Subject: [PATCH] Fix build (#1551) * Fix conveyor and conveyor switch serialization * SS14 in reactive when * Fix new test fail with units being able to accept items when unpowered --- .../Tests/Disposal/DisposalUnitTest.cs | 38 ++++++++++--------- .../Components/Conveyor/ConveyorComponent.cs | 15 +++++--- .../Conveyor/ConveyorSwitchComponent.cs | 30 ++++++++++----- 3 files changed, 50 insertions(+), 33 deletions(-) diff --git a/Content.IntegrationTests/Tests/Disposal/DisposalUnitTest.cs b/Content.IntegrationTests/Tests/Disposal/DisposalUnitTest.cs index a004909e63..b8d887ead5 100644 --- a/Content.IntegrationTests/Tests/Disposal/DisposalUnitTest.cs +++ b/Content.IntegrationTests/Tests/Disposal/DisposalUnitTest.cs @@ -48,13 +48,13 @@ namespace Content.IntegrationTests.Tests.Disposal UnitContains(unit, result, entities); } - private void Flush(DisposalUnitComponent unit, bool result, DisposalEntryComponent? entry = null, IDisposalTubeComponent? next = null, params IEntity[] entities) + private void Flush(DisposalUnitComponent unit, bool result, DisposalEntryComponent? entry = null, params IEntity[] entities) { Assert.That(unit.ContainedEntities, Is.SupersetOf(entities)); - Assert.AreEqual(unit.ContainedEntities.Count, entities.Length); + Assert.That(entities.Length, Is.EqualTo(unit.ContainedEntities.Count)); - Assert.AreEqual(unit.TryFlush(), result); - Assert.AreEqual(unit.ContainedEntities.Count == 0, entry != null || entities.Length == 0); + Assert.That(result, Is.EqualTo(unit.TryFlush())); + Assert.That(result || entities.Length == 0, Is.EqualTo(unit.ContainedEntities.Count == 0)); } [Test] @@ -62,10 +62,10 @@ namespace Content.IntegrationTests.Tests.Disposal { var server = StartServerDummyTicker(); - IEntity human = null!; - IEntity wrench = null!; - DisposalUnitComponent unit = null!; - DisposalEntryComponent entry = null!; + IEntity human; + IEntity wrench; + DisposalUnitComponent unit; + DisposalEntryComponent entry; server.Assert(() => { @@ -88,8 +88,8 @@ namespace Content.IntegrationTests.Tests.Disposal // Can't insert, unanchored and unpowered var disposalUnitAnchorable = disposalUnit.GetComponent(); disposalUnitAnchorable.TryUnAnchor(human, null, true); - UnitInsertContains(unit, false, human, wrench, disposalUnit, disposalTrunk); Assert.False(unit.Anchored); + UnitInsertContains(unit, false, human, wrench, disposalUnit, disposalTrunk); // Anchor the disposal unit disposalUnitAnchorable.TryAnchor(human, null, true); @@ -97,15 +97,9 @@ namespace Content.IntegrationTests.Tests.Disposal Assert.True(anchorableUnit.TryAnchor(human, wrench)); Assert.True(unit.Anchored); - // Can't insert, unpowered - UnitInsertContains(unit, false, human, wrench, disposalUnit, disposalTrunk); + // No power Assert.False(unit.Powered); - // Remove power need - Assert.True(disposalUnit.TryGetComponent(out PowerReceiverComponent power)); - power.NeedsPower = false; - Assert.True(unit.Powered); - // Can't insert the trunk or the unit into itself UnitInsertContains(unit, false, disposalUnit, disposalTrunk); @@ -116,13 +110,21 @@ namespace Content.IntegrationTests.Tests.Disposal disposalTrunk.Transform.WorldPosition += (1, 0); // Fail to flush with a mob and an item - Flush(unit, false, null, null, human, wrench); + Flush(unit, false, null, human, wrench); // Move the disposal trunk back disposalTrunk.Transform.WorldPosition -= (1, 0); + // Fail to flush with a mob and an item, no power + Flush(unit, false, entry, human, wrench); + + // Remove power need + Assert.True(disposalUnit.TryGetComponent(out PowerReceiverComponent power)); + power.NeedsPower = false; + Assert.True(unit.Powered); + // Flush with a mob and an item - Flush(unit, true, entry, null, human, wrench); + Flush(unit, true, entry, human, wrench); // Re-pressurizing Flush(unit, false, entry); diff --git a/Content.Server/GameObjects/Components/Conveyor/ConveyorComponent.cs b/Content.Server/GameObjects/Components/Conveyor/ConveyorComponent.cs index bb988930d0..8faf21556d 100644 --- a/Content.Server/GameObjects/Components/Conveyor/ConveyorComponent.cs +++ b/Content.Server/GameObjects/Components/Conveyor/ConveyorComponent.cs @@ -208,16 +208,21 @@ namespace Content.Server.GameObjects.Components.Conveyor serializer.DataReadWriteFunction( "switches", - new List(), - switches => + new List(), + ids => { - if (switches == null) + if (ids == null) { return; } - foreach (var @switch in switches) + foreach (var id in ids) { + if (!Owner.EntityManager.TryGetEntity(id, out var @switch)) + { + continue; + } + if (!@switch.TryGetComponent(out ConveyorSwitchComponent component)) { continue; @@ -226,7 +231,7 @@ namespace Content.Server.GameObjects.Components.Conveyor component.Connect(this); } }, - () => _group?.Switches.Select(@switch => @switch.Owner)); + () => _group?.Switches.Select(@switch => @switch.Owner.Uid).ToList()); serializer.DataField(ref _angle, "angle", 0); serializer.DataField(ref _speed, "speed", 2); diff --git a/Content.Server/GameObjects/Components/Conveyor/ConveyorSwitchComponent.cs b/Content.Server/GameObjects/Components/Conveyor/ConveyorSwitchComponent.cs index 951b8d9a9e..208b0ceeec 100644 --- a/Content.Server/GameObjects/Components/Conveyor/ConveyorSwitchComponent.cs +++ b/Content.Server/GameObjects/Components/Conveyor/ConveyorSwitchComponent.cs @@ -129,16 +129,21 @@ namespace Content.Server.GameObjects.Components.Conveyor serializer.DataReadWriteFunction( "conveyors", - new List(), - conveyors => + new List(), + ids => { - if (conveyors == null) + if (ids == null) { return; } - foreach (var conveyor in conveyors) + foreach (var id in ids) { + if (!Owner.EntityManager.TryGetEntity(id, out var conveyor)) + { + continue; + } + if (!conveyor.TryGetComponent(out ConveyorComponent component)) { continue; @@ -147,20 +152,25 @@ namespace Content.Server.GameObjects.Components.Conveyor Connect(component); } }, - () => _group?.Conveyors.Select(conveyor => conveyor.Owner)); + () => _group?.Conveyors.Select(conveyor => conveyor.Owner.Uid).ToList()); serializer.DataReadWriteFunction( "switches", - new List(), - switches => + new List(), + ids => { - if (switches == null) + if (ids == null) { return; } - foreach (var @switch in switches) + foreach (var id in ids) { + if (!Owner.EntityManager.TryGetEntity(id, out var @switch)) + { + continue; + } + if (!@switch.TryGetComponent(out ConveyorSwitchComponent component)) { continue; @@ -169,7 +179,7 @@ namespace Content.Server.GameObjects.Components.Conveyor component.SyncWith(this); } }, - () => _group?.Switches.Select(@switch => @switch.Owner)); + () => _group?.Switches.Select(@switch => @switch.Owner.Uid).ToList()); } public override void OnRemove()