]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Refactor AME to use ItemSlot for Fuel (#25558)
authorLordCarve <27449516+LordCarve@users.noreply.github.com>
Thu, 29 Feb 2024 21:44:28 +0000 (22:44 +0100)
committerGitHub <noreply@github.com>
Thu, 29 Feb 2024 21:44:28 +0000 (16:44 -0500)
* 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.

14 files changed:
Content.Client/Ame/UI/AmeControllerBoundUserInterface.cs
Content.Client/Ame/UI/AmeWindow.xaml.cs
Content.Client/Entry/EntryPoint.cs
Content.Server/Ame/Components/AmeControllerComponent.cs
Content.Server/Ame/Components/AmeFuelContainerComponent.cs [deleted file]
Content.Server/Ame/Components/AmeShieldComponent.cs
Content.Server/Ame/EntitySystems/AmeControllerSystem.cs
Content.Server/Ame/EntitySystems/AmeShieldingSystem.cs
Content.Shared/Ame/Components/AmeFuelContainerComponent.cs [new file with mode: 0644]
Content.Shared/Ame/Components/SharedAmeControllerComponent.cs [moved from Content.Shared/Ame/SharedAmeControllerComponent.cs with 95% similarity]
Content.Shared/Ame/Components/SharedAmeShieldComponent.cs [moved from Content.Shared/Ame/SharedAmeShieldComponent.cs with 77% similarity]
Content.Shared/Ame/EntitySystems/AmeFuelContainerSystem.cs [moved from Content.Server/Ame/EntitySystems/AmeFuelSystem.cs with 77% similarity]
Resources/Locale/en-US/ame/components/ame-controller-component.ftl
Resources/Prototypes/Entities/Structures/Power/Generation/ame.yml

index 3b4c9fa224d6f02de4bc8bdc22158e5bfb759e51..e84cf5d34de8b6740fd04de39367f9f4e46b8a89 100644 (file)
@@ -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
 {
index 8f5103e6cf738260cbcaadd8cee8e853a2d9b7d6..8b91ec596609bdc35ff6ae0611f5a16c51bec92f 100644 (file)
@@ -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;
index a9ecb3a725699bf64069399c63fd8bd38b407dc3..3acc4ab18002e4f2a737bfed9299299d5cc63094 100644 (file)
@@ -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;
index 2b7a46e947afbf33a8eba29f6ee3a263cddd8f92..fae3d86633d41bd2836b1b9e39fe16d8d9633fcb 100644 (file)
@@ -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
 {
     /// <summary>
-    /// The id of the container used to store the current fuel container for the AME.
+    /// Antimatter fuel slot.
     /// </summary>
-    public const string FuelContainerId = "AmeFuel";
-
-    /// <summary>
-    /// The container for the fuel canisters used by the AME.
-    /// </summary>
-    [ViewVariables]
-    public ContainerSlot JarSlot = default!;
+    [DataField("fuelSlot")]
+    [ViewVariables(VVAccess.ReadWrite)]
+    public ItemSlot FuelSlot = new();
 
     /// <summary>
     /// 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 (file)
index b69f1d4..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-namespace Content.Server.Ame.Components;
-
-/// <summary>
-/// An antimatter containment cell used to handle the fuel for the AME.
-/// TODO: network and put in shared
-/// </summary>
-[RegisterComponent]
-public sealed partial class AmeFuelContainerComponent : Component
-{
-    /// <summary>
-    /// The amount of fuel in the jar.
-    /// </summary>
-    [DataField("fuelAmount")]
-    [ViewVariables(VVAccess.ReadWrite)]
-    public int FuelAmount = 1000;
-
-    /// <summary>
-    /// The maximum fuel capacity of the jar.
-    /// </summary>
-    [DataField("fuelCapacity")]
-    [ViewVariables(VVAccess.ReadWrite)]
-    public int FuelCapacity = 1000;
-}
index 322c5218dd97b5a99d928224bc443863e263ecac..8ebcfdc88bf45fc7f963a2f98865686e9510cc2a 100644 (file)
@@ -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;
 
index 93b2a29a7679a623f53eca8e9e77273eabc48200..79223d5b1d368ddd286cf23987145952189c19d5 100644 (file)
@@ -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<AmeControllerComponent, ComponentStartup>(OnComponentStartup);
-        SubscribeLocalEvent<AmeControllerComponent, InteractUsingEvent>(OnInteractUsing);
+        SubscribeLocalEvent<AmeControllerComponent, ComponentInit>(OnInit);
+        SubscribeLocalEvent<AmeControllerComponent, ComponentRemove>(OnRemove);
+        SubscribeLocalEvent<AmeControllerComponent, EntInsertedIntoContainerMessage>(OnItemSlotChanged);
+        SubscribeLocalEvent<AmeControllerComponent, EntRemovedFromContainerMessage>(OnItemSlotChanged);
         SubscribeLocalEvent<AmeControllerComponent, PowerChangedEvent>(OnPowerChanged);
         SubscribeLocalEvent<AmeControllerComponent, UiButtonPressedMessage>(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<AmeFuelContainerComponent>(controller.JarSlot.ContainedEntity, out var fuelJar))
+        if (TryComp<AmeFuelContainerComponent>(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<PowerSupplierComponent>(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<AmeFuelContainerComponent>(controller.JarSlot.ContainedEntity, out var jar))
-            return new AmeControllerBoundUserInterfaceState(powered, IsMasterController(uid), false, hasJar, 0, controller.InjectionAmount, coreCount, currentPowerSupply, targetedPowerSupply);
-
-        return new AmeControllerBoundUserInterfaceState(powered, IsMasterController(uid), controller.Injecting, hasJar, jar.FuelAmount, controller.InjectionAmount, coreCount, currentPowerSupply, targetedPowerSupply);
+        var fuelContainerInSlot = controller.FuelSlot.Item;
+        var hasFuelContainerInSlot = Exists(fuelContainerInSlot);
+        if (!hasFuelContainerInSlot || !TryComp<AmeFuelContainerComponent>(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,
+                                                        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<ContainerSlot>(uid, AmeControllerComponent.FuelContainerId);
-    }
-
-    private void OnInteractUsing(EntityUid uid, AmeControllerComponent comp, InteractUsingEvent args)
-    {
-        if (!HasComp<HandsComponent>(args.User))
-        {
-            _popupSystem.PopupEntity(Loc.GetString("ame-controller-component-interact-using-no-hands-text"), uid, args.User);
-            return;
-        }
-
-        if (!HasComp<AmeFuelContainerComponent>(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);
index c8ebaf53e8ce3ace84977692d6f7bfcc43300c59..542ae8035e2d4f014860341e4429a67f96655755 100644 (file)
@@ -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 (file)
index 0000000..757a3a5
--- /dev/null
@@ -0,0 +1,19 @@
+using Robust.Shared.GameStates;
+
+namespace Content.Shared.Ame.Components;
+
+[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
+public sealed partial class AmeFuelContainerComponent : Component
+{
+    /// <summary>
+    /// The amount of fuel in the container.
+    /// </summary>
+    [DataField, ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
+    public int FuelAmount = 1000;
+
+    /// <summary>
+    /// The maximum fuel capacity of the container.
+    /// </summary>
+    [DataField, ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
+    public int FuelCapacity = 1000;
+}
similarity index 95%
rename from Content.Shared/Ame/SharedAmeControllerComponent.cs
rename to Content.Shared/Ame/Components/SharedAmeControllerComponent.cs
index 11925a82a09fd2e185ca3d15590eabf88c7a9af0..d9f5d80c3e09e286c71b920308ffccbbc148022f 100644 (file)
@@ -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]
similarity index 77%
rename from Content.Shared/Ame/SharedAmeShieldComponent.cs
rename to Content.Shared/Ame/Components/SharedAmeShieldComponent.cs
index 3057de71608e8f4ac0436a723f6b34b0aacd68ee..21278e0131cc48fdb3f395bb173fd25385b5f937 100644 (file)
@@ -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
similarity index 77%
rename from Content.Server/Ame/EntitySystems/AmeFuelSystem.cs
rename to Content.Shared/Ame/EntitySystems/AmeFuelContainerSystem.cs
index a7971b449e990804ff48d2b89e2993eedd08dd2b..10e5f78d0d05c83b86b31fd2b1dbea2ecdd069dd 100644 (file)
@@ -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;
 
 /// <summary>
-/// Adds fuel level info to examine on fuel jars and handles network state.
+/// Adds details about fuel level when examining antimatter engine fuel containers.
 /// </summary>
-public sealed class AmeFuelSystem : EntitySystem
+public sealed class AmeFuelContainerSystem : EntitySystem
 {
     public override void Initialize()
     {
index cd5e6b4661c12b3aaaa457f130454878cd453be0..377f43ff2f95ca080c296432a9d8c9d6be3c543f 100644 (file)
@@ -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
 
index 78fdaae01a485e756df1df43726190f02500b42a..a268f351547801339dc45255ae04a1323f3a24b6 100644 (file)
   - 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
     state: static
   - type: PowerSupplier
     supplyRate: 0
+  - type: ItemSlots
   - type: ContainerContainer
     containers:
-      AmeFuel: !type:ContainerSlot {}
+      fuelSlot: !type:ContainerSlot
   - type: GuideHelp
     guides: [ AME, Power ]
   - type: Electrified