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