ChemMaster buffer preserves list ordering (#23352)
ChemMaster now maintains list order on reagent removal
This commit is contained in:
@@ -140,7 +140,7 @@ namespace Content.Server.Chemistry.EntitySystems
|
|||||||
if (fromBuffer) // Buffer to container
|
if (fromBuffer) // Buffer to container
|
||||||
{
|
{
|
||||||
amount = FixedPoint2.Min(amount, containerSolution.AvailableVolume);
|
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 _);
|
_solutionContainerSystem.TryAddReagent(containerSoln.Value, id, amount, out var _);
|
||||||
}
|
}
|
||||||
else // Container to buffer
|
else // Container to buffer
|
||||||
@@ -158,7 +158,7 @@ namespace Content.Server.Chemistry.EntitySystems
|
|||||||
if (fromBuffer)
|
if (fromBuffer)
|
||||||
{
|
{
|
||||||
if (_solutionContainerSystem.TryGetSolution(chemMaster.Owner, SharedChemMaster.BufferSolutionName, out _, out var bufferSolution))
|
if (_solutionContainerSystem.TryGetSolution(chemMaster.Owner, SharedChemMaster.BufferSolutionName, out _, out var bufferSolution))
|
||||||
bufferSolution.RemoveReagent(id, amount);
|
bufferSolution.RemoveReagent(id, amount, preserveOrder: true);
|
||||||
else
|
else
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -466,7 +466,7 @@ namespace Content.Shared.Chemistry.Components
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="toRemove">The reagent to be removed.</param>
|
/// <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>
|
/// <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)
|
if (toRemove.Quantity <= FixedPoint2.Zero)
|
||||||
return FixedPoint2.Zero;
|
return FixedPoint2.Zero;
|
||||||
@@ -483,7 +483,11 @@ namespace Content.Shared.Chemistry.Components
|
|||||||
|
|
||||||
if (newQuantity <= 0)
|
if (newQuantity <= 0)
|
||||||
{
|
{
|
||||||
Contents.RemoveSwap(i);
|
if (!preserveOrder)
|
||||||
|
Contents.RemoveSwap(i);
|
||||||
|
else
|
||||||
|
Contents.RemoveAt(i);
|
||||||
|
|
||||||
Volume -= curQuantity;
|
Volume -= curQuantity;
|
||||||
ValidateSolution();
|
ValidateSolution();
|
||||||
return curQuantity;
|
return curQuantity;
|
||||||
@@ -516,9 +520,9 @@ namespace Content.Shared.Chemistry.Components
|
|||||||
/// <param name="reagentId">The reagent to be removed.</param>
|
/// <param name="reagentId">The reagent to be removed.</param>
|
||||||
/// <param name="quantity">The amount of reagent to remove.</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>
|
/// <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()
|
public void RemoveAllSolution()
|
||||||
|
|||||||
Reference in New Issue
Block a user