Files
tbd-station-14/Content.Server/GameObjects/Components/ComputerComponent.cs
py01 23cc6b1d4e Power Rework (#863)
Co-authored-by: py01 <pyronetics01@gmail.com>
2020-06-28 17:23:26 +02:00

45 lines
1.4 KiB
C#

using Content.Server.GameObjects.Components.Power.ApcNetComponents;
using Content.Shared.GameObjects.Components;
using Robust.Server.GameObjects;
using Robust.Shared.GameObjects;
namespace Content.Server.GameObjects.Components
{
[RegisterComponent]
public sealed class ComputerComponent : SharedComputerComponent
{
public override void Initialize()
{
base.Initialize();
if (Owner.TryGetComponent(out PowerReceiverComponent powerReceiver))
{
powerReceiver.OnPowerStateChanged += PowerReceiverOnOnPowerStateChanged;
if (Owner.TryGetComponent(out AppearanceComponent appearance))
{
appearance.SetData(ComputerVisuals.Powered, powerReceiver.Powered);
}
}
}
public override void OnRemove()
{
if (Owner.TryGetComponent(out PowerReceiverComponent powerReceiver))
{
powerReceiver.OnPowerStateChanged -= PowerReceiverOnOnPowerStateChanged;
}
base.OnRemove();
}
private void PowerReceiverOnOnPowerStateChanged(object sender, PowerStateEventArgs e)
{
if (Owner.TryGetComponent(out AppearanceComponent appearance))
{
appearance.SetData(ComputerVisuals.Powered, e.Powered);
}
}
}
}