add fuel indicator to ame fuel jar, minor refactor (#14590)

Co-authored-by: deltanedas <@deltanedas:kde.org>
This commit is contained in:
deltanedas
2023-03-12 12:39:10 +00:00
committed by GitHub
parent e93d5113ad
commit bf105968e9
4 changed files with 48 additions and 35 deletions

View File

@@ -0,0 +1,28 @@
using Content.Server.AME.Components;
using Content.Shared.Examine;
namespace Content.Server.AME;
/// <summary>
/// Adds fuel level info to examine on fuel jars and handles network state.
/// </summary>
public sealed partial class AMESystem
{
private void InitializeFuel()
{
SubscribeLocalEvent<AMEFuelContainerComponent, ExaminedEvent>(OnFuelExamined);
}
private void OnFuelExamined(EntityUid uid, AMEFuelContainerComponent comp, ExaminedEvent args)
{
if (!args.IsInDetailsRange)
return;
// less than 25%: amount < capacity / 4 = amount * 4 < capacity
var low = comp.FuelAmount * 4 < comp.FuelCapacity;
args.PushMarkup(Loc.GetString("ame-fuel-container-component-on-examine-detailed-message",
("colorName", low ? "darkorange" : "orange"),
("amount", comp.FuelAmount),
("capacity", comp.FuelCapacity)));
}
}

View File

@@ -16,7 +16,7 @@ using JetBrains.Annotations;
namespace Content.Server.AME namespace Content.Server.AME
{ {
[UsedImplicitly] [UsedImplicitly]
public sealed class AntimatterEngineSystem : EntitySystem public sealed partial class AMESystem : EntitySystem
{ {
[Dependency] private readonly IMapManager _mapManager = default!; [Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly PopupSystem _popupSystem = default!; [Dependency] private readonly PopupSystem _popupSystem = default!;
@@ -29,9 +29,12 @@ namespace Content.Server.AME
public override void Initialize() public override void Initialize()
{ {
base.Initialize(); base.Initialize();
SubscribeLocalEvent<AMEControllerComponent, PowerChangedEvent>(OnAMEPowerChange); SubscribeLocalEvent<AMEControllerComponent, PowerChangedEvent>(OnAMEPowerChange);
SubscribeLocalEvent<AMEControllerComponent, InteractUsingEvent>(OnInteractUsing); SubscribeLocalEvent<AMEControllerComponent, InteractUsingEvent>(OnInteractUsing);
SubscribeLocalEvent<AMEPartComponent, InteractUsingEvent>(OnPartInteractUsing); SubscribeLocalEvent<AMEPartComponent, InteractUsingEvent>(OnPartInteractUsing);
InitializeFuel();
} }
public override void Update(float frameTime) public override void Update(float frameTime)

View File

@@ -1,37 +1,18 @@
namespace Content.Server.AME.Components namespace Content.Server.AME.Components;
// TODO: network and put in shared
[RegisterComponent]
public sealed class AMEFuelContainerComponent : Component
{ {
[RegisterComponent] /// <summary>
public sealed class AMEFuelContainerComponent : Component /// The amount of fuel in the jar.
{ /// </summary>
private int _fuelAmount; [ViewVariables(VVAccess.ReadWrite), DataField("fuelAmount")]
private int _maxFuelAmount; public int FuelAmount = 1000;
/// <summary> /// <summary>
/// The amount of fuel in the jar. /// The maximum fuel capacity of the jar.
/// </summary> /// </summary>
[ViewVariables(VVAccess.ReadWrite)] [ViewVariables(VVAccess.ReadWrite), DataField("fuelCapacity")]
public int FuelAmount public int FuelCapacity = 1000;
{
get => _fuelAmount;
set => _fuelAmount = value;
}
/// <summary>
/// The maximum fuel capacity of the jar.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
public int MaxFuelAmount
{
get => _maxFuelAmount;
set => _maxFuelAmount = value;
}
protected override void Initialize()
{
base.Initialize();
_maxFuelAmount = 1000;
_fuelAmount = 1000;
}
}
} }

View File

@@ -0,0 +1 @@
ame-fuel-container-component-on-examine-detailed-message = Fuel: [color={$colorName}]{$amount}/{$capacity}[/color]