Files
OldThink/Content.Server/Power/Components/ExaminableBatteryComponent.cs

39 lines
1.3 KiB
C#
Raw Normal View History

2021-06-09 22:19:39 +02:00
using Content.Shared.Examine;
using Robust.Shared.GameObjects;
2022-01-15 03:26:37 +01:00
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Utility;
2021-06-09 22:19:39 +02:00
using Robust.Shared.ViewVariables;
namespace Content.Server.Power.Components
{
[RegisterComponent]
#pragma warning disable 618
public sealed class ExaminableBatteryComponent : Component, IExamine
#pragma warning restore 618
{
2022-01-15 03:26:37 +01:00
[Dependency] private readonly IEntityManager _entityManager = default!;
2021-12-20 12:42:42 +01:00
void IExamine.Examine(FormattedMessage message, bool inDetailsRange)
{
if (!_entityManager.TryGetComponent<BatteryComponent>(Owner, out var batteryComponent))
return;
if (inDetailsRange)
{
2022-01-15 03:26:37 +01:00
var effectiveMax = batteryComponent.MaxCharge;
if (effectiveMax == 0)
effectiveMax = 1;
2022-01-15 03:26:37 +01:00
var chargeFraction = batteryComponent.CurrentCharge / effectiveMax;
var chargePercentRounded = (int) (chargeFraction * 100);
message.AddMarkup(
Loc.GetString(
"examinable-battery-component-examine-detail",
("percent", chargePercentRounded),
("markupPercentColor", "green")
)
);
}
}
}
}