Allow solutions to store extra reagent data (#19323)
This commit is contained in:
30
Content.IntegrationTests/Tests/Chemistry/ReagentDataTest.cs
Normal file
30
Content.IntegrationTests/Tests/Chemistry/ReagentDataTest.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using Content.IntegrationTests.Tests.Interaction;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Robust.Shared.Reflection;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.IntegrationTests.Tests.Chemistry;
|
||||
|
||||
[TestFixture]
|
||||
[TestOf(typeof(ReagentData))]
|
||||
public sealed class ReagentDataTest : InteractionTest
|
||||
{
|
||||
[Test]
|
||||
public async Task ReagentDataIsSerializable()
|
||||
{
|
||||
await using var pair = await PoolManager.GetServerClient();
|
||||
var reflection = pair.Server.ResolveDependency<IReflectionManager>();
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
foreach (var instance in reflection.GetAllChildren(typeof(ReagentData)))
|
||||
{
|
||||
Assert.That(instance.HasCustomAttribute<NetSerializableAttribute>(), $"{instance} must have the NetSerializable attribute.");
|
||||
Assert.That(instance.HasCustomAttribute<SerializableAttribute>(), $"{instance} must have the serializable attribute.");
|
||||
}
|
||||
});
|
||||
|
||||
await pair.CleanReturnAsync();
|
||||
}
|
||||
}
|
||||
@@ -73,8 +73,8 @@ public sealed class SolutionSystemTests
|
||||
Assert.That(containerSystem
|
||||
.TryAddSolution(beaker, solution, oilAdded));
|
||||
|
||||
solution.TryGetReagent("Water", out var water);
|
||||
solution.TryGetReagent("Oil", out var oil);
|
||||
var water = solution.GetTotalPrototypeQuantity("Water");
|
||||
var oil = solution.GetTotalPrototypeQuantity("Oil");
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(water, Is.EqualTo(waterQuantity));
|
||||
@@ -118,8 +118,8 @@ public sealed class SolutionSystemTests
|
||||
Assert.That(containerSystem
|
||||
.TryAddSolution(beaker, solution, oilAdded), Is.False);
|
||||
|
||||
solution.TryGetReagent("Water", out var water);
|
||||
solution.TryGetReagent("Oil", out var oil);
|
||||
var water = solution.GetTotalPrototypeQuantity("Water");
|
||||
var oil = solution.GetTotalPrototypeQuantity("Oil");
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(water, Is.EqualTo(waterQuantity));
|
||||
@@ -168,15 +168,15 @@ public sealed class SolutionSystemTests
|
||||
{
|
||||
Assert.That(solution.Volume, Is.EqualTo(FixedPoint2.New(threshold)));
|
||||
|
||||
solution.TryGetReagent("Water", out var waterMix);
|
||||
solution.TryGetReagent("Oil", out var oilMix);
|
||||
var waterMix = solution.GetTotalPrototypeQuantity("Water");
|
||||
var oilMix = solution.GetTotalPrototypeQuantity("Oil");
|
||||
Assert.That(waterMix, Is.EqualTo(FixedPoint2.New(threshold / (ratio + 1))));
|
||||
Assert.That(oilMix, Is.EqualTo(FixedPoint2.New(threshold / (ratio + 1) * ratio)));
|
||||
|
||||
Assert.That(overflowingSolution.Volume, Is.EqualTo(FixedPoint2.New(80)));
|
||||
|
||||
overflowingSolution.TryGetReagent("Water", out var waterOverflow);
|
||||
overflowingSolution.TryGetReagent("Oil", out var oilOverFlow);
|
||||
var waterOverflow = overflowingSolution.GetTotalPrototypeQuantity("Water");
|
||||
var oilOverFlow = overflowingSolution.GetTotalPrototypeQuantity("Oil");
|
||||
Assert.That(waterOverflow, Is.EqualTo(waterQuantity - waterMix));
|
||||
Assert.That(oilOverFlow, Is.EqualTo(oilQuantity - oilMix));
|
||||
});
|
||||
|
||||
@@ -79,9 +79,9 @@ namespace Content.IntegrationTests.Tests.Chemistry
|
||||
var foundProductsMap = reactionPrototype.Products
|
||||
.Concat(reactionPrototype.Reactants.Where(x => x.Value.Catalyst).ToDictionary(x => x.Key, x => x.Value.Amount))
|
||||
.ToDictionary(x => x, _ => false);
|
||||
foreach (var reagent in component.Contents)
|
||||
foreach (var (reagent, quantity) in component.Contents)
|
||||
{
|
||||
Assert.That(foundProductsMap.TryFirstOrNull(x => x.Key.Key == reagent.ReagentId && x.Key.Value == reagent.Quantity, out var foundProduct));
|
||||
Assert.That(foundProductsMap.TryFirstOrNull(x => x.Key.Key == reagent.Prototype && x.Key.Value == quantity, out var foundProduct));
|
||||
foundProductsMap[foundProduct.Value.Key] = true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user