From bf105968e9059dc7ba4d76bc0cc93f9b04179b99 Mon Sep 17 00:00:00 2001 From: deltanedas <39013340+deltanedas@users.noreply.github.com> Date: Sun, 12 Mar 2023 12:39:10 +0000 Subject: [PATCH] add fuel indicator to ame fuel jar, minor refactor (#14590) Co-authored-by: deltanedas <@deltanedas:kde.org> --- Content.Server/AME/AMESystem.Fuel.cs | 28 +++++++++++ ...AntimatterEngineSystem.cs => AMESystem.cs} | 5 +- .../Components/AMEFuelContainerComponent.cs | 49 ++++++------------- .../ame-fuel-container-component.ftl | 1 + 4 files changed, 48 insertions(+), 35 deletions(-) create mode 100644 Content.Server/AME/AMESystem.Fuel.cs rename Content.Server/AME/{AntimatterEngineSystem.cs => AMESystem.cs} (98%) create mode 100644 Resources/Locale/en-US/ame/components/ame-fuel-container-component.ftl diff --git a/Content.Server/AME/AMESystem.Fuel.cs b/Content.Server/AME/AMESystem.Fuel.cs new file mode 100644 index 0000000000..e2b7cd0a88 --- /dev/null +++ b/Content.Server/AME/AMESystem.Fuel.cs @@ -0,0 +1,28 @@ +using Content.Server.AME.Components; +using Content.Shared.Examine; + +namespace Content.Server.AME; + +/// +/// Adds fuel level info to examine on fuel jars and handles network state. +/// +public sealed partial class AMESystem +{ + private void InitializeFuel() + { + SubscribeLocalEvent(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))); + } +} diff --git a/Content.Server/AME/AntimatterEngineSystem.cs b/Content.Server/AME/AMESystem.cs similarity index 98% rename from Content.Server/AME/AntimatterEngineSystem.cs rename to Content.Server/AME/AMESystem.cs index 3a2bec9751..f2853863a1 100644 --- a/Content.Server/AME/AntimatterEngineSystem.cs +++ b/Content.Server/AME/AMESystem.cs @@ -16,7 +16,7 @@ using JetBrains.Annotations; namespace Content.Server.AME { [UsedImplicitly] - public sealed class AntimatterEngineSystem : EntitySystem + public sealed partial class AMESystem : EntitySystem { [Dependency] private readonly IMapManager _mapManager = default!; [Dependency] private readonly PopupSystem _popupSystem = default!; @@ -29,9 +29,12 @@ namespace Content.Server.AME public override void Initialize() { base.Initialize(); + SubscribeLocalEvent(OnAMEPowerChange); SubscribeLocalEvent(OnInteractUsing); SubscribeLocalEvent(OnPartInteractUsing); + + InitializeFuel(); } public override void Update(float frameTime) diff --git a/Content.Server/AME/Components/AMEFuelContainerComponent.cs b/Content.Server/AME/Components/AMEFuelContainerComponent.cs index bdebf37cd3..e3ef04fb26 100644 --- a/Content.Server/AME/Components/AMEFuelContainerComponent.cs +++ b/Content.Server/AME/Components/AMEFuelContainerComponent.cs @@ -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] - public sealed class AMEFuelContainerComponent : Component - { - private int _fuelAmount; - private int _maxFuelAmount; + /// + /// The amount of fuel in the jar. + /// + [ViewVariables(VVAccess.ReadWrite), DataField("fuelAmount")] + public int FuelAmount = 1000; - /// - /// The amount of fuel in the jar. - /// - [ViewVariables(VVAccess.ReadWrite)] - public int FuelAmount - { - get => _fuelAmount; - set => _fuelAmount = value; - } - - /// - /// The maximum fuel capacity of the jar. - /// - [ViewVariables(VVAccess.ReadWrite)] - public int MaxFuelAmount - { - get => _maxFuelAmount; - set => _maxFuelAmount = value; - } - - protected override void Initialize() - { - base.Initialize(); - _maxFuelAmount = 1000; - _fuelAmount = 1000; - } - - } + /// + /// The maximum fuel capacity of the jar. + /// + [ViewVariables(VVAccess.ReadWrite), DataField("fuelCapacity")] + public int FuelCapacity = 1000; } diff --git a/Resources/Locale/en-US/ame/components/ame-fuel-container-component.ftl b/Resources/Locale/en-US/ame/components/ame-fuel-container-component.ftl new file mode 100644 index 0000000000..c82b08691d --- /dev/null +++ b/Resources/Locale/en-US/ame/components/ame-fuel-container-component.ftl @@ -0,0 +1 @@ +ame-fuel-container-component-on-examine-detailed-message = Fuel: [color={$colorName}]{$amount}/{$capacity}[/color]