Allow solutions to store extra reagent data (#19323)
This commit is contained in:
77
Content.Shared/Chemistry/Reagent/ReagentQuantity.cs
Normal file
77
Content.Shared/Chemistry/Reagent/ReagentQuantity.cs
Normal file
@@ -0,0 +1,77 @@
|
||||
using Content.Shared.FixedPoint;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Chemistry.Reagent;
|
||||
|
||||
/// <summary>
|
||||
/// Simple struct for storing a <see cref="ReagentId"/> & quantity tuple.
|
||||
/// </summary>
|
||||
[Serializable, NetSerializable]
|
||||
[DataDefinition]
|
||||
public partial struct ReagentQuantity : IEquatable<ReagentQuantity>
|
||||
{
|
||||
[DataField("Quantity", required:true)]
|
||||
public FixedPoint2 Quantity { get; private set; }
|
||||
|
||||
[IncludeDataField]
|
||||
[ViewVariables]
|
||||
public ReagentId Reagent { get; private set; }
|
||||
|
||||
public ReagentQuantity(string reagentId, FixedPoint2 quantity, ReagentData? data)
|
||||
: this(new ReagentId(reagentId, data), quantity)
|
||||
{
|
||||
}
|
||||
|
||||
public ReagentQuantity(ReagentId reagent, FixedPoint2 quantity)
|
||||
{
|
||||
Reagent = reagent;
|
||||
Quantity = quantity;
|
||||
}
|
||||
|
||||
public ReagentQuantity() : this(default, default)
|
||||
{
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Reagent.ToString(Quantity);
|
||||
}
|
||||
|
||||
public void Deconstruct(out string prototype, out FixedPoint2 quantity, out ReagentData? data)
|
||||
{
|
||||
prototype = Reagent.Prototype;
|
||||
quantity = Quantity;
|
||||
data = Reagent.Data;
|
||||
}
|
||||
|
||||
public void Deconstruct(out ReagentId id, out FixedPoint2 quantity)
|
||||
{
|
||||
id = Reagent;
|
||||
quantity = Quantity;
|
||||
}
|
||||
|
||||
public bool Equals(ReagentQuantity other)
|
||||
{
|
||||
return Quantity != other.Quantity && Reagent.Equals(other.Reagent);
|
||||
}
|
||||
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
return obj is ReagentQuantity other && Equals(other);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(Reagent.GetHashCode(), Quantity);
|
||||
}
|
||||
|
||||
public static bool operator ==(ReagentQuantity left, ReagentQuantity right)
|
||||
{
|
||||
return left.Equals(right);
|
||||
}
|
||||
|
||||
public static bool operator !=(ReagentQuantity left, ReagentQuantity right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user