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.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -119,24 +119,24 @@ namespace Content.Server.GameObjects.Components.VendingMachines
|
||||
|
||||
if (Owner.TryGetComponent(out PowerReceiverComponent? receiver))
|
||||
{
|
||||
receiver.OnPowerStateChanged += UpdatePower;
|
||||
TrySetVisualState(receiver.Powered ? VendingMachineVisualState.Normal : VendingMachineVisualState.Off);
|
||||
}
|
||||
|
||||
InitializeFromPrototype();
|
||||
}
|
||||
|
||||
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 -= UpdatePower;
|
||||
case PowerChangedMessage powerChanged:
|
||||
UpdatePower(powerChanged);
|
||||
break;
|
||||
}
|
||||
|
||||
base.OnRemove();
|
||||
}
|
||||
|
||||
private void UpdatePower(object? sender, PowerStateEventArgs args)
|
||||
private void UpdatePower(PowerChangedMessage args)
|
||||
{
|
||||
var state = args.Powered ? VendingMachineVisualState.Normal : VendingMachineVisualState.Off;
|
||||
TrySetVisualState(state);
|
||||
|
||||
Reference in New Issue
Block a user