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
This commit is contained in:
daniel-cr
2020-12-18 01:31:58 -06:00
committed by GitHub
parent dc07718a7c
commit a679e691c2
2 changed files with 40 additions and 7 deletions

View File

@@ -1,4 +1,4 @@
#nullable enable #nullable enable
using System.Threading.Tasks; using System.Threading.Tasks;
using Content.Server.GameObjects.Components.Interactable; using Content.Server.GameObjects.Components.Interactable;
using Content.Server.GameObjects.Components.Items.Storage; using Content.Server.GameObjects.Components.Items.Storage;
@@ -28,6 +28,8 @@ namespace Content.Server.GameObjects.Components.Conveyor
{ {
public override string Name => "Conveyor"; public override string Name => "Conveyor";
[ViewVariables] private bool Powered => !Owner.TryGetComponent(out PowerReceiverComponent? receiver) || receiver.Powered;
/// <summary> /// <summary>
/// The angle to move entities by in relation to the owner's rotation. /// The angle to move entities by in relation to the owner's rotation.
/// </summary> /// </summary>
@@ -41,7 +43,6 @@ namespace Content.Server.GameObjects.Components.Conveyor
private float _speed; private float _speed;
private ConveyorState _state; private ConveyorState _state;
/// <summary> /// <summary>
/// The current state of this conveyor /// The current state of this conveyor
/// </summary> /// </summary>
@@ -52,13 +53,45 @@ namespace Content.Server.GameObjects.Components.Conveyor
set set
{ {
_state = value; _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<AppearanceComponent>(out var appearance))
{
if (Powered)
{ {
return; appearance.SetData(ConveyorVisuals.State, _state);
}
else
{
appearance.SetData(ConveyorVisuals.State, ConveyorState.Off);
} }
appearance.SetData(ConveyorVisuals.State, value);
} }
} }

View File

@@ -27,6 +27,7 @@
drawdepth: FloorObjects drawdepth: FloorObjects
- type: SignalReceiver - type: SignalReceiver
maxTransmitters: 1 maxTransmitters: 1
- type: PowerReceiver
- type: Conveyor - type: Conveyor
- type: Appearance - type: Appearance
visuals: visuals:
@@ -34,7 +35,6 @@
state_running: conveyor_started_cw state_running: conveyor_started_cw
state_stopped: conveyor_stopped_cw state_stopped: conveyor_stopped_cw
state_reversed: conveyor_started_cw_r state_reversed: conveyor_started_cw_r
- type: PowerReceiver
- type: Construction - type: Construction
graph: ConveyorGraph graph: ConveyorGraph
node: entity node: entity