* Fix conveyor and conveyor switch serialization

* SS14 in reactive when

* Fix new test fail with units being able to accept items when unpowered
This commit is contained in:
DrSmugleaf
2020-08-01 01:20:41 +02:00
committed by GitHub
parent 86f74b35d1
commit 9063379af9
3 changed files with 50 additions and 33 deletions

View File

@@ -48,13 +48,13 @@ namespace Content.IntegrationTests.Tests.Disposal
UnitContains(unit, result, entities); 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.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.That(result, Is.EqualTo(unit.TryFlush()));
Assert.AreEqual(unit.ContainedEntities.Count == 0, entry != null || entities.Length == 0); Assert.That(result || entities.Length == 0, Is.EqualTo(unit.ContainedEntities.Count == 0));
} }
[Test] [Test]
@@ -62,10 +62,10 @@ namespace Content.IntegrationTests.Tests.Disposal
{ {
var server = StartServerDummyTicker(); var server = StartServerDummyTicker();
IEntity human = null!; IEntity human;
IEntity wrench = null!; IEntity wrench;
DisposalUnitComponent unit = null!; DisposalUnitComponent unit;
DisposalEntryComponent entry = null!; DisposalEntryComponent entry;
server.Assert(() => server.Assert(() =>
{ {
@@ -88,8 +88,8 @@ namespace Content.IntegrationTests.Tests.Disposal
// Can't insert, unanchored and unpowered // Can't insert, unanchored and unpowered
var disposalUnitAnchorable = disposalUnit.GetComponent<AnchorableComponent>(); var disposalUnitAnchorable = disposalUnit.GetComponent<AnchorableComponent>();
disposalUnitAnchorable.TryUnAnchor(human, null, true); disposalUnitAnchorable.TryUnAnchor(human, null, true);
UnitInsertContains(unit, false, human, wrench, disposalUnit, disposalTrunk);
Assert.False(unit.Anchored); Assert.False(unit.Anchored);
UnitInsertContains(unit, false, human, wrench, disposalUnit, disposalTrunk);
// Anchor the disposal unit // Anchor the disposal unit
disposalUnitAnchorable.TryAnchor(human, null, true); disposalUnitAnchorable.TryAnchor(human, null, true);
@@ -97,15 +97,9 @@ namespace Content.IntegrationTests.Tests.Disposal
Assert.True(anchorableUnit.TryAnchor(human, wrench)); Assert.True(anchorableUnit.TryAnchor(human, wrench));
Assert.True(unit.Anchored); Assert.True(unit.Anchored);
// Can't insert, unpowered // No power
UnitInsertContains(unit, false, human, wrench, disposalUnit, disposalTrunk);
Assert.False(unit.Powered); 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 // Can't insert the trunk or the unit into itself
UnitInsertContains(unit, false, disposalUnit, disposalTrunk); UnitInsertContains(unit, false, disposalUnit, disposalTrunk);
@@ -116,13 +110,21 @@ namespace Content.IntegrationTests.Tests.Disposal
disposalTrunk.Transform.WorldPosition += (1, 0); disposalTrunk.Transform.WorldPosition += (1, 0);
// Fail to flush with a mob and an item // 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 // Move the disposal trunk back
disposalTrunk.Transform.WorldPosition -= (1, 0); 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 with a mob and an item
Flush(unit, true, entry, null, human, wrench); Flush(unit, true, entry, human, wrench);
// Re-pressurizing // Re-pressurizing
Flush(unit, false, entry); Flush(unit, false, entry);

View File

@@ -208,16 +208,21 @@ namespace Content.Server.GameObjects.Components.Conveyor
serializer.DataReadWriteFunction( serializer.DataReadWriteFunction(
"switches", "switches",
new List<IEntity>(), new List<EntityUid>(),
switches => ids =>
{ {
if (switches == null) if (ids == null)
{ {
return; 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)) if (!@switch.TryGetComponent(out ConveyorSwitchComponent component))
{ {
continue; continue;
@@ -226,7 +231,7 @@ namespace Content.Server.GameObjects.Components.Conveyor
component.Connect(this); 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 _angle, "angle", 0);
serializer.DataField(ref _speed, "speed", 2); serializer.DataField(ref _speed, "speed", 2);

View File

@@ -129,16 +129,21 @@ namespace Content.Server.GameObjects.Components.Conveyor
serializer.DataReadWriteFunction( serializer.DataReadWriteFunction(
"conveyors", "conveyors",
new List<IEntity>(), new List<EntityUid>(),
conveyors => ids =>
{ {
if (conveyors == null) if (ids == null)
{ {
return; 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)) if (!conveyor.TryGetComponent(out ConveyorComponent component))
{ {
continue; continue;
@@ -147,20 +152,25 @@ namespace Content.Server.GameObjects.Components.Conveyor
Connect(component); Connect(component);
} }
}, },
() => _group?.Conveyors.Select(conveyor => conveyor.Owner)); () => _group?.Conveyors.Select(conveyor => conveyor.Owner.Uid).ToList());
serializer.DataReadWriteFunction( serializer.DataReadWriteFunction(
"switches", "switches",
new List<IEntity>(), new List<EntityUid>(),
switches => ids =>
{ {
if (switches == null) if (ids == null)
{ {
return; 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)) if (!@switch.TryGetComponent(out ConveyorSwitchComponent component))
{ {
continue; continue;
@@ -169,7 +179,7 @@ namespace Content.Server.GameObjects.Components.Conveyor
component.SyncWith(this); component.SyncWith(this);
} }
}, },
() => _group?.Switches.Select(@switch => @switch.Owner)); () => _group?.Switches.Select(@switch => @switch.Owner.Uid).ToList());
} }
public override void OnRemove() public override void OnRemove()