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

38 lines
1.1 KiB
C#

using Content.Shared.GameObjects.Components.Power;
using Robust.Server.GameObjects;
using Robust.Shared.GameObjects;
namespace Content.Server.GameObjects.Components.Power
{
/// <summary>
/// Batteries that have update an <see cref="AppearanceComponent"/> based on their charge percent.
/// </summary>
[RegisterComponent]
[ComponentReference(typeof(BatteryComponent))]
public class PowerCellComponent : BatteryComponent
{
public override string Name => "PowerCell";
private AppearanceComponent _appearance;
public override void Initialize()
{
base.Initialize();
_appearance = Owner.GetComponent<AppearanceComponent>();
CurrentCharge = MaxCharge;
UpdateVisuals();
}
protected override void OnChargeChanged()
{
base.OnChargeChanged();
UpdateVisuals();
}
private void UpdateVisuals()
{
_appearance?.SetData(PowerCellVisuals.ChargeLevel, CurrentCharge / MaxCharge);
}
}
}