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,10 +1,11 @@
using Content.Server.GameObjects.Components.Power.ApcNetComponents;
using Content.Server.GameObjects.Components.Power.ApcNetComponents;
using Content.Shared.GameObjects.Components;
using JetBrains.Annotations;
using Robust.Server.GameObjects;
using Robust.Server.GameObjects.Components.Container;
using Robust.Server.Interfaces.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Log;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
@@ -29,8 +30,6 @@ namespace Content.Server.GameObjects.Components
if (Owner.TryGetComponent(out PowerReceiverComponent powerReceiver))
{
powerReceiver.OnPowerStateChanged += PowerReceiverOnOnPowerStateChanged;
if (Owner.TryGetComponent(out AppearanceComponent appearance))
{
appearance.SetData(ComputerVisuals.Powered, powerReceiver.Powered);
@@ -45,17 +44,18 @@ namespace Content.Server.GameObjects.Components
CreateComputerBoard();
}
public override void OnRemove()
public override void HandleMessage(ComponentMessage message, IComponent component)
{
if (Owner.TryGetComponent(out PowerReceiverComponent powerReceiver))
base.HandleMessage(message, component);
switch (message)
{
powerReceiver.OnPowerStateChanged -= PowerReceiverOnOnPowerStateChanged;
case PowerChangedMessage powerChanged:
PowerReceiverOnOnPowerStateChanged(powerChanged);
break;
}
base.OnRemove();
}
private void PowerReceiverOnOnPowerStateChanged(object sender, PowerStateEventArgs e)
private void PowerReceiverOnOnPowerStateChanged(PowerChangedMessage e)
{
if (Owner.TryGetComponent(out AppearanceComponent appearance))
{