ChemMaster buffer preserves list ordering (#23352)

ChemMaster now maintains list order on reagent removal
This commit is contained in:
Skye
2024-01-02 10:51:21 -05:00
committed by GitHub
parent 522e33215b
commit fbe72c848a
2 changed files with 10 additions and 6 deletions

View 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;
}

View 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()