Files
tbd-station-14/Content.Shared/GameObjects/Components/Body/Behavior/MechanismBehaviorComponent.cs
DrSmugleaf 101fa9e466 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
2020-10-17 12:26:39 +02:00

80 lines
1.9 KiB
C#

#nullable enable
using Content.Shared.GameObjects.Components.Body.Mechanism;
using Content.Shared.GameObjects.Components.Body.Part;
using Robust.Shared.GameObjects;
namespace Content.Shared.GameObjects.Components.Body.Behavior
{
public abstract class MechanismBehaviorComponent : Component, IMechanismBehavior
{
public IBody? Body => Part?.Body;
public IBodyPart? Part => Mechanism?.Part;
public IMechanism? Mechanism => Owner.GetComponentOrNull<IMechanism>();
protected override void Startup()
{
base.Startup();
if (Part == null)
{
return;
}
if (Body == null)
{
AddedToPart();
}
else
{
AddedToPartInBody();
}
}
public abstract void Update(float frameTime);
public void AddedToBody()
{
OnAddedToBody();
}
public void AddedToPart()
{
OnAddedToPart();
}
public void RemovedFromBody(IBody old)
{
OnRemovedFromBody(old);
}
public void RemovedFromPart(IBodyPart old)
{
OnRemovedFromPart(old);
}
public void AddedToPartInBody()
{
OnAddedToPartInBody();
}
public void RemovedFromPartInBody(IBody? oldBody, IBodyPart? oldPart)
{
OnRemovedFromPartInBody(oldBody, oldPart);
}
protected virtual void OnAddedToBody() { }
protected virtual void OnAddedToPart() { }
protected virtual void OnRemovedFromBody(IBody old) { }
protected virtual void OnRemovedFromPart(IBodyPart old) { }
protected virtual void OnAddedToPartInBody() { }
protected virtual void OnRemovedFromPartInBody(IBody? oldBody, IBodyPart? oldPart) { }
}
}