Refactor body component to use slots instead of an army of dictionaries (#3749)

* Refactor body component to use slots instead of an army of dictionaries

* Update vox

* Replace static method call with extension

* Add setpart method, replace dispose with shutdown

* Fix tests, fix not listening to slot events when setting a part
This commit is contained in:
DrSmugleaf
2021-04-05 14:54:51 +02:00
committed by GitHub
parent 5387f87608
commit 677706b117
30 changed files with 602 additions and 466 deletions

View File

@@ -1,6 +1,5 @@
#nullable enable
using Content.Server.Administration;
using Content.Server.GameObjects.Components.Body.Part;
using Content.Shared.Administration;
using Content.Shared.GameObjects.Components.Body;
using Content.Shared.GameObjects.Components.Body.Part;
@@ -8,6 +7,7 @@ using Robust.Server.Player;
using Robust.Shared.Console;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using static Content.Server.GameObjects.Components.Body.Part.BodyPartComponent;
namespace Content.Server.Commands
{
@@ -100,7 +100,7 @@ namespace Content.Server.Commands
return;
}
body.TryAddPart($"{nameof(BodyPartComponent.AttachBodyPartVerb)}-{partEntity.Uid}", part, true);
body.SetPart($"{nameof(AttachBodyPartVerb)}-{partEntity.Uid}", part);
}
}
}

View File

@@ -138,11 +138,9 @@ namespace Content.Server.Commands.Body
}
var slot = part.GetHashCode().ToString();
var response = body.TryAddPart(slot, part, true)
? $"Added hand to entity {entity.Name}"
: $"Error occurred trying to add a hand to entity {entity.Name}";
body.SetPart(slot, part);
shell.WriteLine(response);
shell.WriteLine($"Added hand to entity {entity.Name}");
}
}
}

View File

@@ -48,7 +48,7 @@ namespace Content.Server.Commands.Body
var mechanismName = string.Join(" ", args).ToLowerInvariant();
foreach (var part in body.Parts.Values)
foreach (var (part, _) in body.Parts)
foreach (var mechanism in part.Mechanisms)
{
if (mechanism.Name.ToLowerInvariant() == mechanismName)

View File

@@ -42,7 +42,8 @@ namespace Content.Server.Commands.Body
return;
}
var (_, hand) = body.Parts.FirstOrDefault(x => x.Value.PartType == BodyPartType.Hand);
var hand = body.GetPartsOfType(BodyPartType.Hand).FirstOrDefault();
if (hand == null)
{
shell.WriteLine("You have no hands.");