SolutionContainer refactors (#2954)

* removes unused method

* Code uncluttering (Also removed the netcode, color code, and visuals, need to rewrite)

* SolutionContainerVisualState

* Removes caching of SolutionContainer Color

* ChemicalsAdded() and ChemicalsRemoved() for updating appearance and handling reaction checks

* SolutionContainerComponentState

* Netcode

* ChemMasterComponent no longer creates a SolutionContainerComponent with new(), uses a Solution instead

* Enable nullable in SolutionContainer implementations

* Some review fixes

* uses IReadOnlyLists in ChemMaster

* Comments

* review fixes 3

* ReagentUnit documentation

* Review fixes

* spelling fix

* spelling 2

* typo

Co-authored-by: py01 <pyronetics01@gmail.com>
This commit is contained in:
py01
2021-01-10 02:41:55 -06:00
committed by GitHub
parent 0b7f286cf3
commit 7bf80fd4b8
14 changed files with 260 additions and 362 deletions

View File

@@ -49,7 +49,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
[ViewVariables] private bool Powered => !Owner.TryGetComponent(out PowerReceiverComponent? receiver) || receiver.Powered;
[ViewVariables] private readonly SolutionContainerComponent BufferSolution = new();
[ViewVariables] private readonly Solution BufferSolution = new();
[ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(ChemMasterUiKey.Key);
@@ -81,8 +81,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
ContainerManagerComponent.Ensure<ContainerSlot>($"{Name}-reagentContainerContainer", Owner);
//BufferSolution = Owner.BufferSolution
BufferSolution.Solution = new Solution();
BufferSolution.MaxVolume = ReagentUnit.New(1000);
BufferSolution.RemoveAllSolution();
UpdateUserInterface();
}
@@ -182,12 +181,12 @@ namespace Content.Server.GameObjects.Components.Chemistry
if (beaker == null)
{
return new ChemMasterBoundUserInterfaceState(Powered, false, ReagentUnit.New(0), ReagentUnit.New(0),
"", Owner.Name, new List<Solution.ReagentQuantity>(), BufferSolution.ReagentList.ToList(), _bufferModeTransfer, BufferSolution.CurrentVolume, BufferSolution.MaxVolume);
"", Owner.Name, new List<Solution.ReagentQuantity>(), BufferSolution.Contents, _bufferModeTransfer, BufferSolution.TotalVolume);
}
var solution = beaker.GetComponent<SolutionContainerComponent>();
return new ChemMasterBoundUserInterfaceState(Powered, true, solution.CurrentVolume, solution.MaxVolume,
beaker.Name, Owner.Name, solution.ReagentList.ToList(), BufferSolution.ReagentList.ToList(), _bufferModeTransfer, BufferSolution.CurrentVolume, BufferSolution.MaxVolume);
beaker.Name, Owner.Name, solution.ReagentList, BufferSolution.Contents, _bufferModeTransfer, BufferSolution.TotalVolume);
}
private void UpdateUserInterface()
@@ -222,12 +221,12 @@ namespace Content.Server.GameObjects.Components.Chemistry
var beakerSolution = beaker.GetComponent<SolutionContainerComponent>();
if (isBuffer)
{
foreach (var reagent in BufferSolution.Solution.Contents)
foreach (var reagent in BufferSolution.Contents)
{
if (reagent.ReagentId == id)
{
ReagentUnit actualAmount;
if (amount == ReagentUnit.New(-1))
if (amount == ReagentUnit.New(-1)) //amount is ReagentUnit.New(-1) when the client sends a message requesting to remove all solution from the container
{
actualAmount = ReagentUnit.Min(reagent.Quantity, beakerSolution.EmptyVolume);
}
@@ -237,7 +236,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
}
BufferSolution.Solution.RemoveReagent(id, actualAmount);
BufferSolution.RemoveReagent(id, actualAmount);
if (_bufferModeTransfer)
{
beakerSolution.TryAddReagent(id, actualAmount, out var _);
@@ -257,14 +256,14 @@ namespace Content.Server.GameObjects.Components.Chemistry
ReagentUnit actualAmount;
if (amount == ReagentUnit.New(-1))
{
actualAmount = ReagentUnit.Min(reagent.Quantity, BufferSolution.EmptyVolume);
actualAmount = reagent.Quantity;
}
else
{
actualAmount = ReagentUnit.Min(reagent.Quantity, amount, BufferSolution.EmptyVolume);
actualAmount = ReagentUnit.Min(reagent.Quantity, amount);
}
beakerSolution.TryRemoveReagent(id, actualAmount);
BufferSolution.Solution.AddReagent(id, actualAmount);
BufferSolution.AddReagent(id, actualAmount);
break;
}
}
@@ -275,12 +274,12 @@ namespace Content.Server.GameObjects.Components.Chemistry
private void TryCreatePackage(IEntity user, UiAction action, int pillAmount, int bottleAmount)
{
if (BufferSolution.CurrentVolume == 0)
if (BufferSolution.TotalVolume == 0)
return;
if (action == UiAction.CreateBottles)
{
var individualVolume = BufferSolution.CurrentVolume / ReagentUnit.New(bottleAmount);
var individualVolume = BufferSolution.TotalVolume / ReagentUnit.New(bottleAmount);
if (individualVolume < ReagentUnit.New(1))
return;
@@ -289,7 +288,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
{
var bottle = Owner.EntityManager.SpawnEntity("bottle", Owner.Transform.Coordinates);
var bufferSolution = BufferSolution.Solution.SplitSolution(actualVolume);
var bufferSolution = BufferSolution.SplitSolution(actualVolume);
bottle.TryGetComponent<SolutionContainerComponent>(out var bottleSolution);
bottleSolution?.TryAddSolution(bufferSolution);
@@ -314,7 +313,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
}
else //Pills
{
var individualVolume = BufferSolution.CurrentVolume / ReagentUnit.New(pillAmount);
var individualVolume = BufferSolution.TotalVolume / ReagentUnit.New(pillAmount);
if (individualVolume < ReagentUnit.New(1))
return;
@@ -323,7 +322,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
{
var pill = Owner.EntityManager.SpawnEntity("pill", Owner.Transform.Coordinates);
var bufferSolution = BufferSolution.Solution.SplitSolution(actualVolume);
var bufferSolution = BufferSolution.SplitSolution(actualVolume);
pill.TryGetComponent<SolutionContainerComponent>(out var pillSolution);
pillSolution?.TryAddSolution(bufferSolution);