Replace decimal with ReagentUnit

This commit is contained in:
PrPleGoo
2020-04-05 11:36:12 +02:00
parent 539214b1ad
commit 4e0242d47c
27 changed files with 496 additions and 253 deletions

View File

@@ -1,4 +1,5 @@
using System;
using Content.Shared.Chemistry;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization;
@@ -18,11 +19,11 @@ namespace Content.Shared.GameObjects.Components.Chemistry
[Serializable, NetSerializable]
protected sealed class InjectorComponentState : ComponentState
{
public decimal CurrentVolume { get; }
public decimal TotalVolume { get; }
public ReagentUnit CurrentVolume { get; }
public ReagentUnit TotalVolume { get; }
public InjectorToggleMode CurrentMode { get; }
public InjectorComponentState(decimal currentVolume, decimal totalVolume, InjectorToggleMode currentMode) : base(ContentNetIDs.REAGENT_INJECTOR)
public InjectorComponentState(ReagentUnit currentVolume, ReagentUnit totalVolume, InjectorToggleMode currentMode) : base(ContentNetIDs.REAGENT_INJECTOR)
{
CurrentVolume = currentVolume;
TotalVolume = totalVolume;

View File

@@ -26,8 +26,8 @@ namespace Content.Shared.GameObjects.Components.Chemistry
public class ReagentDispenserBoundUserInterfaceState : BoundUserInterfaceState
{
public readonly bool HasBeaker;
public readonly decimal BeakerCurrentVolume;
public readonly decimal BeakerMaxVolume;
public readonly ReagentUnit BeakerCurrentVolume;
public readonly ReagentUnit BeakerMaxVolume;
public readonly string ContainerName;
/// <summary>
/// A list of the reagents which this dispenser can dispense.
@@ -38,10 +38,10 @@ namespace Content.Shared.GameObjects.Components.Chemistry
/// </summary>
public readonly List<Solution.ReagentQuantity> ContainerReagents;
public readonly string DispenserName;
public readonly decimal SelectedDispenseAmount;
public readonly ReagentUnit SelectedDispenseAmount;
public ReagentDispenserBoundUserInterfaceState(bool hasBeaker, decimal beakerCurrentVolume, decimal beakerMaxVolume, string containerName,
List<ReagentDispenserInventoryEntry> inventory, string dispenserName, List<Solution.ReagentQuantity> containerReagents, decimal selectedDispenseAmount)
public ReagentDispenserBoundUserInterfaceState(bool hasBeaker, ReagentUnit beakerCurrentVolume, ReagentUnit beakerMaxVolume, string containerName,
List<ReagentDispenserInventoryEntry> inventory, string dispenserName, List<Solution.ReagentQuantity> containerReagents, ReagentUnit selectedDispenseAmount)
{
HasBeaker = hasBeaker;
BeakerCurrentVolume = beakerCurrentVolume;

View File

@@ -18,7 +18,7 @@ namespace Content.Shared.GameObjects.Components.Chemistry
[ViewVariables]
protected Solution ContainedSolution;
private decimal _maxVolume;
private ReagentUnit _maxVolume;
private SolutionCaps _capabilities;
/// <summary>
@@ -30,7 +30,7 @@ namespace Content.Shared.GameObjects.Components.Chemistry
/// The maximum volume of the container.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
public decimal MaxVolume
public ReagentUnit MaxVolume
{
get => _maxVolume;
set => _maxVolume = value; // Note that the contents won't spill out if the capacity is reduced.
@@ -40,13 +40,13 @@ namespace Content.Shared.GameObjects.Components.Chemistry
/// The total volume of all the of the reagents in the container.
/// </summary>
[ViewVariables]
public decimal CurrentVolume => ContainedSolution.TotalVolume;
public ReagentUnit CurrentVolume => ContainedSolution.TotalVolume;
/// <summary>
/// The volume without reagents remaining in the container.
/// </summary>
[ViewVariables]
public decimal EmptyVolume => MaxVolume - CurrentVolume;
public ReagentUnit EmptyVolume => MaxVolume - CurrentVolume;
/// <summary>
/// The current blended color of all the reagents in the container.
@@ -94,14 +94,14 @@ namespace Content.Shared.GameObjects.Components.Chemistry
{
base.ExposeData(serializer);
serializer.DataField(ref _maxVolume, "maxVol", 0M);
serializer.DataField(ref ContainedSolution, "contents", IoCManager.InjectDependencies(new Solution()));
serializer.DataField(ref _maxVolume, "maxVol", ReagentUnit.New(0M));
serializer.DataField(ref ContainedSolution, "contents", new Solution());
serializer.DataField(ref _capabilities, "caps", SolutionCaps.None);
}
public virtual void Init()
{
ContainedSolution = IoCManager.InjectDependencies(new Solution());
ContainedSolution = new Solution();
}
/// <inheritdoc />
@@ -118,7 +118,7 @@ namespace Content.Shared.GameObjects.Components.Chemistry
base.Shutdown();
ContainedSolution.RemoveAllSolution();
ContainedSolution = IoCManager.InjectDependencies(new Solution());
ContainedSolution = new Solution();
}
public void RemoveAllSolution()
@@ -127,7 +127,7 @@ namespace Content.Shared.GameObjects.Components.Chemistry
OnSolutionChanged();
}
public bool TryRemoveReagent(string reagentId, decimal quantity)
public bool TryRemoveReagent(string reagentId, ReagentUnit quantity)
{
if (!ContainsReagent(reagentId, out var currentQuantity)) return false;
@@ -141,7 +141,7 @@ namespace Content.Shared.GameObjects.Components.Chemistry
/// </summary>
/// <param name="quantity">Quantity of this solution to remove</param>
/// <returns>Whether or not the solution was successfully removed</returns>
public bool TryRemoveSolution(int quantity)
public bool TryRemoveSolution(ReagentUnit quantity)
{
if (CurrentVolume == 0)
return false;
@@ -151,7 +151,7 @@ namespace Content.Shared.GameObjects.Components.Chemistry
return true;
}
public Solution SplitSolution(decimal quantity)
public Solution SplitSolution(ReagentUnit quantity)
{
var solutionSplit = ContainedSolution.SplitSolution(quantity);
OnSolutionChanged();
@@ -164,7 +164,7 @@ namespace Content.Shared.GameObjects.Components.Chemistry
SubstanceColor = Color.White;
Color mixColor = default;
var runningTotalQuantity = 0M;
var runningTotalQuantity = ReagentUnit.New(0M);
foreach (var reagent in ContainedSolution)
{
@@ -176,7 +176,7 @@ namespace Content.Shared.GameObjects.Components.Chemistry
if (mixColor == default)
mixColor = proto.SubstanceColor;
mixColor = BlendRGB(mixColor, proto.SubstanceColor, (float) (reagent.Quantity / runningTotalQuantity));
mixColor = BlendRGB(mixColor, proto.SubstanceColor, reagent.Quantity.Float() / runningTotalQuantity.Float());
}
}
@@ -221,7 +221,7 @@ namespace Content.Shared.GameObjects.Components.Chemistry
/// <param name="reagentId">The reagent to check for.</param>
/// <param name="quantity">Output the quantity of the reagent if it is contained, 0 if it isn't.</param>
/// <returns>Return true if the solution contains the reagent.</returns>
public bool ContainsReagent(string reagentId, out decimal quantity)
public bool ContainsReagent(string reagentId, out ReagentUnit quantity)
{
foreach (var reagent in ContainedSolution.Contents)
{
@@ -231,7 +231,7 @@ namespace Content.Shared.GameObjects.Components.Chemistry
return true;
}
}
quantity = 0;
quantity = ReagentUnit.New(0);
return false;
}