Remove IBody, IBodyPart, IMechanism and IMechanismBehavior (#4187)
* Remove IBody, IBodyPart, IMechanism and IMechanismBehavior interfaces * Summary cleanup
This commit is contained in:
@@ -1,256 +0,0 @@
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Content.Shared.Body.Part;
|
||||
using Content.Shared.Body.Part.Property;
|
||||
using Content.Shared.Body.Preset;
|
||||
using Content.Shared.Body.Slot;
|
||||
using Content.Shared.Body.Template;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Shared.Body.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// Component representing a collection of <see cref="IBodyPart"/>s
|
||||
/// attached to each other.
|
||||
/// </summary>
|
||||
public interface IBody : IComponent, IBodyPartContainer
|
||||
{
|
||||
/// <summary>
|
||||
/// The <see cref="BodyTemplatePrototype"/> used to create this
|
||||
/// <see cref="IBody"/>.
|
||||
/// </summary>
|
||||
public BodyTemplatePrototype? Template { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="BodyPresetPrototype"/> used to create this
|
||||
/// <see cref="IBody"/>.
|
||||
/// </summary>
|
||||
public BodyPresetPrototype? Preset { get; }
|
||||
|
||||
/// <summary>
|
||||
/// An enumeration of the slots that make up this body, regardless
|
||||
/// of if they contain a part or not.
|
||||
/// </summary>
|
||||
IEnumerable<BodyPartSlot> Slots { get; }
|
||||
|
||||
/// <summary>
|
||||
/// An enumeration of the parts on this body paired with the slots
|
||||
/// that they are in.
|
||||
/// </summary>
|
||||
IEnumerable<KeyValuePair<IBodyPart, BodyPartSlot>> Parts { get; }
|
||||
|
||||
/// <summary>
|
||||
/// An enumeration of the slots on this body without a part in them.
|
||||
/// </summary>
|
||||
IEnumerable<BodyPartSlot> EmptySlots { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Finds the central <see cref="BodyPartSlot"/>, if any,
|
||||
/// of this body.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// The central <see cref="BodyPartSlot"/> if one exists,
|
||||
/// null otherwise.
|
||||
/// </returns>
|
||||
BodyPartSlot? CenterSlot { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Finds the central <see cref="IBodyPart"/>, if any,
|
||||
/// of this body.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// The central <see cref="IBodyPart"/> if one exists,
|
||||
/// null otherwise.
|
||||
/// </returns>
|
||||
IBodyPart? CenterPart { get; }
|
||||
|
||||
// TODO BODY Sensible templates
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to add a part to the given slot.
|
||||
/// </summary>
|
||||
/// <param name="slotId">The slot to add this part to.</param>
|
||||
/// <param name="part">The part to add.</param>
|
||||
/// <param name="checkSlotExists">
|
||||
/// Whether to check if the slot exists, or create one otherwise.
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// true if the part was added, false otherwise even if it was
|
||||
/// already added.
|
||||
/// </returns>
|
||||
bool TryAddPart(string slotId, IBodyPart part);
|
||||
|
||||
void SetPart(string slotId, IBodyPart part);
|
||||
|
||||
/// <summary>
|
||||
/// Checks if there is a <see cref="IBodyPart"/> in the given slot.
|
||||
/// </summary>
|
||||
/// <param name="slotId">The slot to look in.</param>
|
||||
/// <returns>
|
||||
/// true if there is a part in the given <see cref="slotId"/>,
|
||||
/// false otherwise.
|
||||
/// </returns>
|
||||
bool HasPart(string slotId);
|
||||
|
||||
/// <summary>
|
||||
/// Checks if this <see cref="IBody"/> contains the given <see cref="part"/>.
|
||||
/// </summary>
|
||||
/// <param name="part">The part to look for.</param>
|
||||
/// <returns>
|
||||
/// true if the given <see cref="part"/> is attached to the body,
|
||||
/// false otherwise.
|
||||
/// </returns>
|
||||
bool HasPart(IBodyPart part);
|
||||
|
||||
/// <summary>
|
||||
/// Removes the given <see cref="IBodyPart"/> from this body,
|
||||
/// dropping other <see cref="IBodyPart"/> if they were hanging
|
||||
/// off of it.
|
||||
/// <param name="part">The part to remove.</param>
|
||||
/// <returns>
|
||||
/// true if the part was removed, false otherwise
|
||||
/// even if the part was already removed previously.
|
||||
/// </returns>
|
||||
/// </summary>
|
||||
bool RemovePart(IBodyPart part);
|
||||
|
||||
/// <summary>
|
||||
/// Removes the body part in slot <see cref="slotId"/> from this body,
|
||||
/// if one exists.
|
||||
/// </summary>
|
||||
/// <param name="slotId">The slot to remove it from.</param>
|
||||
/// <returns>true if the part was removed, false otherwise.</returns>
|
||||
bool RemovePart(string slotId);
|
||||
|
||||
/// <summary>
|
||||
/// Removes the body part from this body, if one exists.
|
||||
/// </summary>
|
||||
/// <param name="part">The part to remove from this body.</param>
|
||||
/// <param name="slotId">The slot that the part was in, if any.</param>
|
||||
/// <returns>
|
||||
/// true if <see cref="part"/> was removed, false otherwise.
|
||||
/// </returns>
|
||||
bool RemovePart(IBodyPart part, [NotNullWhen(true)] out BodyPartSlot? slotId);
|
||||
|
||||
/// <summary>
|
||||
/// Disconnects the given <see cref="IBodyPart"/> reference, potentially
|
||||
/// dropping other <see cref="IBodyPart">BodyParts</see> if they
|
||||
/// were hanging off of it.
|
||||
/// </summary>
|
||||
/// <param name="slot">The part to drop.</param>
|
||||
/// <param name="dropped">
|
||||
/// All of the parts that were dropped, including the one in
|
||||
/// <see cref="slot"/>.
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// true if the part was dropped, false otherwise.
|
||||
/// </returns>
|
||||
bool TryDropPart(BodyPartSlot slot, [NotNullWhen(true)] out Dictionary<BodyPartSlot, IBodyPart>? dropped);
|
||||
|
||||
/// <summary>
|
||||
/// Recursively searches for if <see cref="part"/> is connected to
|
||||
/// the center.
|
||||
/// </summary>
|
||||
/// <param name="part">The body part to find the center for.</param>
|
||||
/// <returns>
|
||||
/// true if it is connected to the center, false otherwise.
|
||||
/// </returns>
|
||||
bool ConnectedToCenter(IBodyPart part);
|
||||
|
||||
/// <summary>
|
||||
/// Returns whether the given part slot exists in this body.
|
||||
/// </summary>
|
||||
/// <param name="slot">The slot to check for.</param>
|
||||
/// <returns>true if the slot exists in this body, false otherwise.</returns>
|
||||
bool HasSlot(string slot);
|
||||
|
||||
BodyPartSlot? GetSlot(IBodyPart part);
|
||||
|
||||
/// <summary>
|
||||
/// Finds the slot that the given <see cref="IBodyPart"/> resides in.
|
||||
/// </summary>
|
||||
/// <param name="part">
|
||||
/// The <see cref="IBodyPart"/> to find the slot for.
|
||||
/// </param>
|
||||
/// <param name="slot">The slot found, if any.</param>
|
||||
/// <returns>true if a slot was found, false otherwise</returns>
|
||||
bool TryGetSlot(IBodyPart part, [NotNullWhen(true)] out BodyPartSlot? slot);
|
||||
|
||||
/// <summary>
|
||||
/// Finds the <see cref="IBodyPart"/> in the given
|
||||
/// <see cref="slotId"/> if one exists.
|
||||
/// </summary>
|
||||
/// <param name="slotId">The part slot to search in.</param>
|
||||
/// <param name="result">The body part in that slot, if any.</param>
|
||||
/// <returns>true if found, false otherwise.</returns>
|
||||
bool TryGetPart(string slotId, [NotNullWhen(true)] out IBodyPart? result);
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a slot of the specified type exists on this body.
|
||||
/// </summary>
|
||||
/// <param name="type">The type to check for.</param>
|
||||
/// <returns>true if present, false otherwise.</returns>
|
||||
bool HasSlotOfType(BodyPartType type);
|
||||
|
||||
/// <summary>
|
||||
/// Gets all slots of the specified type on this body.
|
||||
/// </summary>
|
||||
/// <param name="type">The type to check for.</param>
|
||||
/// <returns>An enumerable of the found slots.</returns>
|
||||
IEnumerable<BodyPartSlot> GetSlotsOfType(BodyPartType type);
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a part of the specified type exists on this body.
|
||||
/// </summary>
|
||||
/// <param name="type">The type to check for.</param>
|
||||
/// <returns>true if present, false otherwise.</returns>
|
||||
bool HasPartOfType(BodyPartType type);
|
||||
|
||||
/// <summary>
|
||||
/// Gets all slots of the specified type on this body.
|
||||
/// </summary>
|
||||
/// <param name="type">The type to check for.</param>
|
||||
/// <returns>An enumerable of the found slots.</returns>
|
||||
IEnumerable<IBodyPart> GetPartsOfType(BodyPartType type);
|
||||
|
||||
/// <summary>
|
||||
/// Finds all <see cref="IBodyPart"/>s with the given property in
|
||||
/// this body.
|
||||
/// </summary>
|
||||
/// <type name="type">The property type to look for.</type>
|
||||
/// <returns>A list of parts with that property.</returns>
|
||||
IEnumerable<(IBodyPart part, IBodyPartProperty property)> GetPartsWithProperty(Type type);
|
||||
|
||||
/// <summary>
|
||||
/// Finds all <see cref="IBodyPart"/>s with the given property in this body.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The property type to look for.</typeparam>
|
||||
/// <returns>A list of parts with that property.</returns>
|
||||
IEnumerable<(IBodyPart part, T property)> GetPartsWithProperty<T>() where T : class, IBodyPartProperty;
|
||||
|
||||
// TODO BODY Make a slot object that makes sense to the human mind, and make it serializable. Imagine the possibilities!
|
||||
/// <summary>
|
||||
/// Retrieves the slot at the given index.
|
||||
/// </summary>
|
||||
/// <param name="index">The index to look in.</param>
|
||||
/// <returns>A pair of the slot name and part type occupying it.</returns>
|
||||
BodyPartSlot SlotAt(int index);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the part at the given index.
|
||||
/// </summary>
|
||||
/// <param name="index">The index to look in.</param>
|
||||
/// <returns>A pair of the part name and body part occupying it.</returns>
|
||||
KeyValuePair<IBodyPart, BodyPartSlot> PartAt(int index);
|
||||
|
||||
/// <summary>
|
||||
/// Gibs this body.
|
||||
/// </summary>
|
||||
/// <param name="gibParts">
|
||||
/// Whether or not to also gib this body's parts.
|
||||
/// </param>
|
||||
void Gib(bool gibParts = false);
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using Content.Shared.Body.Behavior;
|
||||
using Content.Shared.Body.Part;
|
||||
using Content.Shared.Body.Part.Property;
|
||||
using Content.Shared.Body.Preset;
|
||||
@@ -25,7 +26,7 @@ using Robust.Shared.ViewVariables;
|
||||
namespace Content.Shared.Body.Components
|
||||
{
|
||||
// TODO BODY Damage methods for collections of IDamageableComponents
|
||||
public abstract class SharedBodyComponent : Component, IBody, ISerializationHooks
|
||||
public abstract class SharedBodyComponent : Component, IBodyPartContainer, ISerializationHooks
|
||||
{
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
|
||||
@@ -55,13 +56,13 @@ namespace Content.Shared.Body.Components
|
||||
private Dictionary<string, BodyPartSlot> SlotIds { get; } = new();
|
||||
|
||||
[ViewVariables]
|
||||
private Dictionary<IBodyPart, BodyPartSlot> SlotParts { get; } = new();
|
||||
private Dictionary<SharedBodyPartComponent, BodyPartSlot> SlotParts { get; } = new();
|
||||
|
||||
[ViewVariables]
|
||||
public IEnumerable<BodyPartSlot> Slots => SlotIds.Values;
|
||||
|
||||
[ViewVariables]
|
||||
public IEnumerable<KeyValuePair<IBodyPart, BodyPartSlot>> Parts => SlotParts;
|
||||
public IEnumerable<KeyValuePair<SharedBodyPartComponent, BodyPartSlot>> Parts => SlotParts;
|
||||
|
||||
[ViewVariables]
|
||||
public IEnumerable<BodyPartSlot> EmptySlots => Slots.Where(slot => slot.Part == null);
|
||||
@@ -71,7 +72,7 @@ namespace Content.Shared.Body.Components
|
||||
? SlotIds.GetValueOrDefault(centerSlot)
|
||||
: null;
|
||||
|
||||
public IBodyPart? CenterPart => CenterSlot?.Part;
|
||||
public SharedBodyPartComponent? CenterPart => CenterSlot?.Part;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -119,9 +120,9 @@ namespace Content.Shared.Body.Components
|
||||
return slot;
|
||||
}
|
||||
|
||||
private Dictionary<BodyPartSlot, IBodyPart> GetHangingParts(BodyPartSlot from)
|
||||
private Dictionary<BodyPartSlot, SharedBodyPartComponent> GetHangingParts(BodyPartSlot from)
|
||||
{
|
||||
var hanging = new Dictionary<BodyPartSlot, IBodyPart>();
|
||||
var hanging = new Dictionary<BodyPartSlot, SharedBodyPartComponent>();
|
||||
|
||||
foreach (var connection in from.Connections)
|
||||
{
|
||||
@@ -135,7 +136,7 @@ namespace Content.Shared.Body.Components
|
||||
return hanging;
|
||||
}
|
||||
|
||||
protected virtual bool CanAddPart(string slotId, IBodyPart part)
|
||||
protected virtual bool CanAddPart(string slotId, SharedBodyPartComponent part)
|
||||
{
|
||||
if (!SlotIds.TryGetValue(slotId, out var slot) ||
|
||||
slot.CanAddPart(part))
|
||||
@@ -146,7 +147,7 @@ namespace Content.Shared.Body.Components
|
||||
return true;
|
||||
}
|
||||
|
||||
protected virtual void OnAddPart(BodyPartSlot slot, IBodyPart part)
|
||||
protected virtual void OnAddPart(BodyPartSlot slot, SharedBodyPartComponent part)
|
||||
{
|
||||
SlotParts[part] = slot;
|
||||
part.Body = this;
|
||||
@@ -162,7 +163,7 @@ namespace Content.Shared.Body.Components
|
||||
OnBodyChanged();
|
||||
}
|
||||
|
||||
protected virtual void OnRemovePart(BodyPartSlot slot, IBodyPart part)
|
||||
protected virtual void OnRemovePart(BodyPartSlot slot, SharedBodyPartComponent part)
|
||||
{
|
||||
SlotParts.Remove(part);
|
||||
|
||||
@@ -203,7 +204,8 @@ namespace Content.Shared.Body.Components
|
||||
OnBodyChanged();
|
||||
}
|
||||
|
||||
public bool TryAddPart(string slotId, IBodyPart part)
|
||||
// TODO BODY Sensible templates
|
||||
public bool TryAddPart(string slotId, SharedBodyPartComponent part)
|
||||
{
|
||||
DebugTools.AssertNotNull(part);
|
||||
DebugTools.AssertNotNull(slotId);
|
||||
@@ -217,7 +219,7 @@ namespace Content.Shared.Body.Components
|
||||
slot.TryAddPart(part);
|
||||
}
|
||||
|
||||
public void SetPart(string slotId, IBodyPart part)
|
||||
public void SetPart(string slotId, SharedBodyPartComponent part)
|
||||
{
|
||||
if (!SlotIds.TryGetValue(slotId, out var slot))
|
||||
{
|
||||
@@ -236,14 +238,14 @@ namespace Content.Shared.Body.Components
|
||||
slot.Part != null;
|
||||
}
|
||||
|
||||
public bool HasPart(IBodyPart part)
|
||||
public bool HasPart(SharedBodyPartComponent part)
|
||||
{
|
||||
DebugTools.AssertNotNull(part);
|
||||
|
||||
return SlotParts.ContainsKey(part);
|
||||
}
|
||||
|
||||
public bool RemovePart(IBodyPart part)
|
||||
public bool RemovePart(SharedBodyPartComponent part)
|
||||
{
|
||||
DebugTools.AssertNotNull(part);
|
||||
|
||||
@@ -259,7 +261,7 @@ namespace Content.Shared.Body.Components
|
||||
slot.RemovePart();
|
||||
}
|
||||
|
||||
public bool RemovePart(IBodyPart part, [NotNullWhen(true)] out BodyPartSlot? slotId)
|
||||
public bool RemovePart(SharedBodyPartComponent part, [NotNullWhen(true)] out BodyPartSlot? slotId)
|
||||
{
|
||||
DebugTools.AssertNotNull(part);
|
||||
|
||||
@@ -279,7 +281,7 @@ namespace Content.Shared.Body.Components
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool TryDropPart(BodyPartSlot slot, [NotNullWhen(true)] out Dictionary<BodyPartSlot, IBodyPart>? dropped)
|
||||
public bool TryDropPart(BodyPartSlot slot, [NotNullWhen(true)] out Dictionary<BodyPartSlot, SharedBodyPartComponent>? dropped)
|
||||
{
|
||||
DebugTools.AssertNotNull(slot);
|
||||
|
||||
@@ -304,7 +306,7 @@ namespace Content.Shared.Body.Components
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool ConnectedToCenter(IBodyPart part)
|
||||
public bool ConnectedToCenter(SharedBodyPartComponent part)
|
||||
{
|
||||
return TryGetSlot(part, out var result) &&
|
||||
ConnectedToCenterPartRecursion(result);
|
||||
@@ -343,7 +345,7 @@ namespace Content.Shared.Body.Components
|
||||
return SlotIds.ContainsKey(slot);
|
||||
}
|
||||
|
||||
public IEnumerable<IBodyPart> GetParts()
|
||||
public IEnumerable<SharedBodyPartComponent> GetParts()
|
||||
{
|
||||
foreach (var slot in SlotIds.Values)
|
||||
{
|
||||
@@ -354,7 +356,7 @@ namespace Content.Shared.Body.Components
|
||||
}
|
||||
}
|
||||
|
||||
public bool TryGetPart(string slotId, [NotNullWhen(true)] out IBodyPart? result)
|
||||
public bool TryGetPart(string slotId, [NotNullWhen(true)] out SharedBodyPartComponent? result)
|
||||
{
|
||||
result = null;
|
||||
|
||||
@@ -367,7 +369,7 @@ namespace Content.Shared.Body.Components
|
||||
return SlotIds.GetValueOrDefault(id);
|
||||
}
|
||||
|
||||
public BodyPartSlot? GetSlot(IBodyPart part)
|
||||
public BodyPartSlot? GetSlot(SharedBodyPartComponent part)
|
||||
{
|
||||
return SlotParts.GetValueOrDefault(part);
|
||||
}
|
||||
@@ -377,12 +379,12 @@ namespace Content.Shared.Body.Components
|
||||
return (slot = GetSlot(slotId)) != null;
|
||||
}
|
||||
|
||||
public bool TryGetSlot(IBodyPart part, [NotNullWhen(true)] out BodyPartSlot? slot)
|
||||
public bool TryGetSlot(SharedBodyPartComponent part, [NotNullWhen(true)] out BodyPartSlot? slot)
|
||||
{
|
||||
return (slot = GetSlot(part)) != null;
|
||||
}
|
||||
|
||||
public bool TryGetPartConnections(string slotId, [NotNullWhen(true)] out List<IBodyPart>? connections)
|
||||
public bool TryGetPartConnections(string slotId, [NotNullWhen(true)] out List<SharedBodyPartComponent>? connections)
|
||||
{
|
||||
if (!SlotIds.TryGetValue(slotId, out var slot))
|
||||
{
|
||||
@@ -390,7 +392,7 @@ namespace Content.Shared.Body.Components
|
||||
return false;
|
||||
}
|
||||
|
||||
connections = new List<IBodyPart>();
|
||||
connections = new List<SharedBodyPartComponent>();
|
||||
foreach (var connection in slot.Connections)
|
||||
{
|
||||
if (connection.Part != null)
|
||||
@@ -439,7 +441,7 @@ namespace Content.Shared.Body.Components
|
||||
return false;
|
||||
}
|
||||
|
||||
public IEnumerable<IBodyPart> GetPartsOfType(BodyPartType type)
|
||||
public IEnumerable<SharedBodyPartComponent> GetPartsOfType(BodyPartType type)
|
||||
{
|
||||
foreach (var slot in GetSlotsOfType(type))
|
||||
{
|
||||
@@ -450,7 +452,8 @@ namespace Content.Shared.Body.Components
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<(IBodyPart part, IBodyPartProperty property)> GetPartsWithProperty(Type type)
|
||||
/// <returns>A list of parts with that property.</returns>
|
||||
public IEnumerable<(SharedBodyPartComponent part, IBodyPartProperty property)> GetPartsWithProperty(Type type)
|
||||
{
|
||||
foreach (var slot in SlotIds.Values)
|
||||
{
|
||||
@@ -461,7 +464,7 @@ namespace Content.Shared.Body.Components
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<(IBodyPart part, T property)> GetPartsWithProperty<T>() where T : class, IBodyPartProperty
|
||||
public IEnumerable<(SharedBodyPartComponent part, T property)> GetPartsWithProperty<T>() where T : class, IBodyPartProperty
|
||||
{
|
||||
foreach (var part in SlotParts.Keys)
|
||||
{
|
||||
@@ -509,9 +512,6 @@ namespace Content.Shared.Body.Components
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when the layout of this body changes.
|
||||
/// </summary>
|
||||
private void OnBodyChanged()
|
||||
{
|
||||
// Calculate move speed based on this body.
|
||||
@@ -523,19 +523,7 @@ namespace Content.Shared.Body.Components
|
||||
Dirty();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the combined length of the distance to the nearest
|
||||
/// <see cref="IBodyPart"/> that is a foot.
|
||||
/// If you consider a <see cref="IBody"/> a node map, then it will
|
||||
/// look for a foot node from the given node. It can only search
|
||||
/// through <see cref="IBodyPart"/>s with an
|
||||
/// <see cref="ExtensionComponent"/>.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// The distance to the foot if found, <see cref="float.MinValue"/>
|
||||
/// otherwise.
|
||||
/// </returns>
|
||||
public float DistanceToNearestFoot(IBodyPart source)
|
||||
public float DistanceToNearestFoot(SharedBodyPartComponent source)
|
||||
{
|
||||
if (source.PartType == BodyPartType.Foot &&
|
||||
source.TryGetProperty<ExtensionComponent>(out var extension))
|
||||
@@ -546,7 +534,7 @@ namespace Content.Shared.Body.Components
|
||||
return LookForFootRecursion(source);
|
||||
}
|
||||
|
||||
private float LookForFootRecursion(IBodyPart current, HashSet<BodyPartSlot>? searched = null)
|
||||
private float LookForFootRecursion(SharedBodyPartComponent current, HashSet<BodyPartSlot>? searched = null)
|
||||
{
|
||||
searched ??= new HashSet<BodyPartSlot>();
|
||||
|
||||
@@ -555,13 +543,11 @@ namespace Content.Shared.Body.Components
|
||||
return float.MinValue;
|
||||
}
|
||||
|
||||
// Get all connected parts if the current part has an extension property
|
||||
if (!TryGetSlot(current, out var slot))
|
||||
{
|
||||
return float.MinValue;
|
||||
}
|
||||
|
||||
// If a connected BodyPart is a foot, return this BodyPart's length.
|
||||
foreach (var connection in slot.Connections)
|
||||
{
|
||||
if (connection.PartType == BodyPartType.Foot &&
|
||||
@@ -571,8 +557,6 @@ namespace Content.Shared.Body.Components
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise, get the recursion values of all connected BodyParts and
|
||||
// store them in a list.
|
||||
var distances = new List<float>();
|
||||
foreach (var connection in slot.Connections)
|
||||
{
|
||||
@@ -589,8 +573,6 @@ namespace Content.Shared.Body.Components
|
||||
}
|
||||
}
|
||||
|
||||
// If one or more of the searches found a foot, return the smallest one
|
||||
// and add this ones length.
|
||||
if (distances.Count > 0)
|
||||
{
|
||||
return distances.Min<float>() + extProperty.Distance;
|
||||
@@ -605,7 +587,7 @@ namespace Content.Shared.Body.Components
|
||||
return SlotIds.Values.ElementAt(index);
|
||||
}
|
||||
|
||||
public KeyValuePair<IBodyPart, BodyPartSlot> PartAt(int index)
|
||||
public KeyValuePair<SharedBodyPartComponent, BodyPartSlot> PartAt(int index)
|
||||
{
|
||||
return SlotParts.ElementAt(index);
|
||||
}
|
||||
@@ -664,12 +646,68 @@ namespace Content.Shared.Body.Components
|
||||
part.Gib();
|
||||
}
|
||||
}
|
||||
|
||||
public bool TryGetMechanismBehaviors([NotNullWhen(true)] out List<SharedMechanismBehavior>? behaviors)
|
||||
{
|
||||
behaviors = GetMechanismBehaviors().ToList();
|
||||
|
||||
if (behaviors.Count == 0)
|
||||
{
|
||||
behaviors = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool HasMechanismBehavior<T>() where T : SharedMechanismBehavior
|
||||
{
|
||||
return Parts.Any(p => p.Key.HasMechanismBehavior<T>());
|
||||
}
|
||||
|
||||
// TODO cache these 2 methods jesus
|
||||
public IEnumerable<SharedMechanismBehavior> GetMechanismBehaviors()
|
||||
{
|
||||
foreach (var (part, _) in Parts)
|
||||
foreach (var mechanism in part.Mechanisms)
|
||||
foreach (var behavior in mechanism.Behaviors.Values)
|
||||
{
|
||||
yield return behavior;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<T> GetMechanismBehaviors<T>() where T : SharedMechanismBehavior
|
||||
{
|
||||
foreach (var (part, _) in Parts)
|
||||
foreach (var mechanism in part.Mechanisms)
|
||||
foreach (var behavior in mechanism.Behaviors.Values)
|
||||
{
|
||||
if (behavior is T tBehavior)
|
||||
{
|
||||
yield return tBehavior;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool TryGetMechanismBehaviors<T>([NotNullWhen(true)] out List<T>? behaviors)
|
||||
where T : SharedMechanismBehavior
|
||||
{
|
||||
behaviors = GetMechanismBehaviors<T>().ToList();
|
||||
|
||||
if (behaviors.Count == 0)
|
||||
{
|
||||
behaviors = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public class BodyComponentState : ComponentState
|
||||
{
|
||||
private Dictionary<string, IBodyPart>? _parts;
|
||||
private Dictionary<string, SharedBodyPartComponent>? _parts;
|
||||
|
||||
public readonly (string slot, EntityUid partId)[] PartIds;
|
||||
|
||||
@@ -678,7 +716,7 @@ namespace Content.Shared.Body.Components
|
||||
PartIds = partIds;
|
||||
}
|
||||
|
||||
public Dictionary<string, IBodyPart> Parts(IEntityManager? entityManager = null)
|
||||
public Dictionary<string, SharedBodyPartComponent> Parts(IEntityManager? entityManager = null)
|
||||
{
|
||||
if (_parts != null)
|
||||
{
|
||||
@@ -687,7 +725,7 @@ namespace Content.Shared.Body.Components
|
||||
|
||||
entityManager ??= IoCManager.Resolve<IEntityManager>();
|
||||
|
||||
var parts = new Dictionary<string, IBodyPart>(PartIds.Length);
|
||||
var parts = new Dictionary<string, SharedBodyPartComponent>(PartIds.Length);
|
||||
|
||||
foreach (var (slot, partId) in PartIds)
|
||||
{
|
||||
@@ -696,7 +734,7 @@ namespace Content.Shared.Body.Components
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!entity.TryGetComponent(out IBodyPart? part))
|
||||
if (!entity.TryGetComponent(out SharedBodyPartComponent? part))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user