Replaces PowerReceiver's C# event with a ComponentMessage (#2888)

Co-authored-by: py01 <pyronetics01@gmail.com>
This commit is contained in:
py01
2021-01-03 09:13:01 -06:00
committed by GitHub
parent 914a214a19
commit 32f04fd7ca
19 changed files with 182 additions and 181 deletions

View File

@@ -8,6 +8,7 @@ using Robust.Shared.Audio;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components.Timers;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.GameObjects;
using System.Collections.Generic;
namespace Content.Server.GameObjects.Components.Cargo
@@ -25,22 +26,15 @@ namespace Content.Server.GameObjects.Components.Cargo
private List<CargoProductPrototype> _teleportQueue = new List<CargoProductPrototype>();
private CargoTelepadState _currentState = CargoTelepadState.Unpowered;
public override void OnAdd()
public override void HandleMessage(ComponentMessage message, IComponent? component)
{
base.OnAdd();
var receiver = Owner.EnsureComponent<PowerReceiverComponent>();
receiver.OnPowerStateChanged += PowerUpdate;
}
public override void OnRemove()
{
if (Owner.TryGetComponent(out PowerReceiverComponent? receiver))
base.HandleMessage(message, component);
switch (message)
{
receiver.OnPowerStateChanged -= PowerUpdate;
case PowerChangedMessage powerChanged:
PowerUpdate(powerChanged);
break;
}
base.OnRemove();
}
public void QueueTeleport(CargoProductPrototype product)
@@ -49,7 +43,7 @@ namespace Content.Server.GameObjects.Components.Cargo
TeleportLoop();
}
private void PowerUpdate(object? sender, PowerStateEventArgs args)
private void PowerUpdate(PowerChangedMessage args)
{
if (args.Powered && _currentState == CargoTelepadState.Unpowered) {
_currentState = CargoTelepadState.Idle;