From 87def406bc2cb3121888d162c8fe707ff937dd6f Mon Sep 17 00:00:00 2001 From: 778b <33431126+778b@users.noreply.github.com> Date: Sun, 25 Feb 2024 17:54:44 +0400 Subject: [PATCH] Added ContainerSpawnPoint check for integration test (#25446) * 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 --- .../Tests/PostMapInitTest.cs | 44 ++++++++++++------- .../ContainerSpawnPointComponent.cs | 4 +- .../Spawners/Components/ISpawnPoint.cs | 7 +++ .../Components/SpawnPointComponent.cs | 10 +++-- 4 files changed, 44 insertions(+), 21 deletions(-) create mode 100644 Content.Server/Spawners/Components/ISpawnPoint.cs diff --git a/Content.IntegrationTests/Tests/PostMapInitTest.cs b/Content.IntegrationTests/Tests/PostMapInitTest.cs index bf11430113..5356529cd8 100644 --- a/Content.IntegrationTests/Tests/PostMapInitTest.cs +++ b/Content.IntegrationTests/Tests/PostMapInitTest.cs @@ -226,25 +226,13 @@ namespace Content.IntegrationTests.Tests if (entManager.HasComponent(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(); - 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(gridUids, entManager); + lateSpawns += GetCountLateSpawn(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(List gridUids, IEntityManager entManager) + where T : ISpawnPoint, IComponent + { + var resultCount = 0; + var queryPoint = entManager.AllEntityQueryEnumerator(); +#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() { diff --git a/Content.Server/Spawners/Components/ContainerSpawnPointComponent.cs b/Content.Server/Spawners/Components/ContainerSpawnPointComponent.cs index 9782becc27..5c8e3c4186 100644 --- a/Content.Server/Spawners/Components/ContainerSpawnPointComponent.cs +++ b/Content.Server/Spawners/Components/ContainerSpawnPointComponent.cs @@ -8,7 +8,7 @@ namespace Content.Server.Spawners.Components; /// [RegisterComponent] [Access(typeof(ContainerSpawnPointSystem))] -public sealed partial class ContainerSpawnPointComponent : Component +public sealed partial class ContainerSpawnPointComponent : Component, ISpawnPoint { /// /// 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 /// [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 index 0000000000..e01841ef99 --- /dev/null +++ b/Content.Server/Spawners/Components/ISpawnPoint.cs @@ -0,0 +1,7 @@ +namespace Content.Server.Spawners.Components; + +public interface ISpawnPoint +{ + SpawnPointType SpawnType { get; set; } +} + diff --git a/Content.Server/Spawners/Components/SpawnPointComponent.cs b/Content.Server/Spawners/Components/SpawnPointComponent.cs index 5a86175a1d..5cf231f224 100644 --- a/Content.Server/Spawners/Components/SpawnPointComponent.cs +++ b/Content.Server/Spawners/Components/SpawnPointComponent.cs @@ -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; + /// + /// The type of spawn point + /// + [DataField("spawn_type"), ViewVariables(VVAccess.ReadWrite)] + public SpawnPointType SpawnType { get; set; } = SpawnPointType.Unset; public JobPrototype? Job => string.IsNullOrEmpty(_jobId) ? null : _prototypeManager.Index(_jobId);