Fix mechanism events not being called properly, add test (#2279)
* Add mechanism events when added/removed to/from body/parts * Change old usages * Add TODO * Remove BodyExtensions and IHasBody * Remove unnecessary extensions and fix wrong event call in mechanism behavior component * Complete test and fix event calls
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#nullable enable
|
||||
using System.Collections.Generic;
|
||||
using Content.Shared.GameObjects.Components.Body.Behavior;
|
||||
using Content.Shared.GameObjects.Components.Body.Part;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
@@ -39,12 +40,26 @@ namespace Content.Shared.GameObjects.Components.Body.Mechanism
|
||||
|
||||
if (old != null)
|
||||
{
|
||||
OnRemovedFromPart(old);
|
||||
if (old.Body == null)
|
||||
{
|
||||
RemovedFromPart(old);
|
||||
}
|
||||
else
|
||||
{
|
||||
RemovedFromPartInBody(old.Body, old);
|
||||
}
|
||||
}
|
||||
|
||||
if (value != null)
|
||||
{
|
||||
OnAddedToPart();
|
||||
if (value.Body == null)
|
||||
{
|
||||
AddedToPart();
|
||||
}
|
||||
else
|
||||
{
|
||||
AddedToPartInBody();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -94,7 +109,7 @@ namespace Content.Shared.GameObjects.Components.Body.Mechanism
|
||||
|
||||
OnAddedToBody();
|
||||
|
||||
foreach (var behavior in Owner.GetMechanismBehaviors())
|
||||
foreach (var behavior in Owner.GetAllComponents<IMechanismBehavior>())
|
||||
{
|
||||
behavior.AddedToBody();
|
||||
}
|
||||
@@ -104,7 +119,7 @@ namespace Content.Shared.GameObjects.Components.Body.Mechanism
|
||||
{
|
||||
OnRemovedFromBody(old);
|
||||
|
||||
foreach (var behavior in Owner.GetMechanismBehaviors())
|
||||
foreach (var behavior in Owner.GetAllComponents<IMechanismBehavior>())
|
||||
{
|
||||
behavior.RemovedFromBody(old);
|
||||
}
|
||||
@@ -117,23 +132,12 @@ namespace Content.Shared.GameObjects.Components.Body.Mechanism
|
||||
Owner.Transform.AttachParent(Part!.Owner);
|
||||
OnAddedToPart();
|
||||
|
||||
foreach (var behavior in Owner.GetMechanismBehaviors())
|
||||
foreach (var behavior in Owner.GetAllComponents<IMechanismBehavior>())
|
||||
{
|
||||
behavior.AddedToPart();
|
||||
}
|
||||
}
|
||||
|
||||
public void RemovedFromPart(IBodyPart old)
|
||||
{
|
||||
Owner.Transform.AttachToGridOrMap();
|
||||
OnRemovedFromPart(old);
|
||||
|
||||
foreach (var behavior in Owner.GetMechanismBehaviors())
|
||||
{
|
||||
behavior.RemovedFromPart(old);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddedToPartInBody()
|
||||
{
|
||||
DebugTools.AssertNotNull(Body);
|
||||
@@ -142,18 +146,29 @@ namespace Content.Shared.GameObjects.Components.Body.Mechanism
|
||||
Owner.Transform.AttachParent(Part!.Owner);
|
||||
OnAddedToPartInBody();
|
||||
|
||||
foreach (var behavior in Owner.GetMechanismBehaviors())
|
||||
foreach (var behavior in Owner.GetAllComponents<IMechanismBehavior>())
|
||||
{
|
||||
behavior.AddedToPartInBody();
|
||||
}
|
||||
}
|
||||
|
||||
public void RemovedFromPart(IBodyPart old)
|
||||
{
|
||||
Owner.Transform.AttachToGridOrMap();
|
||||
OnRemovedFromPart(old);
|
||||
|
||||
foreach (var behavior in Owner.GetAllComponents<IMechanismBehavior>())
|
||||
{
|
||||
behavior.RemovedFromPart(old);
|
||||
}
|
||||
}
|
||||
|
||||
public void RemovedFromPartInBody(IBody? oldBody, IBodyPart? oldPart)
|
||||
{
|
||||
Owner.Transform.AttachToGridOrMap();
|
||||
OnRemovedFromPartInBody();
|
||||
|
||||
foreach (var behavior in Owner.GetMechanismBehaviors())
|
||||
foreach (var behavior in Owner.GetAllComponents<IMechanismBehavior>())
|
||||
{
|
||||
behavior.RemovedFromPartInBody(oldBody, oldPart);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user