1
0

FillLevelSpriteTest.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using System.Linq;
  2. using Content.Shared.Chemistry.Components;
  3. using Robust.Client.GameObjects;
  4. using Robust.Shared.GameObjects;
  5. using Robust.Shared.Prototypes;
  6. namespace Content.IntegrationTests.Tests;
  7. /// <summary>
  8. /// Tests to see if any entity prototypes specify solution fill level sprites that don't exist.
  9. /// </summary>
  10. [TestFixture]
  11. public sealed class FillLevelSpriteTest
  12. {
  13. private static readonly string[] HandStateNames = ["left", "right"];
  14. [Test]
  15. public async Task FillLevelSpritesExist()
  16. {
  17. await using var pair = await PoolManager.GetServerClient();
  18. var client = pair.Client;
  19. var protoMan = client.ResolveDependency<IPrototypeManager>();
  20. var componentFactory = client.ResolveDependency<IComponentFactory>();
  21. await client.WaitAssertion(() =>
  22. {
  23. var protos = protoMan.EnumeratePrototypes<EntityPrototype>()
  24. .Where(p => !p.Abstract)
  25. .Where(p => !pair.IsTestPrototype(p))
  26. .Where(p => p.TryGetComponent<SolutionContainerVisualsComponent>(out _, componentFactory))
  27. .OrderBy(p => p.ID)
  28. .ToList();
  29. foreach (var proto in protos)
  30. {
  31. Assert.That(proto.TryGetComponent<SolutionContainerVisualsComponent>(out var visuals, componentFactory));
  32. Assert.That(proto.TryGetComponent<SpriteComponent>(out var sprite, componentFactory));
  33. var rsi = sprite.BaseRSI;
  34. // Test base sprite fills
  35. if (!string.IsNullOrEmpty(visuals.FillBaseName))
  36. {
  37. for (var i = 1; i <= visuals.MaxFillLevels; i++)
  38. {
  39. var state = $"{visuals.FillBaseName}{i}";
  40. Assert.That(rsi.TryGetState(state, out _), @$"{proto.ID} has SolutionContainerVisualsComponent with
  41. MaxFillLevels = {visuals.MaxFillLevels}, but {rsi.Path} doesn't have state {state}!");
  42. }
  43. }
  44. // Test inhand sprite fills
  45. if (!string.IsNullOrEmpty(visuals.InHandsFillBaseName))
  46. {
  47. for (var i = 1; i <= visuals.InHandsMaxFillLevels; i++)
  48. {
  49. foreach (var handname in HandStateNames)
  50. {
  51. var state = $"inhand-{handname}{visuals.InHandsFillBaseName}{i}";
  52. Assert.That(rsi.TryGetState(state, out _), @$"{proto.ID} has SolutionContainerVisualsComponent with
  53. InHandsMaxFillLevels = {visuals.InHandsMaxFillLevels}, but {rsi.Path} doesn't have state {state}!");
  54. }
  55. }
  56. }
  57. }
  58. });
  59. await pair.CleanReturnAsync();
  60. }
  61. }