Refactoring body system to use containers and general body cleanup (#20202)

Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
This commit is contained in:
Jezithyr
2023-09-21 00:23:02 -07:00
committed by GitHub
parent d888d9ad67
commit 31b2c9f830
38 changed files with 1298 additions and 1098 deletions

View File

@@ -1,32 +1,23 @@
using Content.Shared.Body.Components;
using Content.Shared.Body.Organ;
using Content.Shared.Body.Systems;
using Robust.Shared.Containers;
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;
namespace Content.Shared.Body.Part;
[RegisterComponent, NetworkedComponent]
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
[Access(typeof(SharedBodySystem))]
public sealed partial class BodyPartComponent : Component
{
[DataField("body")]
// Need to set this on container changes as it may be several transform parents up the hierarchy.
/// <summary>
/// Parent body for this part.
/// </summary>
[DataField, AutoNetworkedField]
public EntityUid? Body;
// This inter-entity relationship makes be deeply uncomfortable because its probably going to re-encounter all of the
// networking issues that containers and joints have.
// TODO just use containers. Please.
// Do not use set or get data from this in client-side code.
public BodyPartSlot? ParentSlot;
// Do not use set or get data from this in client-side code.
[DataField("children")]
public Dictionary<string, BodyPartSlot> Children = new();
// See all the above ccomments.
[DataField("organs")]
public Dictionary<string, OrganSlot> Organs = new();
[DataField("partType")]
[DataField, AutoNetworkedField]
public BodyPartType PartType = BodyPartType.Other;
// TODO BODY Replace with a simulation of organs
@@ -34,9 +25,90 @@ public sealed partial class BodyPartComponent : Component
/// Whether or not the owning <see cref="Body"/> will die if all
/// <see cref="BodyComponent"/>s of this type are removed from it.
/// </summary>
[DataField("vital")]
[DataField("vital"), AutoNetworkedField]
public bool IsVital;
[DataField("symmetry")]
[DataField, AutoNetworkedField]
public BodyPartSymmetry Symmetry = BodyPartSymmetry.None;
/// <summary>
/// Child body parts attached to this body part.
/// </summary>
[DataField, AutoNetworkedField(CloneData = true)]
public Dictionary<string, BodyPartSlot> Children = new();
/// <summary>
/// Organs attached to this body part.
/// </summary>
[DataField, AutoNetworkedField(CloneData = true)]
public Dictionary<string, OrganSlot> Organs = new();
/// <summary>
/// These are only for VV/Debug do not use these for gameplay/systems
/// </summary>
[ViewVariables]
private List<ContainerSlot> BodyPartSlotsVV
{
get
{
List<ContainerSlot> temp = new();
var containerSystem = IoCManager.Resolve<IEntityManager>().System<SharedContainerSystem>();
foreach (var slotId in Children.Keys)
{
temp.Add((ContainerSlot) containerSystem.GetContainer(Owner, slotId));
}
return temp;
}
}
[ViewVariables]
private List<ContainerSlot> OrganSlotsVV
{
get
{
List<ContainerSlot> temp = new();
var containerSystem = IoCManager.Resolve<IEntityManager>().System<SharedContainerSystem>();
foreach (var slotId in Organs.Keys)
{
temp.Add((ContainerSlot) containerSystem.GetContainer(Owner, slotId));
}
return temp;
}
}
}
/// <summary>
/// Contains metadata about a body part in relation to its slot.
/// </summary>
[NetSerializable, Serializable]
[DataRecord]
public partial struct BodyPartSlot
{
public string Id;
public BodyPartType Type;
public BodyPartSlot(string id, BodyPartType type)
{
Id = id;
Type = type;
}
};
/// <summary>
/// Contains metadata about an organ part in relation to its slot.
/// </summary>
[NetSerializable, Serializable]
[DataRecord]
public partial struct OrganSlot
{
public string Id;
public OrganSlot(string id)
{
Id = id;
}
};

View File

@@ -1,34 +0,0 @@
using Content.Shared.Body.Organ;
using Robust.Shared.Serialization;
namespace Content.Shared.Body.Part;
[Serializable, NetSerializable]
public sealed class BodyPartComponentState : ComponentState
{
public readonly NetEntity? Body;
public readonly BodyPartSlot? ParentSlot;
public readonly Dictionary<string, BodyPartSlot> Children;
public readonly Dictionary<string, OrganSlot> Organs;
public readonly BodyPartType PartType;
public readonly bool IsVital;
public readonly BodyPartSymmetry Symmetry;
public BodyPartComponentState(
NetEntity? body,
BodyPartSlot? parentSlot,
Dictionary<string, BodyPartSlot> children,
Dictionary<string, OrganSlot> organs,
BodyPartType partType,
bool isVital,
BodyPartSymmetry symmetry)
{
ParentSlot = parentSlot;
Children = children;
Organs = organs;
PartType = partType;
IsVital = isVital;
Symmetry = symmetry;
Body = body;
}
}

View File

@@ -1,43 +0,0 @@
using Content.Shared.Body.Systems;
using Robust.Shared.Serialization;
namespace Content.Shared.Body.Part;
[Serializable, NetSerializable]
[Access(typeof(SharedBodySystem))]
[DataDefinition]
public sealed partial record BodyPartSlot
{
[DataField("id")]
public string Id = string.Empty;
[DataField("type")]
public BodyPartType? Type;
[NonSerialized]
[DataField("parent")]
public EntityUid Parent;
public NetEntity NetParent;
[NonSerialized]
[DataField("child")]
public EntityUid? Child;
public NetEntity? NetChild;
public void SetChild(EntityUid? child, NetEntity? netChild)
{
Child = child;
NetChild = netChild;
}
// Rider doesn't suggest explicit properties during deconstruction without this
public void Deconstruct(out EntityUid? child, out string id, out EntityUid parent, out BodyPartType? type)
{
child = Child;
id = Id;
parent = Parent;
type = Type;
}
}