MagazineVisualsSpriteTest.cs 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using System.Collections.Generic;
  2. using Content.Client.Weapons.Ranged.Components;
  3. using Content.Shared.Prototypes;
  4. using Robust.Client.GameObjects;
  5. using Robust.Shared.GameObjects;
  6. using Robust.Shared.Prototypes;
  7. namespace Content.IntegrationTests.Tests;
  8. /// <summary>
  9. /// Tests all entity prototypes with the MagazineVisualsComponent.
  10. /// </summary>
  11. [TestFixture]
  12. public sealed class MagazineVisualsSpriteTest
  13. {
  14. [Test]
  15. public async Task MagazineVisualsSpritesExist()
  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. Assert.Multiple(() =>
  24. {
  25. foreach (var proto in protoMan.EnumeratePrototypes<EntityPrototype>())
  26. {
  27. if (proto.Abstract || pair.IsTestPrototype(proto))
  28. continue;
  29. if (!proto.TryGetComponent<MagazineVisualsComponent>(out var visuals, componentFactory))
  30. continue;
  31. Assert.That(proto.TryGetComponent<SpriteComponent>(out var sprite, componentFactory),
  32. @$"{proto.ID} has MagazineVisualsComponent but no SpriteComponent.");
  33. Assert.That(proto.HasComponent<AppearanceComponent>(componentFactory),
  34. @$"{proto.ID} has MagazineVisualsComponent but no AppearanceComponent.");
  35. var toTest = new List<(int, string)>();
  36. if (sprite.LayerMapTryGet(GunVisualLayers.Mag, out var magLayerId))
  37. toTest.Add((magLayerId, ""));
  38. if (sprite.LayerMapTryGet(GunVisualLayers.MagUnshaded, out var magUnshadedLayerId))
  39. toTest.Add((magUnshadedLayerId, "-unshaded"));
  40. Assert.That(toTest, Is.Not.Empty,
  41. @$"{proto.ID} has MagazineVisualsComponent but no Mag or MagUnshaded layer map.");
  42. var start = visuals.ZeroVisible ? 0 : 1;
  43. foreach (var (id, midfix) in toTest)
  44. {
  45. Assert.That(sprite.TryGetLayer(id, out var layer));
  46. var rsi = layer.ActualRsi;
  47. for (var i = start; i < visuals.MagSteps; i++)
  48. {
  49. var state = $"{visuals.MagState}{midfix}-{i}";
  50. Assert.That(rsi.TryGetState(state, out _),
  51. @$"{proto.ID} has MagazineVisualsComponent with MagSteps = {visuals.MagSteps}, but {rsi.Path} doesn't have state {state}!");
  52. }
  53. // MagSteps includes the 0th step, so sometimes people are off by one.
  54. var extraState = $"{visuals.MagState}{midfix}-{visuals.MagSteps}";
  55. Assert.That(rsi.TryGetState(extraState, out _), Is.False,
  56. @$"{proto.ID} has MagazineVisualsComponent with MagSteps = {visuals.MagSteps}, but more states exist!");
  57. }
  58. }
  59. });
  60. });
  61. await pair.CleanReturnAsync();
  62. }
  63. }