using Content.Shared.Body.Components; namespace Content.Shared.Body.Part { public sealed class BodyPartSlot { public BodyPartSlot(string id, BodyPartType partType, IEnumerable connections) { Id = id; PartType = partType; Connections = new HashSet(connections); } public BodyPartSlot(string id, BodyPartType partType) { Id = id; PartType = partType; Connections = new HashSet(); } /// /// The ID of this slot. /// [ViewVariables] public string Id { get; } /// /// The part type that this slot accepts. /// [ViewVariables] public BodyPartType PartType { get; } /// /// The part currently in this slot, if any. /// [ViewVariables] public SharedBodyPartComponent? Part { get; private set; } /// /// List of slots that this slot connects to. /// [ViewVariables] public HashSet Connections { get; private set; } public event Action? PartAdded; public event Action? PartRemoved; internal void SetConnectionsInternal(IEnumerable connections) { Connections = new HashSet(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; } } }