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