From fbe72c848a8d24f9a653820e8ed915dd8446bcf5 Mon Sep 17 00:00:00 2001
From: Skye <57879983+Rainbeon@users.noreply.github.com>
Date: Tue, 2 Jan 2024 10:51:21 -0500
Subject: [PATCH] ChemMaster buffer preserves list ordering (#23352)
ChemMaster now maintains list order on reagent removal
---
.../Chemistry/EntitySystems/ChemMasterSystem.cs | 4 ++--
Content.Shared/Chemistry/Components/Solution.cs | 12 ++++++++----
2 files changed, 10 insertions(+), 6 deletions(-)
diff --git a/Content.Server/Chemistry/EntitySystems/ChemMasterSystem.cs b/Content.Server/Chemistry/EntitySystems/ChemMasterSystem.cs
index 2cc0f3d055..ab91044574 100644
--- a/Content.Server/Chemistry/EntitySystems/ChemMasterSystem.cs
+++ b/Content.Server/Chemistry/EntitySystems/ChemMasterSystem.cs
@@ -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;
}
diff --git a/Content.Shared/Chemistry/Components/Solution.cs b/Content.Shared/Chemistry/Components/Solution.cs
index 8598e1ad99..f8e4821319 100644
--- a/Content.Shared/Chemistry/Components/Solution.cs
+++ b/Content.Shared/Chemistry/Components/Solution.cs
@@ -466,7 +466,7 @@ namespace Content.Shared.Chemistry.Components
///
/// The reagent to be removed.
/// How much reagent was actually removed. Zero if the reagent is not present on the solution.
- 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
/// The reagent to be removed.
/// The amount of reagent to remove.
/// How much reagent was actually removed. Zero if the reagent is not present on the solution.
- 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()