Add percentage reading to chargers (#28500)
* Add percentage reading to chargers * using args.pushgroup * change message * Update Content.Server/Power/EntitySystems/ChargerSystem.cs --------- Co-authored-by: plykiya <plykiya@protonmail.com> Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
This commit is contained in:
@@ -43,7 +43,34 @@ internal sealed class ChargerSystem : EntitySystem
|
||||
|
||||
private void OnChargerExamine(EntityUid uid, ChargerComponent component, ExaminedEvent args)
|
||||
{
|
||||
args.PushMarkup(Loc.GetString("charger-examine", ("color", "yellow"), ("chargeRate", (int) component.ChargeRate)));
|
||||
using (args.PushGroup(nameof(ChargerComponent)))
|
||||
{
|
||||
// rate at which the charger charges
|
||||
args.PushMarkup(Loc.GetString("charger-examine", ("color", "yellow"), ("chargeRate", (int) component.ChargeRate)));
|
||||
|
||||
// try to get contents of the charger
|
||||
if (!_container.TryGetContainer(uid, component.SlotId, out var container))
|
||||
return;
|
||||
|
||||
// if charger is empty and not a power cell type charger, add empty message
|
||||
// power cells have their own empty message by default, for things like flash lights
|
||||
if (container.ContainedEntities.Count == 0 && !HasComp<PowerCellSlotComponent>(uid))
|
||||
{
|
||||
args.PushMarkup(Loc.GetString("charger-empty"));
|
||||
}
|
||||
else
|
||||
{
|
||||
// add how much each item is charged it
|
||||
foreach (var contained in container.ContainedEntities)
|
||||
{
|
||||
if (!TryComp<BatteryComponent>(contained, out var battery))
|
||||
continue;
|
||||
|
||||
var chargePercentage = (battery.CurrentCharge / battery.MaxCharge) * 100;
|
||||
args.PushMarkup(Loc.GetString("charger-content", ("chargePercentage", (int) chargePercentage)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
|
||||
@@ -1,2 +1,4 @@
|
||||
charger-examine = Charges at [color={$color}]{$chargeRate}W[/color].
|
||||
charger-component-charge-rate = Charge rate
|
||||
charger-content = Current charge is at [color=#5E7C16]{$chargePercentage}[/color]%.
|
||||
charger-empty = There is nothing in the charger.
|
||||
|
||||
Reference in New Issue
Block a user