Removes some linq from power (#2875)
* PowerProviderComponent Linq removal * AdjacentNode Linq removal * PipeNode Linq removal * Replaces HasFlag usage in PipeNode Co-authored-by: py01 <pyronetics01@gmail.com>
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using Robust.Shared.GameObjects.Components.Transform;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.NodeContainer.Nodes
|
||||
@@ -11,13 +10,25 @@ namespace Content.Server.GameObjects.Components.NodeContainer.Nodes
|
||||
{
|
||||
protected override IEnumerable<Node> GetReachableNodes()
|
||||
{
|
||||
return Owner.GetComponent<SnapGridComponent>()
|
||||
.GetCardinalNeighborCells()
|
||||
.SelectMany(sgc => sgc.GetLocal())
|
||||
.Select(entity => entity.TryGetComponent<NodeContainerComponent>(out var container) ? container : null)
|
||||
.Where(container => container != null)
|
||||
.SelectMany(container => container.Nodes)
|
||||
.Where(node => node != null && node != this);
|
||||
var cells = Owner.GetComponent<SnapGridComponent>()
|
||||
.GetCardinalNeighborCells();
|
||||
|
||||
foreach (var cell in cells)
|
||||
{
|
||||
foreach (var entity in cell.GetLocal())
|
||||
{
|
||||
if (entity.TryGetComponent<NodeContainerComponent>(out var container))
|
||||
{
|
||||
foreach (var node in container.Nodes)
|
||||
{
|
||||
if (node != null && node != this)
|
||||
{
|
||||
yield return node;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Content.Server.Atmos;
|
||||
using Content.Server.GameObjects.Components.NodeContainer.NodeGroups;
|
||||
using Content.Server.Interfaces;
|
||||
@@ -107,17 +105,30 @@ namespace Content.Server.GameObjects.Components.NodeContainer.Nodes
|
||||
|
||||
var ownNeededConnection = pipeDirection;
|
||||
var theirNeededConnection = ownNeededConnection.GetOpposite();
|
||||
if (!_pipeDirection.HasFlag(ownNeededConnection))
|
||||
if (!_pipeDirection.HasDirection(ownNeededConnection))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var pipeNodesInDirection = Owner.GetComponent<SnapGridComponent>()
|
||||
.GetInDir(pipeDirection.ToDirection())
|
||||
.Select(entity => entity.TryGetComponent<NodeContainerComponent>(out var container) ? container : null)
|
||||
.Where(container => container != null)
|
||||
.SelectMany(container => container.Nodes)
|
||||
.OfType<PipeNode>()
|
||||
.Where(pipeNode => pipeNode._pipeDirection.HasFlag(theirNeededConnection));
|
||||
|
||||
var pipeNodesInDirection = new List<PipeNode>();
|
||||
|
||||
var entities = Owner.GetComponent<SnapGridComponent>()
|
||||
.GetInDir(pipeDirection.ToDirection());
|
||||
|
||||
foreach (var entity in entities)
|
||||
{
|
||||
if (entity.TryGetComponent<NodeContainerComponent>(out var container))
|
||||
{
|
||||
foreach (var node in container.Nodes)
|
||||
{
|
||||
if (node is PipeNode pipeNode && pipeNode._pipeDirection.HasDirection(theirNeededConnection))
|
||||
{
|
||||
pipeNodesInDirection.Add(pipeNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var pipeNode in pipeNodesInDirection)
|
||||
{
|
||||
yield return pipeNode;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Content.Server.GameObjects.Components.NodeContainer.NodeGroups;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
@@ -109,12 +108,21 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents
|
||||
{
|
||||
var nearbyEntities = Owner.EntityManager
|
||||
.GetEntitiesInRange(Owner, PowerTransferRange);
|
||||
return nearbyEntities.Select(entity => entity.TryGetComponent<PowerReceiverComponent>(out var receiver) ? receiver : null)
|
||||
.Where(receiver => receiver != null)
|
||||
.Where(receiver => receiver.Connectable)
|
||||
.Where(receiver => receiver.NeedsProvider)
|
||||
.Where(receiver => receiver.Owner.Transform.Coordinates.TryDistance(Owner.EntityManager, Owner.Transform.Coordinates, out var distance) && distance < Math.Min(PowerTransferRange, receiver.PowerReceptionRange))
|
||||
.ToList();
|
||||
|
||||
var receivers = new List<PowerReceiverComponent>();
|
||||
|
||||
foreach (var entity in nearbyEntities)
|
||||
{
|
||||
if (entity.TryGetComponent<PowerReceiverComponent>(out var receiver) &&
|
||||
receiver.Connectable &&
|
||||
receiver.NeedsProvider &&
|
||||
receiver.Owner.Transform.Coordinates.TryDistance(Owner.EntityManager, Owner.Transform.Coordinates, out var distance) &&
|
||||
distance < Math.Min(PowerTransferRange, receiver.PowerReceptionRange))
|
||||
{
|
||||
receivers.Add(receiver);
|
||||
}
|
||||
}
|
||||
return receivers;
|
||||
}
|
||||
|
||||
protected override void AddSelfToNet(IApcNet apcNet)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using System;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Serialization;
|
||||
using System;
|
||||
|
||||
namespace Content.Shared.GameObjects.Components.Atmos
|
||||
{
|
||||
@@ -76,6 +76,11 @@ namespace Content.Shared.GameObjects.Components.Atmos
|
||||
{
|
||||
public const int PipeDirections = 4;
|
||||
|
||||
public static bool HasDirection(this PipeDirection pipeDirection, PipeDirection other)
|
||||
{
|
||||
return (pipeDirection & other) == other;
|
||||
}
|
||||
|
||||
public static Angle ToAngle(this PipeDirection pipeDirection)
|
||||
{
|
||||
return pipeDirection switch
|
||||
|
||||
Reference in New Issue
Block a user