1
0

DungeonTests.cs 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. using System.Collections.Generic;
  2. using Content.Server.Procedural;
  3. using Content.Shared.Procedural;
  4. using Robust.Shared.Maths;
  5. using Robust.Shared.Prototypes;
  6. namespace Content.IntegrationTests.Tests.Procedural;
  7. [TestOf(typeof(DungeonSystem))]
  8. public sealed class DungeonTests
  9. {
  10. [Test]
  11. public async Task TestDungeonRoomPackBounds()
  12. {
  13. await using var pair = await PoolManager.GetServerClient();
  14. var protoManager = pair.Server.ResolveDependency<IPrototypeManager>();
  15. await pair.Server.WaitAssertion(() =>
  16. {
  17. var sizes = new HashSet<Vector2i>();
  18. foreach (var proto in protoManager.EnumeratePrototypes<DungeonRoomPrototype>())
  19. {
  20. sizes.Add(proto.Size);
  21. sizes.Add(new Vector2i(proto.Size.Y, proto.Size.X));
  22. }
  23. foreach (var pack in protoManager.EnumeratePrototypes<DungeonRoomPackPrototype>())
  24. {
  25. var rooms = new List<Box2>();
  26. for (var i = 0; i < pack.Rooms.Count; i++)
  27. {
  28. var room = pack.Rooms[i];
  29. var bounds = (Box2) room;
  30. for (var j = 0; j < rooms.Count; j++)
  31. {
  32. var existing = rooms[j];
  33. Assert.That(!existing.Intersects(bounds), $"Found overlapping rooms {i} and {j} in DungeonRoomPack {pack.ID}");
  34. }
  35. rooms.Add(bounds);
  36. // Inclusive of upper bounds as it's the edge
  37. Assert.That(room.Left >= 0 &&
  38. room.Bottom >= 0 &&
  39. room.Right <= pack.Size.X &&
  40. room.Top <= pack.Size.Y, $"Found invalid room {room} on DungeonRoomPack {pack.ID}");
  41. // Assert that anything exists at this size
  42. var rotated = new Vector2i(room.Size.Y, room.Size.X);
  43. Assert.That(sizes.Contains(room.Size) || sizes.Contains(rotated), $"Didn't find any dungeon room prototypes for {room.Size} on {pack.ID} index {i}");
  44. }
  45. }
  46. });
  47. await pair.CleanReturnAsync();
  48. }
  49. [Test]
  50. public async Task TestDungeonPresets()
  51. {
  52. await using var pair = await PoolManager.GetServerClient();
  53. var protoManager = pair.Server.ResolveDependency<IPrototypeManager>();
  54. await pair.Server.WaitAssertion(() =>
  55. {
  56. var sizes = new HashSet<Vector2i>();
  57. foreach (var pack in protoManager.EnumeratePrototypes<DungeonRoomPackPrototype>())
  58. {
  59. sizes.Add(pack.Size);
  60. sizes.Add(new Vector2i(pack.Size.Y, pack.Size.X));
  61. }
  62. foreach (var preset in protoManager.EnumeratePrototypes<DungeonPresetPrototype>())
  63. {
  64. for (var i = 0; i < preset.RoomPacks.Count; i++)
  65. {
  66. var pack = preset.RoomPacks[i];
  67. // Assert that anything exists at this size
  68. var rotated = new Vector2i(pack.Size.Y, pack.Size.X);
  69. Assert.Multiple(() =>
  70. {
  71. Assert.That(sizes.Contains(pack.Size) || sizes.Contains(rotated), $"Didn't find any dungeon room prototypes for {pack.Size} for {preset.ID} index {i}");
  72. Assert.That(pack.Bottom, Is.GreaterThanOrEqualTo(0), "All dungeon room packs need their y-axis to be above 0!");
  73. });
  74. }
  75. }
  76. });
  77. await pair.CleanReturnAsync();
  78. }
  79. }