Files
OldThink/Content.Server/GameObjects/Components/Power/PowerCellComponent.cs

38 lines
1.1 KiB
C#
Raw Normal View History

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