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:
@@ -226,25 +226,13 @@ namespace Content.IntegrationTests.Tests
|
|||||||
|
|
||||||
if (entManager.HasComponent<StationJobsComponent>(station))
|
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))
|
if (!NoSpawnMaps.Contains(mapProto))
|
||||||
{
|
{
|
||||||
var lateSpawns = 0;
|
var lateSpawns = 0;
|
||||||
|
|
||||||
var query = entManager.AllEntityQueryEnumerator<SpawnPointComponent>();
|
lateSpawns += GetCountLateSpawn<SpawnPointComponent>(gridUids, entManager);
|
||||||
while (query.MoveNext(out var uid, out var comp))
|
lateSpawns += GetCountLateSpawn<ContainerSpawnPointComponent>(gridUids, entManager);
|
||||||
{
|
|
||||||
if (comp.SpawnType != SpawnPointType.LateJoin
|
|
||||||
|| !xformQuery.TryGetComponent(uid, out var xform)
|
|
||||||
|| xform.GridUid == null
|
|
||||||
|| !gridUids.Contains(xform.GridUid.Value))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
lateSpawns++;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
Assert.That(lateSpawns, Is.GreaterThan(0), $"Found no latejoin spawn points on {mapProto}");
|
Assert.That(lateSpawns, Is.GreaterThan(0), $"Found no latejoin spawn points on {mapProto}");
|
||||||
}
|
}
|
||||||
@@ -283,6 +271,32 @@ namespace Content.IntegrationTests.Tests
|
|||||||
await pair.CleanReturnAsync();
|
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]
|
[Test]
|
||||||
public async Task AllMapsTested()
|
public async Task AllMapsTested()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ namespace Content.Server.Spawners.Components;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
[RegisterComponent]
|
[RegisterComponent]
|
||||||
[Access(typeof(ContainerSpawnPointSystem))]
|
[Access(typeof(ContainerSpawnPointSystem))]
|
||||||
public sealed partial class ContainerSpawnPointComponent : Component
|
public sealed partial class ContainerSpawnPointComponent : Component, ISpawnPoint
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The ID of the container that this entity will spawn players into
|
/// 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
|
/// The type of spawn point
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||||
public SpawnPointType SpawnType = SpawnPointType.Unset;
|
public SpawnPointType SpawnType { get; set; } = SpawnPointType.Unset;
|
||||||
}
|
}
|
||||||
|
|||||||
7
Content.Server/Spawners/Components/ISpawnPoint.cs
Normal file
7
Content.Server/Spawners/Components/ISpawnPoint.cs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
namespace Content.Server.Spawners.Components;
|
||||||
|
|
||||||
|
public interface ISpawnPoint
|
||||||
|
{
|
||||||
|
SpawnPointType SpawnType { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
@@ -4,7 +4,7 @@ using Robust.Shared.Prototypes;
|
|||||||
namespace Content.Server.Spawners.Components;
|
namespace Content.Server.Spawners.Components;
|
||||||
|
|
||||||
[RegisterComponent]
|
[RegisterComponent]
|
||||||
public sealed partial class SpawnPointComponent : Component
|
public sealed partial class SpawnPointComponent : Component, ISpawnPoint
|
||||||
{
|
{
|
||||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||||
|
|
||||||
@@ -12,9 +12,11 @@ public sealed partial class SpawnPointComponent : Component
|
|||||||
[DataField("job_id")]
|
[DataField("job_id")]
|
||||||
private string? _jobId;
|
private string? _jobId;
|
||||||
|
|
||||||
[ViewVariables(VVAccess.ReadWrite)]
|
/// <summary>
|
||||||
[DataField("spawn_type")]
|
/// The type of spawn point
|
||||||
public SpawnPointType SpawnType { get; private set; } = SpawnPointType.Unset;
|
/// </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);
|
public JobPrototype? Job => string.IsNullOrEmpty(_jobId) ? null : _prototypeManager.Index<JobPrototype>(_jobId);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user