Refactoring body system to use containers and general body cleanup (#20202)

Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
This commit is contained in:
Jezithyr
2023-09-21 00:23:02 -07:00
committed by GitHub
parent d888d9ad67
commit 31b2c9f830
38 changed files with 1298 additions and 1098 deletions

View File

@@ -38,6 +38,7 @@ namespace Content.IntegrationTests.Tests.Body
var entityManager = server.ResolveDependency<IEntityManager>();
var mapManager = server.ResolveDependency<IMapManager>();
var appearanceSystem = entityManager.System<SharedAppearanceSystem>();
var xformSystem = entityManager.System<SharedTransformSystem>();
await server.WaitAssertion(() =>
{
@@ -60,7 +61,7 @@ namespace Content.IntegrationTests.Tests.Body
foreach (var leg in legs)
{
bodySystem.DropPart(leg.Id, leg.Component);
xformSystem.DetachParentToNull(leg.Id, entityManager.GetComponent<TransformComponent>(leg.Id));
}
});

View File

@@ -3,6 +3,7 @@ using System.Linq;
using Content.Shared.Body.Components;
using Content.Shared.Body.Systems;
using Robust.Server.GameObjects;
using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
using Robust.Shared.Map;
@@ -31,6 +32,7 @@ public sealed class SaveLoadReparentTest
var maps = server.ResolveDependency<IMapManager>();
var mapLoader = entities.System<MapLoaderSystem>();
var bodySystem = entities.System<SharedBodySystem>();
var containerSystem = entities.System<SharedContainerSystem>();
await server.WaitAssertion(() =>
{
@@ -40,7 +42,7 @@ public sealed class SaveLoadReparentTest
Assert.That(entities.HasComponent<BodyComponent>(human), Is.True);
var parts = bodySystem.GetBodyChildren(human).ToArray();
var parts = bodySystem.GetBodyChildren(human).Skip(1).ToArray();
var organs = bodySystem.GetBodyOrgans(human).ToArray();
Assert.Multiple(() =>
@@ -54,9 +56,17 @@ public sealed class SaveLoadReparentTest
Assert.Multiple(() =>
{
Assert.That(component.Body, Is.EqualTo(human));
Assert.That(component.ParentSlot, Is.Not.Null);
Assert.That(component.ParentSlot.Parent, Is.Not.EqualTo(default(EntityUid)));
Assert.That(component.ParentSlot.Child, Is.EqualTo(id));
Assert.That(component.Body, Is.Not.Null);
var parent = bodySystem.GetParentPartOrNull(id);
Assert.That(parent, Is.Not.EqualTo(default(EntityUid)));
if (!bodySystem.IsPartRoot(component.Body.Value, id, null, component))
{
Assert.That(parent, Is.Not.Null);
}
else
{
Assert.That(parent, Is.Null);
}
});
foreach (var (slotId, slot) in component.Children)
@@ -64,19 +74,22 @@ public sealed class SaveLoadReparentTest
Assert.Multiple(() =>
{
Assert.That(slot.Id, Is.EqualTo(slotId));
Assert.That(slot.Parent, Is.Not.EqualTo(default(EntityUid)));
var container =
containerSystem.GetContainer(id, SharedBodySystem.GetPartSlotContainerId(slotId));
Assert.That(container.ContainedEntities, Is.Not.Empty);
});
}
}
foreach (var (id, component) in organs)
{
var parent = bodySystem.GetParentPartOrNull(id);
Assert.Multiple(() =>
{
Assert.That(component.Body, Is.EqualTo(human));
Assert.That(component.ParentSlot, Is.Not.Null);
Assert.That(component.ParentSlot.Parent, Is.Not.EqualTo(default(EntityUid)));
Assert.That(component.ParentSlot.Child, Is.EqualTo(id));
Assert.That(parent, Is.Not.Null);
Assert.That(parent.Value, Is.Not.EqualTo(default(EntityUid)));
});
}
@@ -115,7 +128,7 @@ public sealed class SaveLoadReparentTest
foreach (var (uid, body) in query)
{
human = uid;
parts = bodySystem.GetBodyChildren(human).ToArray();
parts = bodySystem.GetBodyChildren(human).Skip(1).ToArray();
organs = bodySystem.GetBodyOrgans(human).ToArray();
Assert.Multiple(() =>
@@ -126,12 +139,13 @@ public sealed class SaveLoadReparentTest
foreach (var (id, component) in parts)
{
var parent = bodySystem.GetParentPartOrNull(id);
Assert.Multiple(() =>
{
Assert.That(component.Body, Is.EqualTo(human));
Assert.That(component.ParentSlot, Is.Not.Null);
Assert.That(component.ParentSlot.Parent, Is.Not.EqualTo(default(EntityUid)));
Assert.That(component.ParentSlot.Child, Is.EqualTo(id));
Assert.That(parent, Is.Not.Null);
Assert.That(parent.Value, Is.Not.EqualTo(default(EntityUid)));
});
foreach (var (slotId, slot) in component.Children)
@@ -139,19 +153,22 @@ public sealed class SaveLoadReparentTest
Assert.Multiple(() =>
{
Assert.That(slot.Id, Is.EqualTo(slotId));
Assert.That(slot.Parent, Is.Not.EqualTo(default(EntityUid)));
var container =
containerSystem.GetContainer(id, SharedBodySystem.GetPartSlotContainerId(slotId));
Assert.That(container.ContainedEntities, Is.Not.Empty);
});
}
}
foreach (var (id, component) in organs)
{
var parent = bodySystem.GetParentPartOrNull(id);
Assert.Multiple(() =>
{
Assert.That(component.Body, Is.EqualTo(human));
Assert.That(component.ParentSlot, Is.Not.Null);
Assert.That(component.ParentSlot.Parent, Is.Not.EqualTo(default(EntityUid)));
Assert.That(component.ParentSlot.Child, Is.EqualTo(id));
Assert.That(parent, Is.Not.Null);
Assert.That(parent.Value, Is.Not.EqualTo(default(EntityUid)));
});
}

View File

@@ -258,6 +258,7 @@ namespace Content.IntegrationTests.Tests.Buckle
var entityManager = server.ResolveDependency<IEntityManager>();
var handsSys = entityManager.EntitySysManager.GetEntitySystem<SharedHandsSystem>();
var buckleSystem = entityManager.EntitySysManager.GetEntitySystem<SharedBuckleSystem>();
var xformSystem = entityManager.System<SharedTransformSystem>();
await server.WaitAssertion(() =>
{
@@ -309,7 +310,7 @@ namespace Content.IntegrationTests.Tests.Buckle
// Break our guy's kneecaps
foreach (var leg in legs)
{
bodySystem.DropPart(leg.Id, leg.Component);
xformSystem.DetachParentToNull(leg.Id, entityManager.GetComponent<TransformComponent>(leg.Id));
}
});

View File

@@ -30,7 +30,7 @@ public sealed class RemoveEncryptionKeys : InteractionTest
Assert.That(comp.Channels, Has.Count.EqualTo(0));
});
// Checkl that the key was ejected and not just deleted or something.
// Check that the key was ejected and not just deleted or something.
await AssertEntityLookup(("EncryptionKeyCommon", 1));
// Re-insert a key.

View File

@@ -218,12 +218,13 @@ public abstract partial class InteractionTest
// Ensure that the player only has one hand, so that they do not accidentally pick up deconstruction products
await Server.WaitPost(() =>
{
// I lost an hour of my life trying to track down how the hell interaction tests were breaking
// so greatz to this. Just make your own body prototype!
var bodySystem = SEntMan.System<BodySystem>();
var hands = bodySystem.GetBodyChildrenOfType(SEntMan.GetEntity(Player), BodyPartType.Hand).ToArray();
for (var i = 1; i < hands.Length; i++)
{
bodySystem.DropPart(hands[i].Id);
SEntMan.DeleteEntity(hands[i].Id);
}
});