using System.Linq; using Content.Server.NodeContainer.Nodes; using Robust.Shared.Map; using Robust.Shared.Utility; namespace Content.Server.NodeContainer.NodeGroups { /// /// Maintains a collection of s, and performs operations requiring a list of /// all connected s. /// public interface INodeGroup { bool Remaking { get; } /// /// The list of nodes currently in this group. /// IReadOnlyList Nodes { get; } void Create(NodeGroupID groupId); void Initialize(Node sourceNode, IEntityManager? entMan = null); void RemoveNode(Node node); void LoadNodes(List groupNodes); // In theory, the SS13 curse ensures this method will never be called. void AfterRemake(IEnumerable> newGroups); /// /// Return any additional data to display for the node-visualizer debug overlay. /// string? GetDebugData(); } [NodeGroup(NodeGroupID.Default, NodeGroupID.WireNet)] [Virtual] public class BaseNodeGroup : INodeGroup { public bool Remaking { get; set; } IReadOnlyList INodeGroup.Nodes => Nodes; /// /// The list of nodes in this group. /// [ViewVariables] public readonly List Nodes = new(); [ViewVariables] public int NodeCount => Nodes.Count; /// /// Debug variable to indicate that this NodeGroup should not be being used by anything. /// [ViewVariables] public bool Removed { get; set; } = false; [ViewVariables] protected EntityUid GridId { get; private set; } /// /// Network ID of this group for client-side debug visualization of nodes. /// [ViewVariables] public int NetId; [ViewVariables] public NodeGroupID GroupId { get; private set; } public void Create(NodeGroupID groupId) { GroupId = groupId; } public virtual void Initialize(Node sourceNode, IEntityManager? entMan = null) { // TODO: Can we get rid of this GridId? IoCManager.Resolve(ref entMan); var xform = entMan.GetComponent(sourceNode.Owner); DebugTools.AssertNotNull(xform.GridUid); GridId = xform.GridUid!.Value; } /// /// Called when a node has been removed from this group via deletion of the node. /// /// /// Note that this always still results in a complete remake of the group later, /// but hooking this method is good for book keeping. /// /// The node that was deleted. public virtual void RemoveNode(Node node) { } /// /// Called to load this newly created group up with new nodes. /// /// The new nodes for this group. public virtual void LoadNodes( List groupNodes) { Nodes.AddRange(groupNodes); } /// /// Called after the nodes in this group have been made into one or more new groups. /// /// /// Use this to split in-group data such as pipe gas mixtures into newly split nodes. /// /// A list of new groups for this group's former nodes. public virtual void AfterRemake(IEnumerable> newGroups) { } public virtual string? GetDebugData() { return null; } } }