Some more int -> decimal conversions. Changed the use of the Solution constructor.

This commit is contained in:
PrPleGoo
2020-03-21 16:22:35 +01:00
parent dc66621804
commit 539214b1ad
6 changed files with 28 additions and 22 deletions

View File

@@ -28,13 +28,13 @@ namespace Content.Server.GameObjects.Components.Chemistry
public override string Name => "Pourable"; public override string Name => "Pourable";
private int _transferAmount; private decimal _transferAmount;
/// <summary> /// <summary>
/// The amount of solution to be transferred from this solution when clicking on other solutions with it. /// The amount of solution to be transferred from this solution when clicking on other solutions with it.
/// </summary> /// </summary>
[ViewVariables] [ViewVariables]
public int TransferAmount public decimal TransferAmount
{ {
get => _transferAmount; get => _transferAmount;
set => _transferAmount = value; set => _transferAmount = value;
@@ -43,7 +43,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
public override void ExposeData(ObjectSerializer serializer) public override void ExposeData(ObjectSerializer serializer)
{ {
base.ExposeData(serializer); base.ExposeData(serializer);
serializer.DataField(ref _transferAmount, "transferAmount", 5); serializer.DataField(ref _transferAmount, "transferAmount", 5.0M);
} }
/// <summary> /// <summary>

View File

@@ -41,7 +41,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
[ViewVariables] private string _packPrototypeId; [ViewVariables] private string _packPrototypeId;
[ViewVariables] private bool HasBeaker => _beakerContainer.ContainedEntity != null; [ViewVariables] private bool HasBeaker => _beakerContainer.ContainedEntity != null;
[ViewVariables] private int DispenseAmount = 10; [ViewVariables] private decimal _dispenseAmount = 10;
[ViewVariables] [ViewVariables]
private SolutionComponent Solution => _beakerContainer.ContainedEntity.GetComponent<SolutionComponent>(); private SolutionComponent Solution => _beakerContainer.ContainedEntity.GetComponent<SolutionComponent>();
@@ -115,22 +115,22 @@ namespace Content.Server.GameObjects.Components.Chemistry
TryClear(); TryClear();
break; break;
case UiButton.SetDispenseAmount1: case UiButton.SetDispenseAmount1:
DispenseAmount = 1; _dispenseAmount = 1;
break; break;
case UiButton.SetDispenseAmount5: case UiButton.SetDispenseAmount5:
DispenseAmount = 5; _dispenseAmount = 5;
break; break;
case UiButton.SetDispenseAmount10: case UiButton.SetDispenseAmount10:
DispenseAmount = 10; _dispenseAmount = 10;
break; break;
case UiButton.SetDispenseAmount25: case UiButton.SetDispenseAmount25:
DispenseAmount = 25; _dispenseAmount = 25;
break; break;
case UiButton.SetDispenseAmount50: case UiButton.SetDispenseAmount50:
DispenseAmount = 50; _dispenseAmount = 50;
break; break;
case UiButton.SetDispenseAmount100: case UiButton.SetDispenseAmount100:
DispenseAmount = 100; _dispenseAmount = 100;
break; break;
case UiButton.Dispense: case UiButton.Dispense:
if (HasBeaker) if (HasBeaker)
@@ -173,12 +173,12 @@ namespace Content.Server.GameObjects.Components.Chemistry
if (beaker == null) if (beaker == null)
{ {
return new ReagentDispenserBoundUserInterfaceState(false, 0, 0, return new ReagentDispenserBoundUserInterfaceState(false, 0, 0,
"", Inventory, Owner.Name, null, DispenseAmount); "", Inventory, Owner.Name, null, _dispenseAmount);
} }
var solution = beaker.GetComponent<SolutionComponent>(); var solution = beaker.GetComponent<SolutionComponent>();
return new ReagentDispenserBoundUserInterfaceState(true, solution.CurrentVolume, solution.MaxVolume, return new ReagentDispenserBoundUserInterfaceState(true, solution.CurrentVolume, solution.MaxVolume,
beaker.Name, Inventory, Owner.Name, solution.ReagentList.ToList(), DispenseAmount); beaker.Name, Inventory, Owner.Name, solution.ReagentList.ToList(), _dispenseAmount);
} }
private void UpdateUserInterface() private void UpdateUserInterface()
@@ -228,7 +228,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
if (!HasBeaker) return; if (!HasBeaker) return;
var solution = _beakerContainer.ContainedEntity.GetComponent<SolutionComponent>(); var solution = _beakerContainer.ContainedEntity.GetComponent<SolutionComponent>();
solution.TryAddReagent(Inventory[dispenseIndex].ID, DispenseAmount, out _); solution.TryAddReagent(Inventory[dispenseIndex].ID, _dispenseAmount, out _);
UpdateUserInterface(); UpdateUserInterface();
} }

