ECS and cleanup body system, merge body templates and presets into body prototypes (#11991)
Co-authored-by: Jezithyr <Jezithyr@gmail.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
using System.Threading.Tasks;
|
||||
using Content.Server.Body.Components;
|
||||
using Content.Server.Body.Systems;
|
||||
using Content.Shared.Body.Components;
|
||||
using Content.Shared.Body.Part;
|
||||
using Content.Shared.Rotation;
|
||||
@@ -12,7 +12,7 @@ using Robust.Shared.Maths;
|
||||
namespace Content.IntegrationTests.Tests.Body
|
||||
{
|
||||
[TestFixture]
|
||||
[TestOf(typeof(SharedBodyComponent))]
|
||||
[TestOf(typeof(BodyPartComponent))]
|
||||
[TestOf(typeof(BodyComponent))]
|
||||
public sealed class LegTest
|
||||
{
|
||||
@@ -23,16 +23,15 @@ namespace Content.IntegrationTests.Tests.Body
|
||||
components:
|
||||
- type: Appearance
|
||||
- type: Body
|
||||
template: HumanoidTemplate
|
||||
preset: HumanPreset
|
||||
centerSlot: torso
|
||||
prototype: Human
|
||||
- type: StandingState
|
||||
";
|
||||
|
||||
[Test]
|
||||
public async Task RemoveLegsFallTest()
|
||||
{
|
||||
await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings{NoClient = true, ExtraPrototypes = Prototypes});
|
||||
await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings
|
||||
{NoClient = true, ExtraPrototypes = Prototypes});
|
||||
var server = pairTracker.Pair.Server;
|
||||
|
||||
AppearanceComponent appearance = null;
|
||||
@@ -44,18 +43,20 @@ namespace Content.IntegrationTests.Tests.Body
|
||||
var mapId = mapManager.CreateMap();
|
||||
|
||||
var entityManager = IoCManager.Resolve<IEntityManager>();
|
||||
var human = entityManager.SpawnEntity("HumanBodyAndAppearanceDummy", new MapCoordinates(Vector2.Zero, mapId));
|
||||
var human = entityManager.SpawnEntity("HumanBodyAndAppearanceDummy",
|
||||
new MapCoordinates(Vector2.Zero, mapId));
|
||||
|
||||
Assert.That(entityManager.TryGetComponent(human, out SharedBodyComponent body));
|
||||
Assert.That(entityManager.TryGetComponent(human, out BodyComponent body));
|
||||
Assert.That(entityManager.TryGetComponent(human, out appearance));
|
||||
|
||||
Assert.That(!appearance.TryGetData(RotationVisuals.RotationState, out RotationState _));
|
||||
|
||||
var legs = body.GetPartsOfType(BodyPartType.Leg);
|
||||
var bodySystem = entityManager.System<BodySystem>();
|
||||
var legs = bodySystem.GetBodyChildrenOfType(body.Owner, BodyPartType.Leg, body);
|
||||
|
||||
foreach (var leg in legs)
|
||||
{
|
||||
body.RemovePart(leg);
|
||||
bodySystem.DropPart(leg.Id, leg.Component);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -22,9 +22,7 @@ namespace Content.IntegrationTests.Tests.Body
|
||||
components:
|
||||
- type: SolutionContainerManager
|
||||
- type: Body
|
||||
template: HumanoidTemplate
|
||||
preset: HumanPreset
|
||||
centerSlot: torso
|
||||
prototype: Human
|
||||
- type: MobState
|
||||
thresholds:
|
||||
0: Alive
|
||||
@@ -49,7 +47,8 @@ namespace Content.IntegrationTests.Tests.Body
|
||||
public async Task AirConsistencyTest()
|
||||
{
|
||||
// --- Setup
|
||||
await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings{NoClient = true, ExtraPrototypes = Prototypes});
|
||||
await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings
|
||||
{NoClient = true, ExtraPrototypes = Prototypes});
|
||||
var server = pairTracker.Pair.Server;
|
||||
|
||||
await server.WaitIdleAsync();
|
||||
@@ -62,7 +61,7 @@ namespace Content.IntegrationTests.Tests.Body
|
||||
|
||||
MapId mapId;
|
||||
EntityUid? grid = null;
|
||||
SharedBodyComponent body = default;
|
||||
BodyComponent body = default;
|
||||
EntityUid human = default;
|
||||
GridAtmosphereComponent relevantAtmos = default;
|
||||
float startingMoles = 0.0f;
|
||||
@@ -127,7 +126,8 @@ namespace Content.IntegrationTests.Tests.Body
|
||||
[Test]
|
||||
public async Task NoSuffocationTest()
|
||||
{
|
||||
await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings{NoClient = true, ExtraPrototypes = Prototypes});
|
||||
await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings
|
||||
{NoClient = true, ExtraPrototypes = Prototypes});
|
||||
var server = pairTracker.Pair.Server;
|
||||
|
||||
var mapLoader = server.ResolveDependency<IMapLoader>();
|
||||
@@ -155,7 +155,7 @@ namespace Content.IntegrationTests.Tests.Body
|
||||
var coordinates = new EntityCoordinates(grid.Value, center);
|
||||
human = entityManager.SpawnEntity("HumanBodyDummy", coordinates);
|
||||
|
||||
Assert.True(entityManager.HasComponent<SharedBodyComponent>(human));
|
||||
Assert.True(entityManager.HasComponent<BodyComponent>(human));
|
||||
Assert.True(entityManager.TryGetComponent(human, out respirator));
|
||||
Assert.False(respirator.SuffocationCycles > respirator.SuffocationCycleThreshold);
|
||||
});
|
||||
@@ -167,7 +167,8 @@ namespace Content.IntegrationTests.Tests.Body
|
||||
await server.WaitRunTicks(increment);
|
||||
await server.WaitAssertion(() =>
|
||||
{
|
||||
Assert.False(respirator.SuffocationCycles > respirator.SuffocationCycleThreshold, $"Entity {entityManager.GetComponent<MetaDataComponent>(human).EntityName} is suffocating on tick {tick}");
|
||||
Assert.False(respirator.SuffocationCycles > respirator.SuffocationCycleThreshold,
|
||||
$"Entity {entityManager.GetComponent<MetaDataComponent>(human).EntityName} is suffocating on tick {tick}");
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
148
Content.IntegrationTests/Tests/Body/SaveLoadReparentTest.cs
Normal file
148
Content.IntegrationTests/Tests/Body/SaveLoadReparentTest.cs
Normal file
@@ -0,0 +1,148 @@
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Shared.Body.Components;
|
||||
using Content.Shared.Body.Systems;
|
||||
using NUnit.Framework;
|
||||
using Robust.Server.Maps;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Map;
|
||||
|
||||
namespace Content.IntegrationTests.Tests.Body;
|
||||
|
||||
[TestFixture]
|
||||
public sealed class SaveLoadReparentTest
|
||||
{
|
||||
private const string Prototypes = @"
|
||||
- type: entity
|
||||
name: HumanBodyDummy
|
||||
id: HumanBodyDummy
|
||||
components:
|
||||
- type: Body
|
||||
prototype: Human
|
||||
";
|
||||
|
||||
[Test]
|
||||
public async Task Test()
|
||||
{
|
||||
await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings
|
||||
{
|
||||
NoClient = true,
|
||||
ExtraPrototypes = Prototypes
|
||||
});
|
||||
var server = pairTracker.Pair.Server;
|
||||
|
||||
var entities = server.ResolveDependency<IEntityManager>();
|
||||
var maps = server.ResolveDependency<IMapManager>();
|
||||
var mapLoader = server.ResolveDependency<IMapLoader>();
|
||||
var bodySystem = entities.System<SharedBodySystem>();
|
||||
|
||||
await server.WaitAssertion(() =>
|
||||
{
|
||||
var mapId = maps.CreateMap();
|
||||
maps.CreateGrid(mapId);
|
||||
var human = entities.SpawnEntity("HumanBodyDummy", new MapCoordinates(0, 0, mapId));
|
||||
|
||||
Assert.That(entities.HasComponent<BodyComponent>(human), Is.True);
|
||||
|
||||
var parts = bodySystem.GetBodyChildren(human).ToArray();
|
||||
var organs = bodySystem.GetBodyOrgans(human).ToArray();
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(parts, Is.Not.Empty);
|
||||
Assert.That(organs, Is.Not.Empty);
|
||||
});
|
||||
|
||||
foreach (var (id, component) in parts)
|
||||
{
|
||||
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));
|
||||
});
|
||||
|
||||
foreach (var (slotId, slot) in component.Children)
|
||||
{
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(slot.Id, Is.EqualTo(slotId));
|
||||
Assert.That(slot.Parent, Is.Not.EqualTo(default(EntityUid)));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var (id, component) in organs)
|
||||
{
|
||||
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(entities
|
||||
.EntityQuery<BodyComponent>()
|
||||
.Where(e => entities.GetComponent<MetaDataComponent>(e.Owner).EntityPrototype!.Name ==
|
||||
"HumanBodyDummy"), Is.Not.Empty);
|
||||
|
||||
const string mapPath = $"/{nameof(SaveLoadReparentTest)}{nameof(Test)}map.yml";
|
||||
|
||||
mapLoader.SaveMap(mapId, mapPath);
|
||||
maps.DeleteMap(mapId);
|
||||
|
||||
mapId = maps.CreateMap();
|
||||
mapLoader.LoadMap(mapId, mapPath);
|
||||
|
||||
var query = entities
|
||||
.EntityQuery<BodyComponent>()
|
||||
.Where(e => entities.GetComponent<MetaDataComponent>(e.Owner).EntityPrototype!.Name == "HumanBodyDummy")
|
||||
.ToArray();
|
||||
|
||||
Assert.That(query, Is.Not.Empty);
|
||||
foreach (var body in query)
|
||||
{
|
||||
human = body.Owner;
|
||||
parts = bodySystem.GetBodyChildren(human).ToArray();
|
||||
organs = bodySystem.GetBodyOrgans(human).ToArray();
|
||||
|
||||
Assert.That(parts, Is.Not.Empty);
|
||||
Assert.That(organs, Is.Not.Empty);
|
||||
|
||||
foreach (var (id, component) in parts)
|
||||
{
|
||||
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));
|
||||
});
|
||||
|
||||
foreach (var (slotId, slot) in component.Children)
|
||||
{
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(slot.Id, Is.EqualTo(slotId));
|
||||
Assert.That(slot.Parent, Is.Not.EqualTo(default(EntityUid)));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var (id, component) in organs)
|
||||
{
|
||||
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));
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user