2023-12-29 04:47:43 -08:00
|
|
|
using Content.Server.Chemistry.Containers.EntitySystems;
|
2023-12-28 20:45:42 -07:00
|
|
|
using Content.Shared.Chemistry.Reaction;
|
2023-12-29 04:47:43 -08:00
|
|
|
using Content.Shared.Chemistry.Components;
|
2021-07-27 14:54:26 +02:00
|
|
|
using Robust.Shared.GameObjects;
|
|
|
|
|
using Robust.Shared.Map;
|
|
|
|
|
using Robust.Shared.Prototypes;
|
|
|
|
|
using Robust.Shared.Utility;
|
2023-12-29 04:47:43 -08:00
|
|
|
using System.Linq;
|
2021-07-27 14:54:26 +02:00
|
|
|
|
|
|
|
|
namespace Content.IntegrationTests.Tests.Chemistry
|
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
|
|
|
|
[TestOf(typeof(ReactionPrototype))]
|
2022-06-19 20:22:28 -07:00
|
|
|
public sealed class TryAllReactionsTest
|
2021-07-27 14:54:26 +02:00
|
|
|
{
|
2023-08-05 16:16:48 +12:00
|
|
|
[TestPrototypes]
|
2021-11-28 19:25:51 -07:00
|
|
|
private const string Prototypes = @"
|
|
|
|
|
- type: entity
|
|
|
|
|
id: TestSolutionContainer
|
|
|
|
|
components:
|
|
|
|
|
- type: SolutionContainerManager
|
|
|
|
|
solutions:
|
|
|
|
|
beaker:
|
2022-12-20 04:05:02 +00:00
|
|
|
maxVol: 50
|
|
|
|
|
canMix: true";
|
2023-08-05 16:16:48 +12:00
|
|
|
|
2021-07-27 14:54:26 +02:00
|
|
|
[Test]
|
|
|
|
|
public async Task TryAllTest()
|
|
|
|
|
{
|
2023-08-25 02:56:51 +02:00
|
|
|
await using var pair = await PoolManager.GetServerClient();
|
|
|
|
|
var server = pair.Server;
|
2021-07-27 14:54:26 +02:00
|
|
|
|
|
|
|
|
var entityManager = server.ResolveDependency<IEntityManager>();
|
|
|
|
|
var prototypeManager = server.ResolveDependency<IPrototypeManager>();
|
2023-08-25 04:13:11 +02:00
|
|
|
var testMap = await pair.CreateTestMap();
|
2022-06-21 07:44:19 -07:00
|
|
|
var coordinates = testMap.GridCoords;
|
2023-12-29 04:47:43 -08:00
|
|
|
var solutionContainerSystem = entityManager.System<SolutionContainerSystem>();
|
2021-07-27 14:54:26 +02:00
|
|
|
|
|
|
|
|
foreach (var reactionPrototype in prototypeManager.EnumeratePrototypes<ReactionPrototype>())
|
|
|
|
|
{
|
|
|
|
|
//since i have no clue how to isolate each loop assert-wise im just gonna throw this one in for good measure
|
|
|
|
|
Console.WriteLine($"Testing {reactionPrototype.ID}");
|
|
|
|
|
|
2022-10-27 23:37:55 +11:00
|
|
|
EntityUid beaker = default;
|
2023-12-29 04:47:43 -08:00
|
|
|
Entity<SolutionComponent>? solutionEnt = default!;
|
|
|
|
|
Solution solution = null;
|
2021-07-27 14:54:26 +02:00
|
|
|
|
2022-06-19 20:22:28 -07:00
|
|
|
await server.WaitAssertion(() =>
|
2021-07-27 14:54:26 +02:00
|
|
|
{
|
2021-11-28 19:25:51 -07:00
|
|
|
beaker = entityManager.SpawnEntity("TestSolutionContainer", coordinates);
|
2023-12-29 04:47:43 -08:00
|
|
|
Assert.That(solutionContainerSystem
|
|
|
|
|
.TryGetSolution(beaker, "beaker", out solutionEnt, out solution));
|
2021-07-27 14:54:26 +02:00
|
|
|
foreach (var (id, reactant) in reactionPrototype.Reactants)
|
|
|
|
|
{
|
2023-07-05 21:54:25 -07:00
|
|
|
#pragma warning disable NUnit2045
|
2023-12-29 04:47:43 -08:00
|
|
|
Assert.That(solutionContainerSystem
|
|
|
|
|
.TryAddReagent(solutionEnt.Value, id, reactant.Amount, out var quantity));
|
2021-07-27 14:54:26 +02:00
|
|
|
Assert.That(reactant.Amount, Is.EqualTo(quantity));
|
2023-07-05 21:54:25 -07:00
|
|
|
#pragma warning restore NUnit2045
|
2021-07-27 14:54:26 +02:00
|
|
|
}
|
2022-02-12 17:53:54 -07:00
|
|
|
|
2023-12-29 04:47:43 -08:00
|
|
|
solutionContainerSystem.SetTemperature(solutionEnt.Value, reactionPrototype.MinimumTemperature);
|
2022-12-20 04:05:02 +00:00
|
|
|
|
|
|
|
|
if (reactionPrototype.MixingCategories != null)
|
|
|
|
|
{
|
|
|
|
|
var dummyEntity = entityManager.SpawnEntity(null, MapCoordinates.Nullspace);
|
|
|
|
|
var mixerComponent = entityManager.AddComponent<ReactionMixerComponent>(dummyEntity);
|
|
|
|
|
mixerComponent.ReactionTypes = reactionPrototype.MixingCategories;
|
2023-12-29 04:47:43 -08:00
|
|
|
solutionContainerSystem.UpdateChemicals(solutionEnt.Value, true, mixerComponent);
|
2022-12-20 04:05:02 +00:00
|
|
|
}
|
2021-07-27 14:54:26 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await server.WaitIdleAsync();
|
|
|
|
|
|
2022-06-19 20:22:28 -07:00
|
|
|
await server.WaitAssertion(() =>
|
2021-07-27 14:54:26 +02:00
|
|
|
{
|
|
|
|
|
//you just got linq'd fool
|
|
|
|
|
//(i'm sorry)
|
|
|
|
|
var foundProductsMap = reactionPrototype.Products
|
|
|
|
|
.Concat(reactionPrototype.Reactants.Where(x => x.Value.Catalyst).ToDictionary(x => x.Key, x => x.Value.Amount))
|
2021-12-05 18:09:01 +01:00
|
|
|
.ToDictionary(x => x, _ => false);
|
2023-12-29 04:47:43 -08:00
|
|
|
foreach (var (reagent, quantity) in solution.Contents)
|
2021-07-27 14:54:26 +02:00
|
|
|
{
|
2023-09-05 09:55:10 +12:00
|
|
|
Assert.That(foundProductsMap.TryFirstOrNull(x => x.Key.Key == reagent.Prototype && x.Key.Value == quantity, out var foundProduct));
|
2021-07-27 14:54:26 +02:00
|
|
|
foundProductsMap[foundProduct.Value.Key] = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Assert.That(foundProductsMap.All(x => x.Value));
|
|
|
|
|
});
|
|
|
|
|
|
2022-06-19 20:22:28 -07:00
|
|
|
}
|
2023-08-25 02:56:51 +02:00
|
|
|
await pair.CleanReturnAsync();
|
2021-07-27 14:54:26 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|