]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
ChemMaster buffer preserves list ordering (#23352)
authorSkye <57879983+Rainbeon@users.noreply.github.com>
Tue, 2 Jan 2024 15:51:21 +0000 (10:51 -0500)
committerGitHub <noreply@github.com>
Tue, 2 Jan 2024 15:51:21 +0000 (10:51 -0500)
ChemMaster now maintains list order on reagent removal

Content.Server/Chemistry/EntitySystems/ChemMasterSystem.cs
Content.Shared/Chemistry/Components/Solution.cs

index 2cc0f3d055e147b5e294d447984ec6b6640b6ea9..ab91044574957dc5c6abc11ac6235caed2c3937f 100644 (file)
@@ -140,7 +140,7 @@ namespace Content.Server.Chemistry.EntitySystems
             if (fromBuffer) // Buffer to container
             {
                 amount = FixedPoint2.Min(amount, containerSolution.AvailableVolume);
-                amount = bufferSolution.RemoveReagent(id, amount);
+                amount = bufferSolution.RemoveReagent(id, amount, preserveOrder: true);
                 _solutionContainerSystem.TryAddReagent(containerSoln.Value, id, amount, out var _);
             }
             else // Container to buffer
@@ -158,7 +158,7 @@ namespace Content.Server.Chemistry.EntitySystems
             if (fromBuffer)
             {
                 if (_solutionContainerSystem.TryGetSolution(chemMaster.Owner, SharedChemMaster.BufferSolutionName, out _, out var bufferSolution))
-                    bufferSolution.RemoveReagent(id, amount);
+                    bufferSolution.RemoveReagent(id, amount, preserveOrder: true);
                 else
                     return;
             }
index 8598e1ad99f6fcf7010702f9dc189d9a86a664a7..f8e482131996e70d6c8152bd81e2a0f39f7d7388 100644 (file)
@@ -466,7 +466,7 @@ namespace Content.Shared.Chemistry.Components
         /// </summary>
         /// <param name="toRemove">The reagent to be removed.</param>
         /// <returns>How much reagent was actually removed. Zero if the reagent is not present on the solution.</returns>
-        public FixedPoint2 RemoveReagent(ReagentQuantity toRemove)
+        public FixedPoint2 RemoveReagent(ReagentQuantity toRemove, bool preserveOrder = false)
         {
             if (toRemove.Quantity <= FixedPoint2.Zero)
                 return FixedPoint2.Zero;
@@ -483,7 +483,11 @@ namespace Content.Shared.Chemistry.Components
 
                 if (newQuantity <= 0)
                 {
-                    Contents.RemoveSwap(i);
+                    if (!preserveOrder)
+                        Contents.RemoveSwap(i);
+                    else
+                        Contents.RemoveAt(i);
+
                     Volume -= curQuantity;
                     ValidateSolution();
                     return curQuantity;
@@ -516,9 +520,9 @@ namespace Content.Shared.Chemistry.Components
         /// <param name="reagentId">The reagent to be removed.</param>
         /// <param name="quantity">The amount of reagent to remove.</param>
         /// <returns>How much reagent was actually removed. Zero if the reagent is not present on the solution.</returns>
-        public FixedPoint2 RemoveReagent(ReagentId reagentId, FixedPoint2 quantity)
+        public FixedPoint2 RemoveReagent(ReagentId reagentId, FixedPoint2 quantity, bool preserveOrder = false)
         {
-            return RemoveReagent(new ReagentQuantity(reagentId, quantity));
+            return RemoveReagent(new ReagentQuantity(reagentId, quantity), preserveOrder);
         }
 
         public void RemoveAllSolution()