From c47391011d0f7f56dfcba8e4db348f0dc0d58c09 Mon Sep 17 00:00:00 2001
From: LordCarve <27449516+LordCarve@users.noreply.github.com>
Date: Thu, 29 Feb 2024 22:44:28 +0100
Subject: [PATCH] Refactor AME to use ItemSlot for Fuel (#25558)
* Using wrench on AME doesn't first try to put it in.
* Refactor AME to use ItemSlot for fuel.
* Apparently these names want to match.
---
.../Ame/UI/AmeControllerBoundUserInterface.cs | 3 +-
Content.Client/Ame/UI/AmeWindow.xaml.cs | 2 +-
Content.Client/Entry/EntryPoint.cs | 2 +-
.../Ame/Components/AmeControllerComponent.cs | 16 +--
.../Components/AmeFuelContainerComponent.cs | 23 ----
.../Ame/Components/AmeShieldComponent.cs | 4 +-
.../Ame/EntitySystems/AmeControllerSystem.cs | 117 +++++++++---------
.../Ame/EntitySystems/AmeShieldingSystem.cs | 2 +-
.../Components/AmeFuelContainerComponent.cs | 19 +++
.../SharedAmeControllerComponent.cs | 3 +-
.../SharedAmeShieldComponent.cs | 4 +-
.../EntitySystems/AmeFuelContainerSystem.cs | 8 +-
.../components/ame-controller-component.ftl | 6 +-
.../Structures/Power/Generation/ame.yml | 9 +-
14 files changed, 109 insertions(+), 109 deletions(-)
delete mode 100644 Content.Server/Ame/Components/AmeFuelContainerComponent.cs
create mode 100644 Content.Shared/Ame/Components/AmeFuelContainerComponent.cs
rename Content.Shared/Ame/{ => Components}/SharedAmeControllerComponent.cs (95%)
rename Content.Shared/Ame/{ => Components}/SharedAmeShieldComponent.cs (77%)
rename Content.Server/Ame/EntitySystems/AmeFuelSystem.cs => Content.Shared/Ame/EntitySystems/AmeFuelContainerSystem.cs (77%)
diff --git a/Content.Client/Ame/UI/AmeControllerBoundUserInterface.cs b/Content.Client/Ame/UI/AmeControllerBoundUserInterface.cs
index 3b4c9fa224..e84cf5d34d 100644
--- a/Content.Client/Ame/UI/AmeControllerBoundUserInterface.cs
+++ b/Content.Client/Ame/UI/AmeControllerBoundUserInterface.cs
@@ -1,6 +1,5 @@
-using Content.Shared.Ame;
+using Content.Shared.Ame.Components;
using JetBrains.Annotations;
-using Robust.Client.GameObjects;
namespace Content.Client.Ame.UI
{
diff --git a/Content.Client/Ame/UI/AmeWindow.xaml.cs b/Content.Client/Ame/UI/AmeWindow.xaml.cs
index 8f5103e6cf..8b91ec5966 100644
--- a/Content.Client/Ame/UI/AmeWindow.xaml.cs
+++ b/Content.Client/Ame/UI/AmeWindow.xaml.cs
@@ -1,5 +1,5 @@
using Content.Client.UserInterface;
-using Content.Shared.Ame;
+using Content.Shared.Ame.Components;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML;
diff --git a/Content.Client/Entry/EntryPoint.cs b/Content.Client/Entry/EntryPoint.cs
index a9ecb3a725..3acc4ab180 100644
--- a/Content.Client/Entry/EntryPoint.cs
+++ b/Content.Client/Entry/EntryPoint.cs
@@ -21,7 +21,7 @@ using Content.Client.Singularity;
using Content.Client.Stylesheets;
using Content.Client.Viewport;
using Content.Client.Voting;
-using Content.Shared.Ame;
+using Content.Shared.Ame.Components;
using Content.Shared.Gravity;
using Content.Shared.Localizations;
using Robust.Client;
diff --git a/Content.Server/Ame/Components/AmeControllerComponent.cs b/Content.Server/Ame/Components/AmeControllerComponent.cs
index 2b7a46e947..fae3d86633 100644
--- a/Content.Server/Ame/Components/AmeControllerComponent.cs
+++ b/Content.Server/Ame/Components/AmeControllerComponent.cs
@@ -1,7 +1,7 @@
using Content.Server.Ame.EntitySystems;
-using Content.Shared.Ame;
+using Content.Shared.Ame.Components;
+using Content.Shared.Containers.ItemSlots;
using Robust.Shared.Audio;
-using Robust.Shared.Containers;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
namespace Content.Server.Ame.Components;
@@ -15,15 +15,11 @@ namespace Content.Server.Ame.Components;
public sealed partial class AmeControllerComponent : SharedAmeControllerComponent
{
///
- /// The id of the container used to store the current fuel container for the AME.
+ /// Antimatter fuel slot.
///
- public const string FuelContainerId = "AmeFuel";
-
- ///
- /// The container for the fuel canisters used by the AME.
- ///
- [ViewVariables]
- public ContainerSlot JarSlot = default!;
+ [DataField("fuelSlot")]
+ [ViewVariables(VVAccess.ReadWrite)]
+ public ItemSlot FuelSlot = new();
///
/// Whether or not the AME controller is currently injecting animatter into the reactor.
diff --git a/Content.Server/Ame/Components/AmeFuelContainerComponent.cs b/Content.Server/Ame/Components/AmeFuelContainerComponent.cs
deleted file mode 100644
index b69f1d452f..0000000000
--- a/Content.Server/Ame/Components/AmeFuelContainerComponent.cs
+++ /dev/null
@@ -1,23 +0,0 @@
-namespace Content.Server.Ame.Components;
-
-///
-/// An antimatter containment cell used to handle the fuel for the AME.
-/// TODO: network and put in shared
-///
-[RegisterComponent]
-public sealed partial class AmeFuelContainerComponent : Component
-{
- ///
- /// The amount of fuel in the jar.
- ///
- [DataField("fuelAmount")]
- [ViewVariables(VVAccess.ReadWrite)]
- public int FuelAmount = 1000;
-
- ///
- /// The maximum fuel capacity of the jar.
- ///
- [DataField("fuelCapacity")]
- [ViewVariables(VVAccess.ReadWrite)]
- public int FuelCapacity = 1000;
-}
diff --git a/Content.Server/Ame/Components/AmeShieldComponent.cs b/Content.Server/Ame/Components/AmeShieldComponent.cs
index 322c5218dd..8ebcfdc88b 100644
--- a/Content.Server/Ame/Components/AmeShieldComponent.cs
+++ b/Content.Server/Ame/Components/AmeShieldComponent.cs
@@ -1,5 +1,5 @@
-using Content.Server.Ame.EntitySystems;
-using Content.Shared.Ame;
+using Content.Server.Ame.EntitySystems;
+using Content.Shared.Ame.Components;
namespace Content.Server.Ame.Components;
diff --git a/Content.Server/Ame/EntitySystems/AmeControllerSystem.cs b/Content.Server/Ame/EntitySystems/AmeControllerSystem.cs
index 93b2a29a76..79223d5b1d 100644
--- a/Content.Server/Ame/EntitySystems/AmeControllerSystem.cs
+++ b/Content.Server/Ame/EntitySystems/AmeControllerSystem.cs
@@ -6,14 +6,10 @@ using Content.Server.Ame.Components;
using Content.Server.Chat.Managers;
using Content.Server.NodeContainer;
using Content.Server.Power.Components;
-using Content.Shared.Ame;
+using Content.Shared.Ame.Components;
+using Content.Shared.Containers.ItemSlots;
using Content.Shared.Database;
-using Content.Shared.Hands.Components;
-using Content.Shared.Hands.EntitySystems;
-using Content.Shared.Interaction;
using Content.Shared.Mind.Components;
-using Content.Shared.Popups;
-using Robust.Server.Containers;
using Robust.Server.GameObjects;
using Robust.Shared.Audio;
using Robust.Shared.Audio.Systems;
@@ -30,22 +26,29 @@ public sealed class AmeControllerSystem : EntitySystem
[Dependency] private readonly IChatManager _chatManager = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly AppearanceSystem _appearanceSystem = default!;
- [Dependency] private readonly ContainerSystem _containerSystem = default!;
[Dependency] private readonly SharedAudioSystem _audioSystem = default!;
- [Dependency] private readonly SharedHandsSystem _handsSystem = default!;
- [Dependency] private readonly SharedPopupSystem _popupSystem = default!;
[Dependency] private readonly UserInterfaceSystem _userInterfaceSystem = default!;
+ [Dependency] private readonly ItemSlotsSystem _itemSlots = default!;
public override void Initialize()
{
base.Initialize();
- SubscribeLocalEvent(OnComponentStartup);
- SubscribeLocalEvent(OnInteractUsing);
+ SubscribeLocalEvent(OnInit);
+ SubscribeLocalEvent(OnRemove);
+ SubscribeLocalEvent(OnItemSlotChanged);
+ SubscribeLocalEvent(OnItemSlotChanged);
SubscribeLocalEvent(OnPowerChanged);
SubscribeLocalEvent(OnUiButtonPressed);
}
+ private void OnInit(EntityUid uid, AmeControllerComponent component, ComponentInit args)
+ {
+ _itemSlots.AddItemSlot(uid, SharedAmeControllerComponent.FuelSlotId, component.FuelSlot);
+
+ UpdateUi(uid, component);
+ }
+
public override void Update(float frameTime)
{
var curTime = _gameTiming.CurTime;
@@ -59,6 +62,22 @@ public sealed class AmeControllerSystem : EntitySystem
}
}
+ private void OnRemove(EntityUid uid, AmeControllerComponent component, ComponentRemove args)
+ {
+ _itemSlots.RemoveItemSlot(uid, component.FuelSlot);
+ }
+
+ private void OnItemSlotChanged(EntityUid uid, AmeControllerComponent component, ContainerModifiedMessage args)
+ {
+ if (!component.Initialized)
+ return;
+
+ if (args.Container.ID != component.FuelSlot.ID)
+ return;
+
+ UpdateUi(uid, component);
+ }
+
private void UpdateController(EntityUid uid, TimeSpan curTime, AmeControllerComponent? controller = null, NodeContainerComponent? nodes = null)
{
if (!Resolve(uid, ref controller))
@@ -71,23 +90,24 @@ public sealed class AmeControllerSystem : EntitySystem
if (!controller.Injecting)
return;
+
if (!TryGetAMENodeGroup(uid, out var group, nodes))
return;
- if (TryComp(controller.JarSlot.ContainedEntity, out var fuelJar))
+ if (TryComp(controller.FuelSlot.Item, out var fuelContainer))
{
// if the jar is empty shut down the AME
- if (fuelJar.FuelAmount <= 0)
+ if (fuelContainer.FuelAmount <= 0)
{
SetInjecting(uid, false, null, controller);
}
else
{
- var availableInject = Math.Min(controller.InjectionAmount, fuelJar.FuelAmount);
+ var availableInject = Math.Min(controller.InjectionAmount, fuelContainer.FuelAmount);
var powerOutput = group.InjectFuel(availableInject, out var overloading);
if (TryComp(uid, out var powerOutlet))
powerOutlet.MaxSupply = powerOutput;
- fuelJar.FuelAmount -= availableInject;
+ fuelContainer.FuelAmount -= availableInject;
// only play audio if we actually had an injection
if (availableInject > 0)
_audioSystem.PlayPvs(controller.InjectSound, uid, AudioParams.Default.WithVolume(overloading ? 10f : 0f));
@@ -138,11 +158,28 @@ public sealed class AmeControllerSystem : EntitySystem
currentPowerSupply = powerOutlet.CurrentSupply / 1000;
}
- var hasJar = Exists(controller.JarSlot.ContainedEntity);
- if (!hasJar || !TryComp(controller.JarSlot.ContainedEntity, out var jar))
- return new AmeControllerBoundUserInterfaceState(powered, IsMasterController(uid), false, hasJar, 0, controller.InjectionAmount, coreCount, currentPowerSupply, targetedPowerSupply);
+ var fuelContainerInSlot = controller.FuelSlot.Item;
+ var hasFuelContainerInSlot = Exists(fuelContainerInSlot);
+ if (!hasFuelContainerInSlot || !TryComp(fuelContainerInSlot, out var fuelContainer))
+ return new AmeControllerBoundUserInterfaceState(powered,
+ IsMasterController(uid),
+ false,
+ hasFuelContainerInSlot,
+ 0,
+ controller.InjectionAmount,
+ coreCount,
+ currentPowerSupply,
+ targetedPowerSupply);
- return new AmeControllerBoundUserInterfaceState(powered, IsMasterController(uid), controller.Injecting, hasJar, jar.FuelAmount, controller.InjectionAmount, coreCount, currentPowerSupply, targetedPowerSupply);
+ return new AmeControllerBoundUserInterfaceState(powered,
+ IsMasterController(uid),
+ controller.Injecting,
+ hasFuelContainerInSlot,
+ fuelContainer.FuelAmount,
+ controller.InjectionAmount,
+ coreCount,
+ currentPowerSupply,
+ targetedPowerSupply);
}
private bool IsMasterController(EntityUid uid)
@@ -170,23 +207,23 @@ public sealed class AmeControllerSystem : EntitySystem
{
if (!Resolve(uid, ref controller))
return;
+
if (controller.Injecting)
return;
- var jar = controller.JarSlot.ContainedEntity;
- if (!Exists(jar))
+ if (!Exists(controller.FuelSlot.Item))
return;
- _containerSystem.Remove(jar!.Value, controller.JarSlot);
+ _itemSlots.TryEjectToHands(uid, controller.FuelSlot, user);
+
UpdateUi(uid, controller);
- if (Exists(user))
- _handsSystem.PickupOrDrop(user, jar!.Value);
}
public void SetInjecting(EntityUid uid, bool value, EntityUid? user = null, AmeControllerComponent? controller = null)
{
if (!Resolve(uid, ref controller))
return;
+
if (controller.Injecting == value)
return;
@@ -278,38 +315,6 @@ public sealed class AmeControllerSystem : EntitySystem
);
}
- private void OnComponentStartup(EntityUid uid, AmeControllerComponent comp, ComponentStartup args)
- {
- // TODO: Fix this bad name. I'd update maps but then people get mad.
- comp.JarSlot = _containerSystem.EnsureContainer(uid, AmeControllerComponent.FuelContainerId);
- }
-
- private void OnInteractUsing(EntityUid uid, AmeControllerComponent comp, InteractUsingEvent args)
- {
- if (!HasComp(args.User))
- {
- _popupSystem.PopupEntity(Loc.GetString("ame-controller-component-interact-using-no-hands-text"), uid, args.User);
- return;
- }
-
- if (!HasComp(args.Used))
- {
- _popupSystem.PopupEntity(Loc.GetString("ame-controller-component-interact-using-fail"), uid, args.User);
- return;
- }
-
- if (Exists(comp.JarSlot.ContainedEntity))
- {
- _popupSystem.PopupEntity(Loc.GetString("ame-controller-component-interact-using-already-has-jar"), uid, args.User);
- return;
- }
-
- _containerSystem.Insert(args.Used, comp.JarSlot);
- _popupSystem.PopupEntity(Loc.GetString("ame-controller-component-interact-using-success"), uid, args.User, PopupType.Medium);
-
- UpdateUi(uid, comp);
- }
-
private void OnPowerChanged(EntityUid uid, AmeControllerComponent comp, ref PowerChangedEvent args)
{
UpdateUi(uid, comp);
diff --git a/Content.Server/Ame/EntitySystems/AmeShieldingSystem.cs b/Content.Server/Ame/EntitySystems/AmeShieldingSystem.cs
index c8ebaf53e8..542ae8035e 100644
--- a/Content.Server/Ame/EntitySystems/AmeShieldingSystem.cs
+++ b/Content.Server/Ame/EntitySystems/AmeShieldingSystem.cs
@@ -1,5 +1,5 @@
using Content.Server.Ame.Components;
-using Content.Shared.Ame;
+using Content.Shared.Ame.Components;
using Robust.Server.GameObjects;
namespace Content.Server.Ame.EntitySystems;
diff --git a/Content.Shared/Ame/Components/AmeFuelContainerComponent.cs b/Content.Shared/Ame/Components/AmeFuelContainerComponent.cs
new file mode 100644
index 0000000000..757a3a515b
--- /dev/null
+++ b/Content.Shared/Ame/Components/AmeFuelContainerComponent.cs
@@ -0,0 +1,19 @@
+using Robust.Shared.GameStates;
+
+namespace Content.Shared.Ame.Components;
+
+[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
+public sealed partial class AmeFuelContainerComponent : Component
+{
+ ///
+ /// The amount of fuel in the container.
+ ///
+ [DataField, ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
+ public int FuelAmount = 1000;
+
+ ///
+ /// The maximum fuel capacity of the container.
+ ///
+ [DataField, ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
+ public int FuelCapacity = 1000;
+}
diff --git a/Content.Shared/Ame/SharedAmeControllerComponent.cs b/Content.Shared/Ame/Components/SharedAmeControllerComponent.cs
similarity index 95%
rename from Content.Shared/Ame/SharedAmeControllerComponent.cs
rename to Content.Shared/Ame/Components/SharedAmeControllerComponent.cs
index 11925a82a0..d9f5d80c3e 100644
--- a/Content.Shared/Ame/SharedAmeControllerComponent.cs
+++ b/Content.Shared/Ame/Components/SharedAmeControllerComponent.cs
@@ -1,10 +1,11 @@
using Robust.Shared.Serialization;
-namespace Content.Shared.Ame;
+namespace Content.Shared.Ame.Components;
[Virtual]
public partial class SharedAmeControllerComponent : Component
{
+ public const string FuelSlotId = "fuelSlot";
}
[Serializable, NetSerializable]
diff --git a/Content.Shared/Ame/SharedAmeShieldComponent.cs b/Content.Shared/Ame/Components/SharedAmeShieldComponent.cs
similarity index 77%
rename from Content.Shared/Ame/SharedAmeShieldComponent.cs
rename to Content.Shared/Ame/Components/SharedAmeShieldComponent.cs
index 3057de7160..21278e0131 100644
--- a/Content.Shared/Ame/SharedAmeShieldComponent.cs
+++ b/Content.Shared/Ame/Components/SharedAmeShieldComponent.cs
@@ -1,6 +1,6 @@
-using Robust.Shared.Serialization;
+using Robust.Shared.Serialization;
-namespace Content.Shared.Ame;
+namespace Content.Shared.Ame.Components;
[Virtual]
public partial class SharedAmeShieldComponent : Component
diff --git a/Content.Server/Ame/EntitySystems/AmeFuelSystem.cs b/Content.Shared/Ame/EntitySystems/AmeFuelContainerSystem.cs
similarity index 77%
rename from Content.Server/Ame/EntitySystems/AmeFuelSystem.cs
rename to Content.Shared/Ame/EntitySystems/AmeFuelContainerSystem.cs
index a7971b449e..10e5f78d0d 100644
--- a/Content.Server/Ame/EntitySystems/AmeFuelSystem.cs
+++ b/Content.Shared/Ame/EntitySystems/AmeFuelContainerSystem.cs
@@ -1,12 +1,12 @@
-using Content.Server.Ame.Components;
+using Content.Shared.Ame.Components;
using Content.Shared.Examine;
-namespace Content.Server.Ame.EntitySystems;
+namespace Content.Shared.Ame.EntitySystems;
///
-/// Adds fuel level info to examine on fuel jars and handles network state.
+/// Adds details about fuel level when examining antimatter engine fuel containers.
///
-public sealed class AmeFuelSystem : EntitySystem
+public sealed class AmeFuelContainerSystem : EntitySystem
{
public override void Initialize()
{
diff --git a/Resources/Locale/en-US/ame/components/ame-controller-component.ftl b/Resources/Locale/en-US/ame/components/ame-controller-component.ftl
index cd5e6b4661..377f43ff2f 100644
--- a/Resources/Locale/en-US/ame/components/ame-controller-component.ftl
+++ b/Resources/Locale/en-US/ame/components/ame-controller-component.ftl
@@ -1,8 +1,4 @@
-ame-controller-component-interact-no-hands-text = You have no hands.
-ame-controller-component-interact-using-no-hands-text = You have no hands.
-ame-controller-component-interact-using-already-has-jar = The controller already has a jar loaded.
-ame-controller-component-interact-using-success = You insert the jar into the fuel slot.
-ame-controller-component-interact-using-fail = You can't put that in the controller...
+ame-controller-component-interact-using-whitelist-fail = You can't put that in the controller...
## UI
diff --git a/Resources/Prototypes/Entities/Structures/Power/Generation/ame.yml b/Resources/Prototypes/Entities/Structures/Power/Generation/ame.yml
index 78fdaae01a..a268f35154 100644
--- a/Resources/Prototypes/Entities/Structures/Power/Generation/ame.yml
+++ b/Resources/Prototypes/Entities/Structures/Power/Generation/ame.yml
@@ -50,6 +50,12 @@
- type: Anchorable
- type: Pullable
- type: AmeController
+ fuelSlot:
+ whitelist:
+ components:
+ - AmeFuelContainer
+ whitelistFailPopup: ame-controller-component-interact-using-whitelist-fail
+ swap: false
- type: Explosive
explosionType: Default
intensitySlope: 5
@@ -86,9 +92,10 @@
state: static
- type: PowerSupplier
supplyRate: 0
+ - type: ItemSlots
- type: ContainerContainer
containers:
- AmeFuel: !type:ContainerSlot {}
+ fuelSlot: !type:ContainerSlot
- type: GuideHelp
guides: [ AME, Power ]
- type: Electrified