View File

@@ -37,8 +37,9 @@ namespace Content.Server.GameObjects.Components.Chemistry
Init(); Init();
} }
public void Init() public override void Init()
{ {
base.Init();
_reactions = _prototypeManager.EnumeratePrototypes<ReactionPrototype>(); _reactions = _prototypeManager.EnumeratePrototypes<ReactionPrototype>();
_audioSystem = _entitySystemManager.GetEntitySystem<AudioSystem>(); _audioSystem = _entitySystemManager.GetEntitySystem<AudioSystem>();
} }

View File

@@ -119,7 +119,7 @@ namespace Content.Server.GameObjects.Components.Nutrition
} }
//Add reagents ready for transfer to bloodstream to transferSolution //Add reagents ready for transfer to bloodstream to transferSolution
var transferSolution = new Solution(); var transferSolution = IoCManager.InjectDependencies(new Solution());
foreach (var delta in _reagentDeltas.ToList()) //Use ToList here to remove entries while iterating foreach (var delta in _reagentDeltas.ToList()) //Use ToList here to remove entries while iterating
{ {
//Increment lifetime of reagents //Increment lifetime of reagents

View File

@@ -172,7 +172,7 @@ namespace Content.Shared.Chemistry
public Solution SplitSolution(decimal quantity) public Solution SplitSolution(decimal quantity)
{ {
if (quantity <= 0) if (quantity <= 0)
return new Solution(); return IoCManager.InjectDependencies(new Solution());
Solution newSolution; Solution newSolution;
@@ -183,7 +183,7 @@ namespace Content.Shared.Chemistry
return newSolution; return newSolution;
} }
newSolution = new Solution(); newSolution = IoCManager.InjectDependencies(new Solution());
var newTotalVolume = 0M; var newTotalVolume = 0M;
var ratio = (TotalVolume - quantity) / TotalVolume; var ratio = (TotalVolume - quantity) / TotalVolume;
@@ -235,7 +235,7 @@ namespace Content.Shared.Chemistry
public Solution Clone() public Solution Clone()
{ {
var volume = 0M; var volume = 0M;
var newSolution = new Solution(); var newSolution = IoCManager.InjectDependencies(new Solution());
for (var i = 0; i < _contents.Count; i++) for (var i = 0; i < _contents.Count; i++)
{ {

View File

@@ -17,7 +17,7 @@ namespace Content.Shared.GameObjects.Components.Chemistry
#pragma warning restore 649 #pragma warning restore 649
[ViewVariables] [ViewVariables]
protected Solution ContainedSolution = new Solution(); protected Solution ContainedSolution;
private decimal _maxVolume; private decimal _maxVolume;
private SolutionCaps _capabilities; private SolutionCaps _capabilities;
@@ -95,15 +95,20 @@ namespace Content.Shared.GameObjects.Components.Chemistry
base.ExposeData(serializer); base.ExposeData(serializer);
serializer.DataField(ref _maxVolume, "maxVol", 0M); serializer.DataField(ref _maxVolume, "maxVol", 0M);
serializer.DataField(ref ContainedSolution, "contents", ContainedSolution); serializer.DataField(ref ContainedSolution, "contents", IoCManager.InjectDependencies(new Solution()));
serializer.DataField(ref _capabilities, "caps", SolutionCaps.None); serializer.DataField(ref _capabilities, "caps", SolutionCaps.None);
} }
public virtual void Init()
{
ContainedSolution = IoCManager.InjectDependencies(new Solution());
}
/// <inheritdoc /> /// <inheritdoc />
protected override void Startup() protected override void Startup()
{ {
base.Startup(); base.Startup();
RecalculateColor(); RecalculateColor();
} }
@@ -113,7 +118,7 @@ namespace Content.Shared.GameObjects.Components.Chemistry
base.Shutdown(); base.Shutdown();
ContainedSolution.RemoveAllSolution(); ContainedSolution.RemoveAllSolution();
ContainedSolution = new Solution(); ContainedSolution = IoCManager.InjectDependencies(new Solution());
} }
public void RemoveAllSolution() public void RemoveAllSolution()