BaseNetConnectorNodeGroup.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using Content.Server.NodeContainer.NodeGroups;
  2. using Content.Server.NodeContainer.Nodes;
  3. using Content.Server.Power.Components;
  4. namespace Content.Server.Power.NodeGroups
  5. {
  6. public abstract class BaseNetConnectorNodeGroup<TNetType> : BaseNodeGroup
  7. {
  8. protected IEntityManager EntMan = default!;
  9. public override void Initialize(Node sourceNode, IEntityManager entMan)
  10. {
  11. base.Initialize(sourceNode, entMan);
  12. EntMan = entMan;
  13. }
  14. public override void LoadNodes(List<Node> groupNodes)
  15. {
  16. base.LoadNodes(groupNodes);
  17. foreach (var node in groupNodes)
  18. {
  19. // TODO POWER PERFORMANCE
  20. // Replace this with TryComps or some other sane way of doing this, the current solution is awful.
  21. // This allocates an array, copies ALL of an entities components over, and then iterates over them to
  22. // yield any that implement the interface.
  23. foreach (var comp in EntMan.GetComponents<IBaseNetConnectorComponent<TNetType>>(node.Owner))
  24. {
  25. if ((comp.NodeId == null ||
  26. comp.NodeId == node.Name) &&
  27. (NodeGroupID) comp.Voltage == node.NodeGroupID)
  28. {
  29. SetNetConnectorNet(comp);
  30. }
  31. }
  32. }
  33. }
  34. protected abstract void SetNetConnectorNet(IBaseNetConnectorComponent<TNetType> netConnectorComponent);
  35. }
  36. }