Replaces PowerReceiver's C# event with a ComponentMessage (#2888)
Co-authored-by: py01 <pyronetics01@gmail.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
#nullable enable
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Server.GameObjects.Components.GUI;
|
||||
@@ -53,19 +53,21 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece
|
||||
Owner.EnsureComponent<PowerReceiverComponent>();
|
||||
_container = ContainerManagerComponent.Ensure<ContainerSlot>($"{Name}-powerCellContainer", Owner);
|
||||
// Default state in the visualizer is OFF, so when this gets powered on during initialization it will generally show empty
|
||||
if (Owner.TryGetComponent(out PowerReceiverComponent? receiver))
|
||||
}
|
||||
|
||||
public override void HandleMessage(ComponentMessage message, IComponent? component)
|
||||
{
|
||||
base.HandleMessage(message, component);
|
||||
switch (message)
|
||||
{
|
||||
receiver.OnPowerStateChanged += PowerUpdate;
|
||||
case PowerChangedMessage powerChanged:
|
||||
PowerUpdate(powerChanged);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnRemove()
|
||||
{
|
||||
if (Owner.TryGetComponent(out PowerReceiverComponent? receiver))
|
||||
{
|
||||
receiver.OnPowerStateChanged -= PowerUpdate;
|
||||
}
|
||||
|
||||
_heldBattery = null;
|
||||
|
||||
base.OnRemove();
|
||||
@@ -114,7 +116,7 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece
|
||||
UpdateStatus();
|
||||
}
|
||||
|
||||
private void PowerUpdate(object? sender, PowerStateEventArgs eventArgs)
|
||||
private void PowerUpdate(PowerChangedMessage eventArgs)
|
||||
{
|
||||
UpdateStatus();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user