Shuffle body container subs slightly (#21084)

This commit is contained in:
metalgearsloth
2023-12-11 21:35:24 +11:00
committed by GitHub
parent c2df96a879
commit eb49ad11ba
4 changed files with 118 additions and 131 deletions

View File

@@ -25,63 +25,11 @@ public partial class SharedBodySystem
private void InitializeBody()
{
// Body here to handle root body parts.
SubscribeLocalEvent<BodyComponent, EntInsertedIntoContainerMessage>(OnBodyInserted);
SubscribeLocalEvent<BodyComponent, EntRemovedFromContainerMessage>(OnBodyRemoved);
SubscribeLocalEvent<BodyComponent, ComponentInit>(OnBodyInit);
SubscribeLocalEvent<BodyComponent, MapInitEvent>(OnBodyMapInit);
SubscribeLocalEvent<BodyComponent, CanDragEvent>(OnBodyCanDrag);
}
private void OnBodyInserted(EntityUid uid, BodyComponent component, EntInsertedIntoContainerMessage args)
{
// Root body part?
var slotId = args.Container.ID;
if (slotId != BodyRootContainerId)
return;
var entity = args.Entity;
if (TryComp(entity, out BodyPartComponent? childPart))
{
AddPart(uid, entity, slotId, childPart);
RecursiveBodyUpdate(entity, uid, childPart);
}
if (TryComp(entity, out OrganComponent? organ))
{
AddOrgan(entity, uid, uid, organ);
}
}
private void OnBodyRemoved(EntityUid uid, BodyComponent component, EntRemovedFromContainerMessage args)
{
// TODO: lifestage shenanigans
if (TerminatingOrDeleted(uid))
return;
// Root body part?
var slotId = args.Container.ID;
if (slotId != BodyRootContainerId)
return;
var entity = args.Entity;
if (TryComp(entity, out BodyPartComponent? childPart))
{
RemovePart(uid, entity, slotId, childPart);
RecursiveBodyUpdate(entity, null, childPart);
}
if (TryComp(entity, out OrganComponent? organ))
{
RemoveOrgan(entity, uid, organ);
}
}
private void OnBodyInit(EntityUid bodyId, BodyComponent body, ComponentInit args)
{
// Setup the initial container.
@@ -229,6 +177,8 @@ public partial class SharedBodySystem
yield break;
}
yield return (body.RootContainer.ContainedEntity.Value, rootPart);
foreach (var child in GetBodyPartChildren(body.RootContainer.ContainedEntity.Value, rootPart))
{
yield return child;