* Refactor battery/powercell assets and add new ones. * committing before I fuck things up * slot component doned I think * dictionary update * Fixes * Moving flashlight to powerslotcomponent * har har i am using the message tubes * Better documentation comment * Reverting this overengineered garbage. * Off with ye I said * Examine texts. * Some minor fixes to IDE complaints * slot size from yaml * Ignored component + removing a useless typo entry * Making stunbatons use this * Handle the message and remove some unnecessary dirtiness * actionblocker checks * remove unused file * remove updatevisual * make these nullable * make these nullable too * Unrename sprite folder * check itemcomponent on insertion * Use SendMessage over Owner.SendMessage * Add support for auto-recharging batteries, an auto-recharging cell, and make flashlight status update correctly if one is inserted in it. * get rid of public fields which are Bad * add a description for the stun baton while i'm in here * one more public field * Add the blinky animation to the atomic cell * Fix the charge indicator being STUPID * better comments * this is a better function * add pause for flashlight, remove unnecessary imports from battery * potato battery copyright link * WHO DID THAT * mr clean has come * Random pitch * pausing * round to nearest levels
68 lines
2.0 KiB
C#
68 lines
2.0 KiB
C#
using Content.Shared.GameObjects.Components.Power;
|
|
using Content.Shared.GameObjects.EntitySystems;
|
|
using Robust.Server.GameObjects;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.Localization;
|
|
using Robust.Shared.Serialization;
|
|
using Robust.Shared.Utility;
|
|
using Robust.Shared.ViewVariables;
|
|
|
|
namespace Content.Server.GameObjects.Components.Power
|
|
{
|
|
/// <summary>
|
|
/// Batteries that can update an <see cref="AppearanceComponent"/> based on their charge percent
|
|
/// and fit into a <see cref="PowerCellSlotComponent"/> of the appropriate size.
|
|
/// </summary>
|
|
[RegisterComponent]
|
|
[ComponentReference(typeof(BatteryComponent))]
|
|
public class PowerCellComponent : BatteryComponent, IExamine
|
|
{
|
|
public override string Name => "PowerCell";
|
|
|
|
[ViewVariables] public PowerCellSize CellSize => _cellSize;
|
|
private PowerCellSize _cellSize = PowerCellSize.Small;
|
|
|
|
public override void ExposeData(ObjectSerializer serializer)
|
|
{
|
|
base.ExposeData(serializer);
|
|
serializer.DataField(ref _cellSize, "cellSize", PowerCellSize.Small);
|
|
}
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
CurrentCharge = MaxCharge;
|
|
UpdateVisuals();
|
|
}
|
|
|
|
protected override void OnChargeChanged()
|
|
{
|
|
base.OnChargeChanged();
|
|
UpdateVisuals();
|
|
}
|
|
|
|
private void UpdateVisuals()
|
|
{
|
|
if (Owner.TryGetComponent(out AppearanceComponent appearance))
|
|
{
|
|
appearance.SetData(PowerCellVisuals.ChargeLevel, CurrentCharge / MaxCharge);
|
|
}
|
|
}
|
|
|
|
void IExamine.Examine(FormattedMessage message, bool inDetailsRange)
|
|
{
|
|
if(inDetailsRange)
|
|
{
|
|
message.AddMarkup(Loc.GetString($"The charge indicator reads {CurrentCharge / MaxCharge * 100:F0} %."));
|
|
}
|
|
}
|
|
}
|
|
|
|
public enum PowerCellSize
|
|
{
|
|
Small,
|
|
Medium,
|
|
Large
|
|
}
|
|
}
|