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 <comedian_vs_clown@hotmail.com>
This commit is contained in:
778b
2024-02-25 17:54:44 +04:00
committed by GitHub
parent 1de102d08e
commit 87def406bc
4 changed files with 44 additions and 21 deletions

View 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()
{

View 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;
}

View File

@@ -0,0 +1,7 @@
namespace Content.Server.Spawners.Components;
public interface ISpawnPoint
{
SpawnPointType SpawnType { get; set; }
}

View 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);