diff --git a/Content.Server/Atmos/Piping/Binary/Components/GasValveComponent.cs b/Content.Server/Atmos/Piping/Binary/Components/GasValveComponent.cs index 7a20b63509..61fccc8877 100644 --- a/Content.Server/Atmos/Piping/Binary/Components/GasValveComponent.cs +++ b/Content.Server/Atmos/Piping/Binary/Components/GasValveComponent.cs @@ -1,55 +1,21 @@ -using Content.Server.NodeContainer; -using Content.Server.NodeContainer.Nodes; -using Content.Shared.ActionBlocker; using Content.Shared.Interaction; -using Content.Shared.Interaction.Helpers; using Robust.Shared.GameObjects; using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Server.Atmos.Piping.Binary.Components { - // TODO ATMOS: Make ECS. - [ComponentReference(typeof(IActivate))] [RegisterComponent] - public class GasValveComponent : Component, IActivate + public class GasValveComponent : Component { public override string Name => "GasValve"; [ViewVariables] [DataField("open")] - private bool _open = true; + public bool Open { get; set; } = true; [DataField("pipe")] [ViewVariables(VVAccess.ReadWrite)] - private string _pipeName = "pipe"; - - protected override void Startup() - { - base.Startup(); - - Set(); - } - - private void Set() - { - if (Owner.TryGetComponent(out NodeContainerComponent? nodeContainer) - && nodeContainer.TryGetNode(_pipeName, out PipeNode? pipe)) - { - pipe.ConnectionsEnabled = _open; - } - } - - private void Toggle() - { - _open = !_open; - Set(); - } - - void IActivate.Activate(ActivateEventArgs eventArgs) - { - if(eventArgs.InRangeUnobstructed() && EntitySystem.Get().CanInteract(eventArgs.User)) - Toggle(); - } + public string PipeName { get; } = "pipe"; } } diff --git a/Content.Server/Atmos/Piping/Binary/EntitySystems/GasValveSystem.cs b/Content.Server/Atmos/Piping/Binary/EntitySystems/GasValveSystem.cs new file mode 100644 index 0000000000..69c1ef362c --- /dev/null +++ b/Content.Server/Atmos/Piping/Binary/EntitySystems/GasValveSystem.cs @@ -0,0 +1,53 @@ +using Content.Server.Atmos.Piping.Binary.Components; +using Content.Server.NodeContainer; +using Content.Server.NodeContainer.Nodes; +using Content.Shared.ActionBlocker; +using Content.Shared.Atmos.Piping; +using Content.Shared.Interaction; +using Content.Shared.Interaction.Helpers; +using JetBrains.Annotations; +using Robust.Server.GameObjects; +using Robust.Shared.GameObjects; + +namespace Content.Server.Atmos.Piping.Binary.EntitySystems +{ + [UsedImplicitly] + public class GasValveSystem : EntitySystem + { + public override void Initialize() + { + base.Initialize(); + + SubscribeLocalEvent(OnStartup); + SubscribeLocalEvent(OnActivate); + } + + private void OnStartup(EntityUid uid, GasValveComponent component, ComponentStartup args) + { + // We call set in startup so it sets the appearance, node state, etc. + Set(uid, component, component.Open); + } + + private void OnActivate(EntityUid uid, GasValveComponent component, ActivateInWorldEvent args) + { + if(args.User.InRangeUnobstructed(args.Target) && Get().CanInteract(args.User)) + Toggle(uid, component); + } + + public void Set(EntityUid uid, GasValveComponent component, bool value) + { + component.Open = value; + + if (ComponentManager.TryGetComponent(uid, out NodeContainerComponent? nodeContainer) + && nodeContainer.TryGetNode(component.PipeName, out PipeNode? pipe)) + { + pipe.ConnectionsEnabled = component.Open; + } + } + + public void Toggle(EntityUid uid, GasValveComponent component) + { + Set(uid, component, !component.Open); + } + } +}