1
0

BaseNodeGroup.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. using System.Linq;
  2. using Content.Server.NodeContainer.Nodes;
  3. using Robust.Shared.Map;
  4. using Robust.Shared.Utility;
  5. namespace Content.Server.NodeContainer.NodeGroups
  6. {
  7. /// <summary>
  8. /// Maintains a collection of <see cref="Node"/>s, and performs operations requiring a list of
  9. /// all connected <see cref="Node"/>s.
  10. /// </summary>
  11. public interface INodeGroup
  12. {
  13. bool Remaking { get; }
  14. /// <summary>
  15. /// The list of nodes currently in this group.
  16. /// </summary>
  17. IReadOnlyList<Node> Nodes { get; }
  18. void Create(NodeGroupID groupId);
  19. void Initialize(Node sourceNode, IEntityManager entMan);
  20. void RemoveNode(Node node);
  21. void LoadNodes(List<Node> groupNodes);
  22. // In theory, the SS13 curse ensures this method will never be called.
  23. void AfterRemake(IEnumerable<IGrouping<INodeGroup?, Node>> newGroups);
  24. /// <summary>
  25. /// Return any additional data to display for the node-visualizer debug overlay.
  26. /// </summary>
  27. string? GetDebugData();
  28. }
  29. [NodeGroup(NodeGroupID.Default, NodeGroupID.WireNet)]
  30. [Virtual]
  31. public class BaseNodeGroup : INodeGroup
  32. {
  33. public bool Remaking { get; set; }
  34. IReadOnlyList<Node> INodeGroup.Nodes => Nodes;
  35. /// <summary>
  36. /// The list of nodes in this group.
  37. /// </summary>
  38. [ViewVariables] public readonly List<Node> Nodes = new();
  39. [ViewVariables] public int NodeCount => Nodes.Count;
  40. /// <summary>
  41. /// Debug variable to indicate that this NodeGroup should not be being used by anything.
  42. /// </summary>
  43. [ViewVariables]
  44. public bool Removed { get; set; } = false;
  45. /// <summary>
  46. /// Network ID of this group for client-side debug visualization of nodes.
  47. /// </summary>
  48. [ViewVariables]
  49. public int NetId;
  50. [ViewVariables]
  51. public NodeGroupID GroupId { get; private set; }
  52. public void Create(NodeGroupID groupId)
  53. {
  54. GroupId = groupId;
  55. }
  56. public virtual void Initialize(Node sourceNode, IEntityManager entMan)
  57. {
  58. }
  59. /// <summary>
  60. /// Called when a node has been removed from this group via deletion of the node.
  61. /// </summary>
  62. /// <remarks>
  63. /// Note that this always still results in a complete remake of the group later,
  64. /// but hooking this method is good for book keeping.
  65. /// </remarks>
  66. /// <param name="node">The node that was deleted.</param>
  67. public virtual void RemoveNode(Node node)
  68. {
  69. }
  70. /// <summary>
  71. /// Called to load this newly created group up with new nodes.
  72. /// </summary>
  73. /// <param name="groupNodes">The new nodes for this group.</param>
  74. public virtual void LoadNodes(
  75. List<Node> groupNodes)
  76. {
  77. Nodes.AddRange(groupNodes);
  78. }
  79. /// <summary>
  80. /// Called after the nodes in this group have been made into one or more new groups.
  81. /// </summary>
  82. /// <remarks>
  83. /// Use this to split in-group data such as pipe gas mixtures into newly split nodes.
  84. /// </remarks>
  85. /// <param name="newGroups">A list of new groups for this group's former nodes.</param>
  86. public virtual void AfterRemake(IEnumerable<IGrouping<INodeGroup?, Node>> newGroups) { }
  87. public virtual string? GetDebugData()
  88. {
  89. return null;
  90. }
  91. }
  92. }