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) { }
}
}

View File

@@ -62,7 +62,10 @@ namespace Content.Shared.GameObjects.Components.Body.Mechanism
/// 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 this <see cref="IMechanism"/> was added to.
/// </param>
void AddedToBody(IBody body);
/// <summary>
/// Called when the parent <see cref="IMechanism"/> is
@@ -71,7 +74,10 @@ namespace Content.Shared.GameObjects.Components.Body.Mechanism
/// 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 this <see cref="IMechanism"/> was added to.
/// </param>
void AddedToPart(IBodyPart part);
/// <summary>
/// Called when the parent <see cref="IMechanism"/> is added to a
@@ -79,7 +85,13 @@ namespace Content.Shared.GameObjects.Components.Body.Mechanism
/// 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 this <see cref="IMechanism"/> was added to.
/// </param>
/// <param name="part">
/// The part that this <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
@@ -87,6 +99,9 @@ namespace Content.Shared.GameObjects.Components.Body.Mechanism
/// 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 this <see cref="IMechanism"/> was removed from.
/// </param>
void RemovedFromBody(IBody old);
/// <summary>
@@ -96,6 +111,9 @@ namespace Content.Shared.GameObjects.Components.Body.Mechanism
/// 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 this <see cref="IMechanism"/> was removed from.
/// </param>
void RemovedFromPart(IBodyPart old);
/// <summary>
@@ -104,6 +122,12 @@ namespace Content.Shared.GameObjects.Components.Body.Mechanism
/// 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 this <see cref="IMechanism"/> was removed from.
/// </param>
/// <param name="oldPart">
/// The part that this <see cref="IMechanism"/> was removed from.
/// </param>
void RemovedFromPartInBody(IBody oldBody, IBodyPart oldPart);
}
}

View File

@@ -15,13 +15,9 @@ namespace Content.Shared.GameObjects.Components.Body.Mechanism
public override string Name => "Mechanism";
private IBodyPart? _part;
protected readonly Dictionary<int, object> OptionsCache = new Dictionary<int, object>();
protected IBody? BodyCache;
protected int IdHash;
protected IEntity? PerformerCache;
public IBody? Body => Part?.Body;
@@ -55,11 +51,11 @@ namespace Content.Shared.GameObjects.Components.Body.Mechanism
{
if (value.Body == null)
{
AddedToPart();
AddedToPart(value);
}
else
{
AddedToPartInBody();
AddedToPartInBody(value.Body, value);
}
}
}
@@ -104,20 +100,54 @@ namespace Content.Shared.GameObjects.Components.Body.Mechanism
serializer.DataField(this, m => m.Compatibility, "compatibility", BodyPartCompatibility.Universal);
}
public void AddedToBody()
public void AddedToBody(IBody body)
{
DebugTools.AssertNotNull(Body);
DebugTools.AssertNotNull(body);
OnAddedToBody();
OnAddedToBody(body);
foreach (var behavior in Owner.GetAllComponents<IMechanismBehavior>())
{
behavior.AddedToBody();
behavior.AddedToBody(body);
}
}
public void AddedToPart(IBodyPart part)
{
DebugTools.AssertNotNull(Part);
DebugTools.AssertNotNull(part);
Owner.Transform.AttachParent(part.Owner);
OnAddedToPart(part);
foreach (var behavior in Owner.GetAllComponents<IMechanismBehavior>().ToArray())
{
behavior.AddedToPart(part);
}
}
public void AddedToPartInBody(IBody body, IBodyPart part)
{
DebugTools.AssertNotNull(Body);
DebugTools.AssertNotNull(body);
DebugTools.AssertNotNull(Part);
DebugTools.AssertNotNull(part);
Owner.Transform.AttachParent(part.Owner);
OnAddedToPartInBody(body, part);
foreach (var behavior in Owner.GetAllComponents<IMechanismBehavior>())
{
behavior.AddedToPartInBody(body, part);
}
}
public void RemovedFromBody(IBody old)
{
DebugTools.AssertNull(Body);
DebugTools.AssertNotNull(old);
OnRemovedFromBody(old);
foreach (var behavior in Owner.GetAllComponents<IMechanismBehavior>())
@@ -126,35 +156,11 @@ namespace Content.Shared.GameObjects.Components.Body.Mechanism
}
}
public void AddedToPart()
{
DebugTools.AssertNotNull(Part);
Owner.Transform.AttachParent(Part!.Owner);
OnAddedToPart();
foreach (var behavior in Owner.GetAllComponents<IMechanismBehavior>().ToArray())
{
behavior.AddedToPart();
}
}
public void AddedToPartInBody()
{
DebugTools.AssertNotNull(Body);
DebugTools.AssertNotNull(Part);
Owner.Transform.AttachParent(Part!.Owner);
OnAddedToPartInBody();
foreach (var behavior in Owner.GetAllComponents<IMechanismBehavior>())
{
behavior.AddedToPartInBody();
}
}
public void RemovedFromPart(IBodyPart old)
{
DebugTools.AssertNull(Part);
DebugTools.AssertNotNull(old);
Owner.Transform.AttachToGridOrMap();
OnRemovedFromPart(old);
@@ -164,10 +170,15 @@ namespace Content.Shared.GameObjects.Components.Body.Mechanism
}
}
public void RemovedFromPartInBody(IBody? oldBody, IBodyPart? oldPart)
public void RemovedFromPartInBody(IBody oldBody, IBodyPart oldPart)
{
DebugTools.AssertNull(Body);
DebugTools.AssertNotNull(oldBody);
DebugTools.AssertNull(Part);
DebugTools.AssertNotNull(oldPart);
Owner.Transform.AttachToGridOrMap();
OnRemovedFromPartInBody();
OnRemovedFromPartInBody(oldBody, oldPart);
foreach (var behavior in Owner.GetAllComponents<IMechanismBehavior>())
{
@@ -175,16 +186,16 @@ namespace Content.Shared.GameObjects.Components.Body.Mechanism
}
}
protected virtual void OnAddedToBody() { }
protected virtual void OnAddedToBody(IBody body) { }
protected virtual void OnAddedToPart(IBodyPart part) { }
protected virtual void OnAddedToPartInBody(IBody body, IBodyPart part) { }
protected virtual void OnRemovedFromBody(IBody old) { }
protected virtual void OnAddedToPart() { }
protected virtual void OnRemovedFromPart(IBodyPart old) { }
protected virtual void OnAddedToPartInBody() { }
protected virtual void OnRemovedFromPartInBody() { }
protected virtual void OnRemovedFromPartInBody(IBody oldBody, IBodyPart oldPart) { }
}
}

View File

@@ -50,7 +50,7 @@ namespace Content.Shared.GameObjects.Components.Body.Part
if (value != null)
{
AddedToBody();
AddedToBody(value);
}
}
}
@@ -284,14 +284,14 @@ namespace Content.Shared.GameObjects.Components.Body.Part
return true;
}
private void AddedToBody()
private void AddedToBody(IBody body)
{
Owner.Transform.AttachParent(Body!.Owner);
OnAddedToBody();
OnAddedToBody(body);
foreach (var mechanism in _mechanisms)
{
mechanism.AddedToBody();
mechanism.AddedToBody(body);
}
}
@@ -310,7 +310,7 @@ namespace Content.Shared.GameObjects.Components.Body.Part
}
}
protected virtual void OnAddedToBody() { }
protected virtual void OnAddedToBody(IBody body) { }
protected virtual void OnRemovedFromBody(IBody old) { }
}