]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Added ContainerSpawnPoint check for integration test (#25446)
author778b <33431126+778b@users.noreply.github.com>
Sun, 25 Feb 2024 13:54:44 +0000 (17:54 +0400)
committerGitHub <noreply@github.com>
Sun, 25 Feb 2024 13:54:44 +0000 (00:54 +1100)
* Added logic for ContainerSpawnPoint checks

* Improved with template function

* fixed nullable

* hehe

* hehe T?

* added type check before cast

* another nullable fix

* and another one

* return to old code (found typo)

* Code cleanup

---------

Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
Content.IntegrationTests/Tests/PostMapInitTest.cs
Content.Server/Spawners/Components/ContainerSpawnPointComponent.cs
Content.Server/Spawners/Components/ISpawnPoint.cs [new file with mode: 0644]
Content.Server/Spawners/Components/SpawnPointComponent.cs

index bf114301136b23bc29ef9496914de919c07dc620..5356529cd884bac91e7fc3695841e3cbb3f9f3c6 100644 (file)
@@ -226,25 +226,13 @@ namespace Content.IntegrationTests.Tests
 
                 if (entManager.HasComponent<StationJobsComponent>(station))
                 {
-                    // Test that the map has valid latejoin spawn points
+                    // Test that the map has valid latejoin spawn points or container spawn points
                     if (!NoSpawnMaps.Contains(mapProto))
                     {
                         var lateSpawns = 0;
 
-                        var query = entManager.AllEntityQueryEnumerator<SpawnPointComponent>();
-                        while (query.MoveNext(out var uid, out var comp))
-                        {
-                            if (comp.SpawnType != SpawnPointType.LateJoin
-                            || !xformQuery.TryGetComponent(uid, out var xform)
-                            || xform.GridUid == null
-                            || !gridUids.Contains(xform.GridUid.Value))
-                            {
-                                continue;
-                            }
-
-                            lateSpawns++;
-                            break;
-                        }
+                        lateSpawns += GetCountLateSpawn<SpawnPointComponent>(gridUids, entManager);
+                        lateSpawns += GetCountLateSpawn<ContainerSpawnPointComponent>(gridUids, entManager);
 
                         Assert.That(lateSpawns, Is.GreaterThan(0), $"Found no latejoin spawn points on {mapProto}");
                     }
@@ -283,6 +271,32 @@ namespace Content.IntegrationTests.Tests
             await pair.CleanReturnAsync();
         }
 
+
+
+        private static int GetCountLateSpawn<T>(List<EntityUid> gridUids, IEntityManager entManager)
+            where T : ISpawnPoint, IComponent
+        {
+            var resultCount = 0;
+            var queryPoint = entManager.AllEntityQueryEnumerator<T, TransformComponent>();
+#nullable enable
+            while (queryPoint.MoveNext(out T? comp, out var xform))
+            {
+                var spawner = (ISpawnPoint) comp;
+
+                if (spawner.SpawnType is not SpawnPointType.LateJoin
+                || xform.GridUid == null
+                || !gridUids.Contains(xform.GridUid.Value))
+                {
+                    continue;
+                }
+#nullable disable
+                resultCount++;
+                break;
+            }
+
+            return resultCount;
+        }
+
         [Test]
         public async Task AllMapsTested()
         {
index 9782becc2714d393068ed427cbf1365a62f3e353..5c8e3c4186b50e7352187d8eaebb7b753be328ca 100644 (file)
@@ -8,7 +8,7 @@ namespace Content.Server.Spawners.Components;
 /// </summary>
 [RegisterComponent]
 [Access(typeof(ContainerSpawnPointSystem))]
-public sealed partial class ContainerSpawnPointComponent : Component
+public sealed partial class ContainerSpawnPointComponent : Component, ISpawnPoint
 {
     /// <summary>
     /// The ID of the container that this entity will spawn players into
@@ -26,5 +26,5 @@ public sealed partial class ContainerSpawnPointComponent : Component
     /// The type of spawn point
     /// </summary>
     [DataField, ViewVariables(VVAccess.ReadWrite)]
-    public SpawnPointType SpawnType = SpawnPointType.Unset;
+    public SpawnPointType SpawnType { get; set; } = SpawnPointType.Unset;
 }
diff --git a/Content.Server/Spawners/Components/ISpawnPoint.cs b/Content.Server/Spawners/Components/ISpawnPoint.cs
new file mode 100644 (file)
index 0000000..e01841e
--- /dev/null
@@ -0,0 +1,7 @@
+namespace Content.Server.Spawners.Components;
+
+public interface ISpawnPoint
+{
+    SpawnPointType SpawnType { get; set; }
+}
+
index 5a86175a1d2dd3d07085002eb42950205e091d04..5cf231f224e828e0177bb874f7014b73167624fe 100644 (file)
@@ -4,7 +4,7 @@ using Robust.Shared.Prototypes;
 namespace Content.Server.Spawners.Components;
 
 [RegisterComponent]
-public sealed partial class SpawnPointComponent : Component
+public sealed partial class SpawnPointComponent : Component, ISpawnPoint
 {
     [Dependency] private readonly IPrototypeManager _prototypeManager = default!;
 
@@ -12,9 +12,11 @@ public sealed partial class SpawnPointComponent : Component
     [DataField("job_id")]
     private string? _jobId;
 
-    [ViewVariables(VVAccess.ReadWrite)]
-    [DataField("spawn_type")]
-    public SpawnPointType SpawnType { get; private set; } = SpawnPointType.Unset;
+    /// <summary>
+    /// The type of spawn point
+    /// </summary>
+    [DataField("spawn_type"), ViewVariables(VVAccess.ReadWrite)]
+    public SpawnPointType SpawnType { get; set; } = SpawnPointType.Unset;
 
     public JobPrototype? Job => string.IsNullOrEmpty(_jobId) ? null : _prototypeManager.Index<JobPrototype>(_jobId);