Remove IBody, IBodyPart, IMechanism and IMechanismBehavior (#4187)
* Remove IBody, IBodyPart, IMechanism and IMechanismBehavior interfaces * Summary cleanup
This commit is contained in:
@@ -11,42 +11,42 @@ namespace Content.Server.Body.Behavior
|
||||
{
|
||||
public class BrainBehavior : MechanismBehavior
|
||||
{
|
||||
protected override void OnAddedToBody(IBody body)
|
||||
protected override void OnAddedToBody(SharedBodyComponent body)
|
||||
{
|
||||
base.OnAddedToBody(body);
|
||||
|
||||
HandleMind(body.Owner, Owner);
|
||||
}
|
||||
|
||||
protected override void OnAddedToPart(IBodyPart part)
|
||||
protected override void OnAddedToPart(SharedBodyPartComponent part)
|
||||
{
|
||||
base.OnAddedToPart(part);
|
||||
|
||||
HandleMind(part.Owner, Owner);
|
||||
}
|
||||
|
||||
protected override void OnAddedToPartInBody(IBody body, IBodyPart part)
|
||||
protected override void OnAddedToPartInBody(SharedBodyComponent body, SharedBodyPartComponent part)
|
||||
{
|
||||
base.OnAddedToPartInBody(body, part);
|
||||
|
||||
HandleMind(body.Owner, Owner);
|
||||
}
|
||||
|
||||
protected override void OnRemovedFromBody(IBody old)
|
||||
protected override void OnRemovedFromBody(SharedBodyComponent old)
|
||||
{
|
||||
base.OnRemovedFromBody(old);
|
||||
|
||||
HandleMind(Part!.Owner, old.Owner);
|
||||
}
|
||||
|
||||
protected override void OnRemovedFromPart(IBodyPart old)
|
||||
protected override void OnRemovedFromPart(SharedBodyPartComponent old)
|
||||
{
|
||||
base.OnRemovedFromPart(old);
|
||||
|
||||
HandleMind(Owner, old.Owner);
|
||||
}
|
||||
|
||||
protected override void OnRemovedFromPartInBody(IBody oldBody, IBodyPart oldPart)
|
||||
protected override void OnRemovedFromPartInBody(SharedBodyComponent oldBody, SharedBodyPartComponent oldPart)
|
||||
{
|
||||
base.OnRemovedFromPartInBody(oldBody, oldPart);
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ namespace Content.Server.Body.Behavior
|
||||
IoCManager.InjectDependencies(this);
|
||||
}
|
||||
|
||||
protected override void OnAddedToBody(IBody body)
|
||||
protected override void OnAddedToBody(SharedBodyComponent body)
|
||||
{
|
||||
base.OnAddedToBody(body);
|
||||
Inhale(CycleDelay);
|
||||
|
||||
@@ -8,22 +8,24 @@ using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Server.Body.Behavior
|
||||
{
|
||||
public abstract class MechanismBehavior : IMechanismBehavior
|
||||
public abstract class MechanismBehavior : SharedMechanismBehavior
|
||||
{
|
||||
public IBody? Body => Part?.Body;
|
||||
private SharedMechanismComponent _parent = default!;
|
||||
|
||||
public IBodyPart? Part => Parent.Part;
|
||||
public override SharedBodyComponent? Body => Part?.Body;
|
||||
|
||||
public IMechanism Parent { get; private set; } = default!;
|
||||
public override SharedBodyPartComponent? Part => Parent.Part;
|
||||
|
||||
public IEntity Owner => Parent.Owner;
|
||||
public override SharedMechanismComponent Parent => _parent;
|
||||
|
||||
public virtual void Initialize(IMechanism parent)
|
||||
public override IEntity Owner => Parent.Owner;
|
||||
|
||||
public override void Initialize(SharedMechanismComponent parent)
|
||||
{
|
||||
Parent = parent;
|
||||
_parent = parent;
|
||||
}
|
||||
|
||||
public virtual void Startup()
|
||||
public override void Startup()
|
||||
{
|
||||
if (Part == null)
|
||||
{
|
||||
@@ -40,7 +42,9 @@ namespace Content.Server.Body.Behavior
|
||||
}
|
||||
}
|
||||
|
||||
public void AddedToBody(IBody body)
|
||||
public override void Update(float frameTime) { }
|
||||
|
||||
public override void AddedToBody(SharedBodyComponent body)
|
||||
{
|
||||
DebugTools.AssertNotNull(Body);
|
||||
DebugTools.AssertNotNull(body);
|
||||
@@ -48,7 +52,7 @@ namespace Content.Server.Body.Behavior
|
||||
OnAddedToBody(body);
|
||||
}
|
||||
|
||||
public void AddedToPart(IBodyPart part)
|
||||
public override void AddedToPart(SharedBodyPartComponent part)
|
||||
{
|
||||
DebugTools.AssertNotNull(Part);
|
||||
DebugTools.AssertNotNull(part);
|
||||
@@ -56,7 +60,7 @@ namespace Content.Server.Body.Behavior
|
||||
OnAddedToPart(part);
|
||||
}
|
||||
|
||||
public void AddedToPartInBody(IBody body, IBodyPart part)
|
||||
public override void AddedToPartInBody(SharedBodyComponent body, SharedBodyPartComponent part)
|
||||
{
|
||||
DebugTools.AssertNotNull(Body);
|
||||
DebugTools.AssertNotNull(body);
|
||||
@@ -66,7 +70,7 @@ namespace Content.Server.Body.Behavior
|
||||
OnAddedToPartInBody(body, part);
|
||||
}
|
||||
|
||||
public void RemovedFromBody(IBody old)
|
||||
public override void RemovedFromBody(SharedBodyComponent old)
|
||||
{
|
||||
DebugTools.AssertNull(Body);
|
||||
DebugTools.AssertNotNull(old);
|
||||
@@ -74,7 +78,7 @@ namespace Content.Server.Body.Behavior
|
||||
OnRemovedFromBody(old);
|
||||
}
|
||||
|
||||
public void RemovedFromPart(IBodyPart old)
|
||||
public override void RemovedFromPart(SharedBodyPartComponent old)
|
||||
{
|
||||
DebugTools.AssertNull(Part);
|
||||
DebugTools.AssertNotNull(old);
|
||||
@@ -82,7 +86,7 @@ namespace Content.Server.Body.Behavior
|
||||
OnRemovedFromPart(old);
|
||||
}
|
||||
|
||||
public void RemovedFromPartInBody(IBody oldBody, IBodyPart oldPart)
|
||||
public override void RemovedFromPartInBody(SharedBodyComponent oldBody, SharedBodyPartComponent oldPart)
|
||||
{
|
||||
DebugTools.AssertNull(Body);
|
||||
DebugTools.AssertNull(Part);
|
||||
@@ -92,18 +96,16 @@ namespace Content.Server.Body.Behavior
|
||||
OnRemovedFromPartInBody(oldBody, oldPart);
|
||||
}
|
||||
|
||||
protected virtual void OnAddedToBody(IBody body) { }
|
||||
protected virtual void OnAddedToBody(SharedBodyComponent body) { }
|
||||
|
||||
protected virtual void OnAddedToPart(IBodyPart part) { }
|
||||
protected virtual void OnAddedToPart(SharedBodyPartComponent part) { }
|
||||
|
||||
protected virtual void OnAddedToPartInBody(IBody body, IBodyPart part) { }
|
||||
protected virtual void OnAddedToPartInBody(SharedBodyComponent body, SharedBodyPartComponent part) { }
|
||||
|
||||
protected virtual void OnRemovedFromBody(IBody old) { }
|
||||
protected virtual void OnRemovedFromBody(SharedBodyComponent old) { }
|
||||
|
||||
protected virtual void OnRemovedFromPart(IBodyPart old) { }
|
||||
protected virtual void OnRemovedFromPart(SharedBodyPartComponent old) { }
|
||||
|
||||
protected virtual void OnRemovedFromPartInBody(IBody oldBody, IBodyPart oldPart) { }
|
||||
|
||||
public virtual void Update(float frameTime) { }
|
||||
protected virtual void OnRemovedFromPartInBody(SharedBodyComponent oldBody, SharedBodyPartComponent oldPart) { }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
#nullable enable
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using Content.Shared.Body.Behavior;
|
||||
using Content.Shared.Body.Components;
|
||||
using Content.Shared.Body.Part;
|
||||
|
||||
namespace Content.Server.Body.Behavior
|
||||
{
|
||||
public static class MechanismExtensions
|
||||
{
|
||||
public static bool HasMechanismBehavior<T>(this IBody body) where T : IMechanismBehavior
|
||||
{
|
||||
return body.Parts.Any(p => p.Key.HasMechanismBehavior<T>());
|
||||
}
|
||||
|
||||
public static bool HasMechanismBehavior<T>(this IBodyPart part) where T : IMechanismBehavior
|
||||
{
|
||||
return part.Mechanisms.Any(m => m.HasBehavior<T>());
|
||||
}
|
||||
|
||||
public static IEnumerable<IMechanismBehavior> GetMechanismBehaviors(this IBody body)
|
||||
{
|
||||
foreach (var (part, _) in body.Parts)
|
||||
foreach (var mechanism in part.Mechanisms)
|
||||
foreach (var behavior in mechanism.Behaviors.Values)
|
||||
{
|
||||
yield return behavior;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool TryGetMechanismBehaviors(this IBody body,
|
||||
[NotNullWhen(true)] out List<IMechanismBehavior>? behaviors)
|
||||
{
|
||||
behaviors = body.GetMechanismBehaviors().ToList();
|
||||
|
||||
if (behaviors.Count == 0)
|
||||
{
|
||||
behaviors = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static IEnumerable<T> GetMechanismBehaviors<T>(this IBody body) where T : class, IMechanismBehavior
|
||||
{
|
||||
foreach (var (part, _) in body.Parts)
|
||||
foreach (var mechanism in part.Mechanisms)
|
||||
foreach (var behavior in mechanism.Behaviors.Values)
|
||||
{
|
||||
if (behavior is T tBehavior)
|
||||
{
|
||||
yield return tBehavior;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static bool TryGetMechanismBehaviors<T>(this IBody entity, [NotNullWhen(true)] out List<T>? behaviors)
|
||||
where T : class, IMechanismBehavior
|
||||
{
|
||||
behaviors = entity.GetMechanismBehaviors<T>().ToList();
|
||||
|
||||
if (behaviors.Count == 0)
|
||||
{
|
||||
behaviors = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user