ECS and cleanup body system, merge body templates and presets into body prototypes (#11991)

Co-authored-by: Jezithyr <Jezithyr@gmail.com>
This commit is contained in:
DrSmugleaf
2022-10-23 00:46:28 +02:00
committed by GitHub
parent 9a38736c3c
commit f323fb7644
140 changed files with 2478 additions and 2571 deletions

View File

@@ -1,18 +0,0 @@
using Content.Shared.Body.Components;
using Robust.Shared.Serialization;
namespace Content.Shared.Body.Part
{
//TODO: This should be a prototype. --DrSmugleaf
/// <summary>
/// Determines whether two <see cref="SharedBodyPartComponent"/>s can connect.
/// </summary>
[Serializable, NetSerializable]
public enum BodyPartCompatibility
{
Universal = 0,
Biological,
Mechanical,
Slime,
}
}

View File

@@ -0,0 +1,44 @@
using Content.Shared.Body.Components;
using Content.Shared.Body.Organ;
using Content.Shared.Body.Systems;
using Robust.Shared.GameStates;
namespace Content.Shared.Body.Part;
[RegisterComponent, NetworkedComponent]
[Access(typeof(SharedBodySystem))]
public sealed class BodyPartComponent : Component
{
[ViewVariables]
[DataField("body")]
public EntityUid? Body;
[ViewVariables]
[DataField("parent")]
public BodyPartSlot? ParentSlot;
[ViewVariables]
[DataField("children")]
public Dictionary<string, BodyPartSlot> Children = new();
[ViewVariables]
[DataField("organs")]
public Dictionary<string, OrganSlot> Organs = new();
[ViewVariables]
[DataField("partType")]
public BodyPartType PartType = BodyPartType.Other;
// TODO BODY Replace with a simulation of organs
/// <summary>
/// Whether or not the owning <see cref="Body"/> will die if all
/// <see cref="BodyComponent"/>s of this type are removed from it.
/// </summary>
[ViewVariables]
[DataField("vital")]
public bool IsVital;
[ViewVariables]
[DataField("symmetry")]
public BodyPartSymmetry Symmetry = BodyPartSymmetry.None;
}

View File

@@ -0,0 +1,34 @@
using Content.Shared.Body.Organ;
using Robust.Shared.Serialization;
namespace Content.Shared.Body.Part;
[Serializable, NetSerializable]
public sealed class BodyPartComponentState : ComponentState
{
public readonly EntityUid? 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(
EntityUid? 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,104 +1,21 @@
using Content.Shared.Body.Components;
using Content.Shared.Body.Systems;
using Robust.Shared.Serialization;
namespace Content.Shared.Body.Part
namespace Content.Shared.Body.Part;
[Serializable, NetSerializable]
[Access(typeof(SharedBodySystem))]
[DataRecord]
public sealed record BodyPartSlot(string Id, EntityUid Parent, BodyPartType? Type)
{
public sealed class BodyPartSlot
public EntityUid? Child { get; set; }
// 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)
{
public BodyPartSlot(string id, BodyPartType partType, IEnumerable<BodyPartSlot> connections)
{
Id = id;
PartType = partType;
Connections = new HashSet<BodyPartSlot>(connections);
}
public BodyPartSlot(string id, BodyPartType partType)
{
Id = id;
PartType = partType;
Connections = new HashSet<BodyPartSlot>();
}
/// <summary>
/// The ID of this slot.
/// </summary>
[ViewVariables]
public string Id { get; }
/// <summary>
/// The part type that this slot accepts.
/// </summary>
[ViewVariables]
public BodyPartType PartType { get; }
/// <summary>
/// The part currently in this slot, if any.
/// </summary>
[ViewVariables]
public SharedBodyPartComponent? Part { get; private set; }
/// <summary>
/// List of slots that this slot connects to.
/// </summary>
[ViewVariables]
public HashSet<BodyPartSlot> Connections { get; private set; }
public event Action<SharedBodyPartComponent>? PartAdded;
public event Action<SharedBodyPartComponent>? PartRemoved;
internal void SetConnectionsInternal(IEnumerable<BodyPartSlot> connections)
{
Connections = new HashSet<BodyPartSlot>(connections);
}
public bool CanAddPart(SharedBodyPartComponent part)
{
return Part == null && part.PartType == PartType;
}
public bool TryAddPart(SharedBodyPartComponent part)
{
if (!CanAddPart(part))
{
return false;
}
SetPart(part);
return true;
}
public void SetPart(SharedBodyPartComponent part)
{
if (Part != null)
{
RemovePart();
}
Part = part;
PartAdded?.Invoke(part);
}
public bool RemovePart()
{
if (Part == null)
{
return false;
}
var old = Part;
Part = null;
PartRemoved?.Invoke(old);
return true;
}
public void Shutdown()
{
Part = null;
Connections.Clear();
PartAdded = null;
PartRemoved = null;
}
child = Child;
id = Id;
parent = Parent;
type = Type;
}
}

View File

@@ -4,7 +4,7 @@ using Robust.Shared.Serialization;
namespace Content.Shared.Body.Part
{
/// <summary>
/// Defines the symmetry of a <see cref="SharedBodyPartComponent"/>.
/// Defines the symmetry of a <see cref="BodyComponent"/>.
/// </summary>
[Serializable, NetSerializable]
public enum BodyPartSymmetry

View File

@@ -4,7 +4,7 @@ using Robust.Shared.Serialization;
namespace Content.Shared.Body.Part
{
/// <summary>
/// Defines the type of a <see cref="SharedBodyPartComponent"/>.
/// Defines the type of a <see cref="BodyComponent"/>.
/// </summary>
[Serializable, NetSerializable]
public enum BodyPartType

View File

@@ -1,5 +1,4 @@
using Content.Shared.Body.Components;
using Robust.Shared.Serialization;
namespace Content.Shared.Body.Part
{
@@ -10,18 +9,16 @@ namespace Content.Shared.Body.Part
public interface IBodyPartAdded : IComponent
{
/// <summary>
/// Called when a <see cref="SharedBodyPartComponent"/> is added to the
/// Called when a <see cref="BodyComponent"/> is added to the
/// entity owning this component.
/// </summary>
/// <param name="args">Information about the part that was added.</param>
void BodyPartAdded(BodyPartAddedEventArgs args);
}
[Serializable, NetSerializable]
public sealed class BodyPartAddedEventArgs : EventArgs
{
public BodyPartAddedEventArgs(string slot, SharedBodyPartComponent part)
public BodyPartAddedEventArgs(string slot, BodyPartComponent part)
{
Slot = slot;
Part = part;
@@ -35,6 +32,6 @@ namespace Content.Shared.Body.Part
/// <summary>
/// The part that was added.
/// </summary>
public SharedBodyPartComponent Part { get; }
public BodyPartComponent Part { get; }
}
}

View File

@@ -1,5 +1,4 @@
using Content.Shared.Body.Components;
using Robust.Shared.Serialization;
namespace Content.Shared.Body.Part
{
@@ -10,17 +9,16 @@ namespace Content.Shared.Body.Part
public interface IBodyPartRemoved
{
/// <summary>
/// Called when a <see cref="SharedBodyPartComponent"/> is removed from the
/// Called when a <see cref="BodyComponent"/> is removed from the
/// entity owning this component.
/// </summary>
/// <param name="args">Information about the part that was removed.</param>
void BodyPartRemoved(BodyPartRemovedEventArgs args);
}
[Serializable, NetSerializable]
public sealed class BodyPartRemovedEventArgs : EventArgs
{
public BodyPartRemovedEventArgs(string slot, SharedBodyPartComponent part)
public BodyPartRemovedEventArgs(string slot, BodyPartComponent part)
{
Slot = slot;
Part = part;
@@ -34,6 +32,6 @@ namespace Content.Shared.Body.Part
/// <summary>
/// The part that was removed.
/// </summary>
public SharedBodyPartComponent Part { get; }
public BodyPartComponent Part { get; }
}
}