Remove IoC resolves in BaseNetConnectorNodeGroup and friends (#20333)

This commit is contained in:
Leon Friedrich
2023-09-20 00:44:49 +12:00
committed by GitHub
parent 39af74e0a3
commit 86fa8ae180
6 changed files with 53 additions and 50 deletions

View File

@@ -6,29 +6,33 @@ namespace Content.Server.Power.NodeGroups
{
public abstract class BaseNetConnectorNodeGroup<TNetType> : BaseNodeGroup
{
protected IEntityManager EntMan = default!;
public override void Initialize(Node sourceNode, IEntityManager entMan)
{
base.Initialize(sourceNode, entMan);
EntMan = entMan;
}
public override void LoadNodes(List<Node> groupNodes)
{
base.LoadNodes(groupNodes);
var entManager = IoCManager.Resolve<IEntityManager>();
foreach (var node in groupNodes)
{
var newNetConnectorComponents = new List<IBaseNetConnectorComponent<TNetType>>();
foreach (var comp in entManager.GetComponents<IBaseNetConnectorComponent<TNetType>>(node.Owner))
// TODO POWER PERFORMANCE
// Replace this with TryComps or some other sane way of doing this, the current solution is awful.
// This allocates an array, copies ALL of an entities components over, and then iterates over them to
// yield any that implement the interface.
foreach (var comp in EntMan.GetComponents<IBaseNetConnectorComponent<TNetType>>(node.Owner))
{
if ((comp.NodeId == null ||
comp.NodeId == node.Name) &&
(NodeGroupID) comp.Voltage == node.NodeGroupID)
{
newNetConnectorComponents.Add(comp);
SetNetConnectorNet(comp);
}
}
foreach (var netConnector in newNetConnectorComponents)
{
SetNetConnectorNet(netConnector);
}
}
}