From 9926ef298c46832c794546e879b910dcceededf5 Mon Sep 17 00:00:00 2001 From: DrSmugleaf Date: Fri, 6 Nov 2020 12:52:01 +0100 Subject: [PATCH] Move rotate event subscription from NodeContainerComponent to NodeContainerSystem (#2506) --- .../NodeContainer/NodeContainerComponent.cs | 16 ------- .../EntitySystems/NodeContainerSystem.cs | 45 +++++++++++++++++++ 2 files changed, 45 insertions(+), 16 deletions(-) create mode 100644 Content.Server/GameObjects/EntitySystems/NodeContainerSystem.cs diff --git a/Content.Server/GameObjects/Components/NodeContainer/NodeContainerComponent.cs b/Content.Server/GameObjects/Components/NodeContainer/NodeContainerComponent.cs index de72f5b58e..23a2d1be45 100644 --- a/Content.Server/GameObjects/Components/NodeContainer/NodeContainerComponent.cs +++ b/Content.Server/GameObjects/Components/NodeContainer/NodeContainerComponent.cs @@ -1,9 +1,6 @@ using System.Collections.Generic; -using System.Linq; using Content.Server.GameObjects.Components.NodeContainer.Nodes; using Robust.Shared.GameObjects; -using Robust.Shared.GameObjects.Components.Transform; -using Robust.Shared.Maths; using Robust.Shared.Serialization; using Robust.Shared.ViewVariables; @@ -34,8 +31,6 @@ namespace Content.Server.GameObjects.Components.NodeContainer { node.Initialize(Owner); } - - Owner.EntityManager.EventBus.SubscribeEvent(EventSource.Local, this, RotateEvent); } protected override void Startup() @@ -55,16 +50,5 @@ namespace Content.Server.GameObjects.Components.NodeContainer } base.OnRemove(); } - - private void RotateEvent(RotateEvent ev) - { - if (ev.Sender != Owner || ev.NewRotation == ev.OldRotation) - return; - - foreach (var rotatableNode in Nodes.OfType()) - { - rotatableNode.RotateEvent(ev); - } - } } } diff --git a/Content.Server/GameObjects/EntitySystems/NodeContainerSystem.cs b/Content.Server/GameObjects/EntitySystems/NodeContainerSystem.cs new file mode 100644 index 0000000000..2c60a40bed --- /dev/null +++ b/Content.Server/GameObjects/EntitySystems/NodeContainerSystem.cs @@ -0,0 +1,45 @@ +using System.Linq; +using Content.Server.GameObjects.Components.NodeContainer; +using Content.Server.GameObjects.Components.NodeContainer.Nodes; +using JetBrains.Annotations; +using Robust.Shared.GameObjects.Components.Transform; +using Robust.Shared.GameObjects.Systems; + +namespace Content.Server.GameObjects.EntitySystems +{ + [UsedImplicitly] + public class NodeContainerSystem : EntitySystem + { + public override void Initialize() + { + base.Initialize(); + + SubscribeLocalEvent(RotateEvent); + } + + public override void Shutdown() + { + base.Shutdown(); + + UnsubscribeLocalEvent(); + } + + private void RotateEvent(RotateEvent ev) + { + if (!ev.Sender.TryGetComponent(out NodeContainerComponent container)) + { + return; + } + + if (ev.NewRotation == ev.OldRotation) + { + return; + } + + foreach (var rotatableNode in container.Nodes.OfType()) + { + rotatableNode.RotateEvent(ev); + } + } + } +}