Add arguments to part and mechanism event methods (#2293)

This commit is contained in:
DrSmugleaf
2020-10-19 15:23:59 +02:00
committed by GitHub
parent 19d32eb4ce
commit 7ad46ddabf
9 changed files with 175 additions and 146 deletions

View File

@@ -23,7 +23,10 @@ namespace Content.Shared.GameObjects.Components.Body.Behavior
/// For instance, attaching a head with a brain inside to a body.
/// DO NOT CALL THIS DIRECTLY FROM OUTSIDE BODY SYSTEM CODE!
/// </summary>
void AddedToBody();
/// <param name="body">
/// The body that the containing <see cref="IMechanism"/> was added to.
/// </param>
void AddedToBody(IBody body);
/// <summary>
/// Called when the parent <see cref="IMechanism"/> is
@@ -32,7 +35,10 @@ namespace Content.Shared.GameObjects.Components.Body.Behavior
/// For instance, adding a brain to a dismembered head.
/// DO NOT CALL THIS DIRECTLY FROM OUTSIDE BODY SYSTEM CODE!
/// </summary>
void AddedToPart();
/// <param name="part">
/// The part that the containing <see cref="IMechanism"/> was added to.
/// </param>
void AddedToPart(IBodyPart part);
/// <summary>
/// Called when the parent <see cref="IMechanism"/> is added to a
@@ -40,7 +46,13 @@ namespace Content.Shared.GameObjects.Components.Body.Behavior
/// For instance, adding a brain to a head that is attached to a body.
/// DO NOT CALL THIS DIRECTLY FROM OUTSIDE BODY SYSTEM CODE!
/// </summary>
void AddedToPartInBody();
/// <param name="body">
/// The body that the containing <see cref="IMechanism"/> was added to.
/// </param>
/// <param name="part">
/// The part that the containing <see cref="IMechanism"/> was added to.
/// </param>
void AddedToPartInBody(IBody body, IBodyPart part);
/// <summary>
/// Called when the parent <see cref="IBodyPart"/> is removed from a
@@ -48,6 +60,9 @@ namespace Content.Shared.GameObjects.Components.Body.Behavior
/// For instance, removing a head with a brain inside from a body.
/// DO NOT CALL THIS DIRECTLY FROM OUTSIDE BODY SYSTEM CODE!
/// </summary>
/// <param name="old">
/// The body that the containing <see cref="IMechanism"/> was removed from.
/// </param>
void RemovedFromBody(IBody old);
/// <summary>
@@ -57,6 +72,9 @@ namespace Content.Shared.GameObjects.Components.Body.Behavior
/// For instance, removing a brain from a dismembered head.
/// DO NOT CALL THIS DIRECTLY FROM OUTSIDE BODY SYSTEM CODE!
/// </summary>
/// <param name="old">
/// The part that the containing <see cref="IMechanism"/> was removed from.
/// </param>
void RemovedFromPart(IBodyPart old);
/// <summary>
@@ -65,6 +83,12 @@ namespace Content.Shared.GameObjects.Components.Body.Behavior
/// For instance, removing a brain from a head that is attached to a body.
/// DO NOT CALL THIS DIRECTLY FROM OUTSIDE BODY SYSTEM CODE!
/// </summary>
void RemovedFromPartInBody(IBody? oldBody, IBodyPart? oldPart);
/// <param name="oldBody">
/// The body that the containing <see cref="IMechanism"/> was removed from.
/// </param>
/// <param name="oldPart">
/// The part that the containing <see cref="IMechanism"/> was removed from.
/// </param>
void RemovedFromPartInBody(IBody oldBody, IBodyPart oldPart);
}
}

View File

@@ -2,6 +2,7 @@
using Content.Shared.GameObjects.Components.Body.Mechanism;
using Content.Shared.GameObjects.Components.Body.Part;
using Robust.Shared.GameObjects;
using Robust.Shared.Utility;
namespace Content.Shared.GameObjects.Components.Body.Behavior
{
@@ -24,56 +25,78 @@ namespace Content.Shared.GameObjects.Components.Body.Behavior
if (Body == null)
{
AddedToPart();
AddedToPart(Part);
}
else
{
AddedToPartInBody();
AddedToPartInBody(Body, Part);
}
}
public abstract void Update(float frameTime);
public void AddedToBody()
public void AddedToBody(IBody body)
{
OnAddedToBody();
DebugTools.AssertNotNull(Body);
DebugTools.AssertNotNull(body);
OnAddedToBody(body);
}
public void AddedToPart()
public void AddedToPart(IBodyPart part)
{
OnAddedToPart();
DebugTools.AssertNotNull(Part);
DebugTools.AssertNotNull(part);
OnAddedToPart(part);
}
public void AddedToPartInBody(IBody body, IBodyPart part)
{
DebugTools.AssertNotNull(Body);
DebugTools.AssertNotNull(body);
DebugTools.AssertNotNull(Part);
DebugTools.AssertNotNull(part);
OnAddedToPartInBody(body, part);
}
public void RemovedFromBody(IBody old)
{
DebugTools.AssertNull(Body);
DebugTools.AssertNotNull(old);
OnRemovedFromBody(old);
}
public void RemovedFromPart(IBodyPart old)
{
DebugTools.AssertNull(Part);
DebugTools.AssertNotNull(old);
OnRemovedFromPart(old);
}
public void AddedToPartInBody()
public void RemovedFromPartInBody(IBody oldBody, IBodyPart oldPart)
{
OnAddedToPartInBody();
}
DebugTools.AssertNull(Body);
DebugTools.AssertNull(Part);
DebugTools.AssertNotNull(oldBody);
DebugTools.AssertNotNull(oldPart);
public void RemovedFromPartInBody(IBody? oldBody, IBodyPart? oldPart)
{
OnRemovedFromPartInBody(oldBody, oldPart);
}
protected virtual void OnAddedToBody() { }
protected virtual void OnAddedToBody(IBody body) { }
protected virtual void OnAddedToPart() { }
protected virtual void OnAddedToPart(IBodyPart part) { }
protected virtual void OnAddedToPartInBody(IBody body, IBodyPart part) { }
protected virtual void OnRemovedFromBody(IBody old) { }
protected virtual void OnRemovedFromPart(IBodyPart old) { }
protected virtual void OnAddedToPartInBody() { }
protected virtual void OnRemovedFromPartInBody(IBody? oldBody, IBodyPart? oldPart) { }
protected virtual void OnRemovedFromPartInBody(IBody oldBody, IBodyPart oldPart) { }
}
}