SolutionContainerComponent refactors (#2746)
* Moves ContainsReagent from SolutionContainer to Solution * GetMajorReagentId from SOlutionContainer to Solution * Makes capability checks use HasFlag * Moves Solution Color calculation from SolutionContainer to Solution * Replaces SolutionContainerCaps.NoExamine with CanExamine * Misc SolutionContainer.Capabilities yaml cleanup * Removes HasFlag usage in SolutionContainerComponent Co-authored-by: py01 <pyronetics01@gmail.com>
This commit is contained in:
@@ -1,8 +1,12 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using Robust.Shared.Interfaces.Serialization;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Utility;
|
||||
using Robust.Shared.ViewVariables;
|
||||
@@ -27,6 +31,8 @@ namespace Content.Shared.Chemistry
|
||||
[ViewVariables]
|
||||
public ReagentUnit TotalVolume { get; private set; }
|
||||
|
||||
public Color Color => GetColor();
|
||||
|
||||
/// <summary>
|
||||
/// Constructs an empty solution (ex. an empty beaker).
|
||||
/// </summary>
|
||||
@@ -57,6 +63,32 @@ namespace Content.Shared.Chemistry
|
||||
() => _contents);
|
||||
}
|
||||
|
||||
public bool ContainsReagent(string reagentId, out ReagentUnit quantity)
|
||||
{
|
||||
foreach (var reagent in Contents)
|
||||
{
|
||||
if (reagent.ReagentId == reagentId)
|
||||
{
|
||||
quantity = reagent.Quantity;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
quantity = ReagentUnit.New(0);
|
||||
return false;
|
||||
}
|
||||
|
||||
public string GetPrimaryReagentId()
|
||||
{
|
||||
if (Contents.Count == 0)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
var majorReagent = Contents.OrderByDescending(reagent => reagent.Quantity).First(); ;
|
||||
return majorReagent.ReagentId;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a given quantity of a reagent directly into the solution.
|
||||
/// </summary>
|
||||
@@ -231,6 +263,37 @@ namespace Content.Shared.Chemistry
|
||||
TotalVolume += otherSolution.TotalVolume;
|
||||
}
|
||||
|
||||
private Color GetColor()
|
||||
{
|
||||
if (TotalVolume == 0)
|
||||
{
|
||||
return Color.Transparent;
|
||||
}
|
||||
|
||||
Color mixColor = default;
|
||||
var runningTotalQuantity = ReagentUnit.New(0);
|
||||
|
||||
foreach (var reagent in Contents)
|
||||
{
|
||||
runningTotalQuantity += reagent.Quantity;
|
||||
|
||||
if (!IoCManager.Resolve<IPrototypeManager>().TryIndex(reagent.ReagentId, out ReagentPrototype proto))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (mixColor == default)
|
||||
{
|
||||
mixColor = proto.SubstanceColor;
|
||||
continue;
|
||||
}
|
||||
|
||||
var interpolateValue = (1 / runningTotalQuantity.Float()) * reagent.Quantity.Float();
|
||||
mixColor = Color.InterpolateBetween(mixColor, proto.SubstanceColor, interpolateValue);
|
||||
}
|
||||
return mixColor;
|
||||
}
|
||||
|
||||
public Solution Clone()
|
||||
{
|
||||
var volume = ReagentUnit.New(0);
|
||||
|
||||
Reference in New Issue
Block a user