Update PowerChangedEvent (#7503)

* Update PowerChangedEvent

* Comments
This commit is contained in:
Leon Friedrich
2022-04-14 01:50:42 +12:00
committed by GitHub
parent f440006ed9
commit 2777d2ef64
3 changed files with 24 additions and 31 deletions

View File

@@ -1,6 +1,5 @@
using Content.Server.Power.NodeGroups;
using Content.Server.Power.Pow3r;
using Content.Shared.Power;
namespace Content.Server.Power.Components
{
@@ -11,8 +10,6 @@ namespace Content.Server.Power.Components
[RegisterComponent]
public sealed class ApcPowerReceiverComponent : Component
{
[Dependency] private readonly IEntityManager _entMan = default!;
[ViewVariables]
public bool Powered => (MathHelper.CloseToPercent(NetworkLoad.ReceivingPower, Load) || !NeedsPower) && !PowerDisabled;
@@ -36,7 +33,7 @@ namespace Content.Server.Power.Components
{
_needsPower = value;
// Reset this so next tick will do a power update.
LastPowerReceived = float.NaN;
PoweredLastUpdate = null;
}
}
@@ -50,7 +47,7 @@ namespace Content.Server.Power.Components
[DataField("powerDisabled")]
public bool PowerDisabled { get => !NetworkLoad.Enabled; set => NetworkLoad.Enabled = !value; }
public float LastPowerReceived = float.NaN;
public bool? PoweredLastUpdate;
[ViewVariables]
public PowerState.Load NetworkLoad { get; } = new PowerState.Load
@@ -66,16 +63,6 @@ namespace Content.Server.Power.Components
base.OnRemove();
}
public void ApcPowerChanged()
{
_entMan.EventBus.RaiseLocalEvent(Owner, new PowerChangedEvent(Powered, NetworkLoad.ReceivingPower));
if (_entMan.TryGetComponent<AppearanceComponent?>(Owner, out var appearance))
{
appearance.SetData(PowerDeviceVisuals.Powered, Powered);
}
}
}
/// <summary>