Revert unnecessary changes made by previous PR to SolutionCompon… (#583)
#574 added an out arg to `SolutionComponent.TryRemoveSolution` containing the solution that was removed. I made this change since I thought there was no way to get the removed solution for further use. Didn't notice `SplitSolution` which provides nearly the same behavior. With this PR I want to remove that out arg from `TryRemoveSolution` to keep the SolutionComponent API simple and to avoid having multiple ways of doing things. Existing code uses `SplitSolution`, I just wasn't paying attention. Feel free to deny merging this if I'm over thinking it. I think it'll help keep solution code from becoming a mess.
This commit is contained in:
@@ -76,11 +76,9 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
|||||||
_localizationManager.GetString("Container is full"));
|
_localizationManager.GetString("Container is full"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
//Remove transfer amount from attacker
|
|
||||||
if (!attackSolution.TryRemoveSolution(realTransferAmount, out var removedSolution))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
//Add poured solution to this solution
|
//Move units from attackSolution to targetSolution
|
||||||
|
var removedSolution = attackSolution.SplitSolution(realTransferAmount);
|
||||||
if (!targetSolution.TryAddSolution(removedSolution))
|
if (!targetSolution.TryAddSolution(removedSolution))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|||||||
@@ -129,11 +129,8 @@ namespace Content.Shared.Chemistry
|
|||||||
/// Remove the specified quantity from this solution.
|
/// Remove the specified quantity from this solution.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="quantity">The quantity of this solution to remove</param>
|
/// <param name="quantity">The quantity of this solution to remove</param>
|
||||||
/// <param name="removedSolution">Out arg. The removed solution. Useful for adding removed solution
|
public void RemoveSolution(int quantity)
|
||||||
/// into other solutions. For example, when pouring from one container to another.</param>
|
|
||||||
public void RemoveSolution(int quantity, out Solution removedSolution)
|
|
||||||
{
|
{
|
||||||
removedSolution = new Solution();
|
|
||||||
if(quantity <= 0)
|
if(quantity <= 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -141,7 +138,6 @@ namespace Content.Shared.Chemistry
|
|||||||
|
|
||||||
if (ratio <= 0)
|
if (ratio <= 0)
|
||||||
{
|
{
|
||||||
removedSolution = this.Clone(); //Todo: Check if clone necessary
|
|
||||||
RemoveAllSolution();
|
RemoveAllSolution();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -156,7 +152,6 @@ namespace Content.Shared.Chemistry
|
|||||||
var newQuantity = (int)Math.Floor(oldQuantity * ratio);
|
var newQuantity = (int)Math.Floor(oldQuantity * ratio);
|
||||||
|
|
||||||
_contents[i] = new ReagentQuantity(reagent.ReagentId, newQuantity);
|
_contents[i] = new ReagentQuantity(reagent.ReagentId, newQuantity);
|
||||||
removedSolution.AddReagent(reagent.ReagentId, oldQuantity - newQuantity);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TotalVolume = (int)Math.Floor(TotalVolume * ratio);
|
TotalVolume = (int)Math.Floor(TotalVolume * ratio);
|
||||||
|
|||||||
@@ -127,16 +127,13 @@ namespace Content.Shared.GameObjects.Components.Chemistry
|
|||||||
/// Attempt to remove the specified quantity from this solution
|
/// Attempt to remove the specified quantity from this solution
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="quantity">Quantity of this solution to remove</param>
|
/// <param name="quantity">Quantity of this solution to remove</param>
|
||||||
/// <param name="removedSolution">Out arg. The removed solution. Useful for adding removed solution
|
|
||||||
/// into other solutions. For example, when pouring from one container to another.</param>
|
|
||||||
/// <returns>Whether or not the solution was successfully removed</returns>
|
/// <returns>Whether or not the solution was successfully removed</returns>
|
||||||
public bool TryRemoveSolution(int quantity, out Solution removedSolution)
|
public bool TryRemoveSolution(int quantity)
|
||||||
{
|
{
|
||||||
removedSolution = new Solution();
|
|
||||||
if (CurrentVolume == 0)
|
if (CurrentVolume == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
_containedSolution.RemoveSolution(quantity, out removedSolution);
|
_containedSolution.RemoveSolution(quantity);
|
||||||
OnSolutionChanged();
|
OnSolutionChanged();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -141,14 +141,11 @@ namespace Content.Tests.Shared.Chemistry
|
|||||||
{
|
{
|
||||||
var solution = new Solution("water", 700);
|
var solution = new Solution("water", 700);
|
||||||
|
|
||||||
solution.RemoveSolution(500, out var removedSolution);
|
solution.RemoveSolution(500);
|
||||||
|
|
||||||
//Check that edited solution is correct
|
//Check that edited solution is correct
|
||||||
Assert.That(solution.GetReagentQuantity("water"), Is.EqualTo(200));
|
Assert.That(solution.GetReagentQuantity("water"), Is.EqualTo(200));
|
||||||
Assert.That(solution.TotalVolume, Is.EqualTo(200));
|
Assert.That(solution.TotalVolume, Is.EqualTo(200));
|
||||||
//Check that removed solution is correct
|
|
||||||
Assert.That(removedSolution.GetReagentQuantity("water"), Is.EqualTo(500));
|
|
||||||
Assert.That(removedSolution.TotalVolume, Is.EqualTo(500));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -156,14 +153,11 @@ namespace Content.Tests.Shared.Chemistry
|
|||||||
{
|
{
|
||||||
var solution = new Solution("water", 800);
|
var solution = new Solution("water", 800);
|
||||||
|
|
||||||
solution.RemoveSolution(1000, out var removedSolution);
|
solution.RemoveSolution(1000);
|
||||||
|
|
||||||
//Check that edited solution is correct
|
//Check that edited solution is correct
|
||||||
Assert.That(solution.GetReagentQuantity("water"), Is.EqualTo(0));
|
Assert.That(solution.GetReagentQuantity("water"), Is.EqualTo(0));
|
||||||
Assert.That(solution.TotalVolume, Is.EqualTo(0));
|
Assert.That(solution.TotalVolume, Is.EqualTo(0));
|
||||||
//Check that removed solution is correct
|
|
||||||
Assert.That(removedSolution.GetReagentQuantity("water"), Is.EqualTo(800));
|
|
||||||
Assert.That(removedSolution.TotalVolume, Is.EqualTo(800));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -173,15 +167,11 @@ namespace Content.Tests.Shared.Chemistry
|
|||||||
solution.AddReagent("water", 1000);
|
solution.AddReagent("water", 1000);
|
||||||
solution.AddReagent("fire", 2000);
|
solution.AddReagent("fire", 2000);
|
||||||
|
|
||||||
solution.RemoveSolution(1500, out var removedSolution);
|
solution.RemoveSolution(1500);
|
||||||
|
|
||||||
Assert.That(solution.GetReagentQuantity("water"), Is.EqualTo(500));
|
Assert.That(solution.GetReagentQuantity("water"), Is.EqualTo(500));
|
||||||
Assert.That(solution.GetReagentQuantity("fire"), Is.EqualTo(1000));
|
Assert.That(solution.GetReagentQuantity("fire"), Is.EqualTo(1000));
|
||||||
Assert.That(solution.TotalVolume, Is.EqualTo(1500));
|
Assert.That(solution.TotalVolume, Is.EqualTo(1500));
|
||||||
|
|
||||||
Assert.That(removedSolution.GetReagentQuantity("water"), Is.EqualTo(500));
|
|
||||||
Assert.That(removedSolution.GetReagentQuantity("fire"), Is.EqualTo(1000));
|
|
||||||
Assert.That(removedSolution.TotalVolume, Is.EqualTo(1500));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -189,13 +179,10 @@ namespace Content.Tests.Shared.Chemistry
|
|||||||
{
|
{
|
||||||
var solution = new Solution("water", 800);
|
var solution = new Solution("water", 800);
|
||||||
|
|
||||||
solution.RemoveSolution(-200, out var removedSolution);
|
solution.RemoveSolution(-200);
|
||||||
|
|
||||||
Assert.That(solution.GetReagentQuantity("water"), Is.EqualTo(800));
|
Assert.That(solution.GetReagentQuantity("water"), Is.EqualTo(800));
|
||||||
Assert.That(solution.TotalVolume, Is.EqualTo(800));
|
Assert.That(solution.TotalVolume, Is.EqualTo(800));
|
||||||
|
|
||||||
Assert.That(removedSolution.GetReagentQuantity("water"), Is.EqualTo(0));
|
|
||||||
Assert.That(removedSolution.TotalVolume, Is.EqualTo(0));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
|||||||
Reference in New Issue
Block a user