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

@@ -1,4 +1,4 @@
#nullable enable
#nullable enable
using System;
using System.Threading;
using System.Threading.Tasks;
@@ -15,6 +15,7 @@ using Robust.Server.Interfaces.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components.Timers;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Localization;
using Robust.Shared.Maths;
using Robust.Shared.ViewVariables;
@@ -191,8 +192,6 @@ namespace Content.Server.GameObjects.Components.Doors
if (Owner.TryGetComponent(out PowerReceiverComponent? receiver))
{
receiver.OnPowerStateChanged += PowerDeviceOnOnPowerStateChanged;
if (Owner.TryGetComponent(out AppearanceComponent? appearance))
{
@@ -201,17 +200,18 @@ namespace Content.Server.GameObjects.Components.Doors
}
}
public override void OnRemove()
public override void HandleMessage(ComponentMessage message, IComponent? component)
{
if (Owner.TryGetComponent(out PowerReceiverComponent? receiver))
base.HandleMessage(message, component);
switch (message)
{
receiver.OnPowerStateChanged -= PowerDeviceOnOnPowerStateChanged;
case PowerChangedMessage powerChanged:
PowerDeviceOnOnPowerStateChanged(powerChanged);
break;
}
base.OnRemove();
}
private void PowerDeviceOnOnPowerStateChanged(object? sender, PowerStateEventArgs e)
private void PowerDeviceOnOnPowerStateChanged(PowerChangedMessage e)
{
if (Owner.TryGetComponent(out AppearanceComponent? appearance))
{