From 56b2041b128cbad46106a178a643a356d5810980 Mon Sep 17 00:00:00 2001 From: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com> Date: Fri, 18 Feb 2022 10:31:23 +1300 Subject: [PATCH] Fix pipe connection bug (#6753) --- .../EntitySystems/NodeContainerSystem.cs | 9 ++++--- Content.Server/NodeContainer/Nodes/Node.cs | 4 +-- .../NodeContainer/Nodes/PipeNode.cs | 27 ++++++++++++++----- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/Content.Server/NodeContainer/EntitySystems/NodeContainerSystem.cs b/Content.Server/NodeContainer/EntitySystems/NodeContainerSystem.cs index b52468e1e0..01e3ac9f1b 100644 --- a/Content.Server/NodeContainer/EntitySystems/NodeContainerSystem.cs +++ b/Content.Server/NodeContainer/EntitySystems/NodeContainerSystem.cs @@ -61,6 +61,8 @@ namespace Content.Server.NodeContainer.EntitySystems if (!node.NeedAnchored) continue; + node.OnAnchorStateChanged(EntityManager, args.Anchored); + if (args.Anchored) _nodeGroupSystem.QueueReflood(node); else @@ -75,14 +77,15 @@ namespace Content.Server.NodeContainer.EntitySystems return; } - var anchored = Transform(uid).Anchored; + var xform = Transform(uid); foreach (var node in container.Nodes.Values) { - if (node.NeedAnchored && !anchored) + if (node is not IRotatableNode rotatableNode) continue; - if (node is not IRotatableNode rotatableNode) + // Don't bother updating nodes that can't even be connected to anything atm. + if (!node.Connectable(EntityManager, xform)) continue; if (rotatableNode.RotateEvent(ref ev)) diff --git a/Content.Server/NodeContainer/Nodes/Node.cs b/Content.Server/NodeContainer/Nodes/Node.cs index 4e4aee4f80..394489f085 100644 --- a/Content.Server/NodeContainer/Nodes/Node.cs +++ b/Content.Server/NodeContainer/Nodes/Node.cs @@ -52,12 +52,12 @@ namespace Content.Server.NodeContainer.Nodes return xform.Anchored; } - protected bool Anchored => !NeedAnchored || IoCManager.Resolve().GetComponent(Owner).Anchored; - [ViewVariables(VVAccess.ReadWrite)] [DataField("needAnchored")] public bool NeedAnchored { get; } = true; + public virtual void OnAnchorStateChanged(IEntityManager entityManager, bool anchored) { } + /// /// Prevents a node from being used by other nodes while midway through removal. /// diff --git a/Content.Server/NodeContainer/Nodes/PipeNode.cs b/Content.Server/NodeContainer/Nodes/PipeNode.cs index f01b6dcc8c..dcc6652180 100644 --- a/Content.Server/NodeContainer/Nodes/PipeNode.cs +++ b/Content.Server/NodeContainer/Nodes/PipeNode.cs @@ -133,14 +133,29 @@ namespace Content.Server.NodeContainer.Nodes return false; CurrentPipeDirection = _originalPipeDirection; - } - else - { - CurrentPipeDirection = _originalPipeDirection.RotatePipeDirection(ev.NewRotation); + return true; } - // node connections need to be updated - return true; + var oldDirection = CurrentPipeDirection; + CurrentPipeDirection = _originalPipeDirection.RotatePipeDirection(ev.NewRotation); + return oldDirection != CurrentPipeDirection; + } + + public override void OnAnchorStateChanged(IEntityManager entityManager, bool anchored) + { + if (!anchored) + return; + + // update valid pipe directions + + if (!RotationsEnabled) + { + CurrentPipeDirection = _originalPipeDirection; + return; + } + + var xform = entityManager.GetComponent(Owner); + CurrentPipeDirection = _originalPipeDirection.RotatePipeDirection(xform.LocalRotation); } public override IEnumerable GetReachableNodes(TransformComponent xform,