From a679e691c25a521db04972c8e085b290dc0c5fa6 Mon Sep 17 00:00:00 2001 From: daniel-cr Date: Fri, 18 Dec 2020 01:31:58 -0600 Subject: [PATCH] Conveyor Belt appearance when power is off (#2762) * Conveyor Belt appearance when power is off If the conveyor belt is running and the power turns off the belt stops pushing things but the animation continues. This changes it so the animation stops if there is no power and resumes when it returns. * Change from using Initialize, to OnAdd and OnRemove --- .../Components/Conveyor/ConveyorComponent.cs | 45 ++++++++++++++++--- .../Specific/Conveyor/conveyor.yml | 2 +- 2 files changed, 40 insertions(+), 7 deletions(-) diff --git a/Content.Server/GameObjects/Components/Conveyor/ConveyorComponent.cs b/Content.Server/GameObjects/Components/Conveyor/ConveyorComponent.cs index 2d50e5c052..d6441ae935 100644 --- a/Content.Server/GameObjects/Components/Conveyor/ConveyorComponent.cs +++ b/Content.Server/GameObjects/Components/Conveyor/ConveyorComponent.cs @@ -1,4 +1,4 @@ -#nullable enable +#nullable enable using System.Threading.Tasks; using Content.Server.GameObjects.Components.Interactable; using Content.Server.GameObjects.Components.Items.Storage; @@ -28,6 +28,8 @@ namespace Content.Server.GameObjects.Components.Conveyor { public override string Name => "Conveyor"; + [ViewVariables] private bool Powered => !Owner.TryGetComponent(out PowerReceiverComponent? receiver) || receiver.Powered; + /// /// The angle to move entities by in relation to the owner's rotation. /// @@ -41,7 +43,6 @@ namespace Content.Server.GameObjects.Components.Conveyor private float _speed; private ConveyorState _state; - /// /// The current state of this conveyor /// @@ -52,13 +53,45 @@ namespace Content.Server.GameObjects.Components.Conveyor set { _state = value; + UpdateAppearance(); + } + } - if (!Owner.TryGetComponent(out AppearanceComponent? appearance)) + public override void OnAdd() + { + base.OnAdd(); + if (Owner.TryGetComponent(out PowerReceiverComponent? receiver)) + { + receiver.OnPowerStateChanged += OnPowerChanged; + } + } + + public override void OnRemove() + { + base.OnRemove(); + if (Owner.TryGetComponent(out PowerReceiverComponent? receiver)) + { + receiver.OnPowerStateChanged -= OnPowerChanged; + } + } + + private void OnPowerChanged(object? sender, PowerStateEventArgs e) + { + UpdateAppearance(); + } + + private void UpdateAppearance() + { + if (Owner.TryGetComponent(out var appearance)) + { + if (Powered) { - return; + appearance.SetData(ConveyorVisuals.State, _state); + } + else + { + appearance.SetData(ConveyorVisuals.State, ConveyorState.Off); } - - appearance.SetData(ConveyorVisuals.State, value); } } diff --git a/Resources/Prototypes/Entities/Constructible/Specific/Conveyor/conveyor.yml b/Resources/Prototypes/Entities/Constructible/Specific/Conveyor/conveyor.yml index 3a6e2f43bc..a456138250 100644 --- a/Resources/Prototypes/Entities/Constructible/Specific/Conveyor/conveyor.yml +++ b/Resources/Prototypes/Entities/Constructible/Specific/Conveyor/conveyor.yml @@ -27,6 +27,7 @@ drawdepth: FloorObjects - type: SignalReceiver maxTransmitters: 1 + - type: PowerReceiver - type: Conveyor - type: Appearance visuals: @@ -34,7 +35,6 @@ state_running: conveyor_started_cw state_stopped: conveyor_stopped_cw state_reversed: conveyor_started_cw_r - - type: PowerReceiver - type: Construction graph: ConveyorGraph node: entity