2021-02-13 17:52:06 +01:00
|
|
|
|
#nullable enable
|
|
|
|
|
|
using Content.Shared.Physics;
|
2021-06-09 22:19:39 +02:00
|
|
|
|
using Content.Shared.Spawning;
|
2021-02-13 17:52:06 +01:00
|
|
|
|
using Robust.Shared.GameObjects;
|
2022-09-14 17:26:26 +10:00
|
|
|
|
using Robust.Shared.Physics.Systems;
|
2021-02-13 17:52:06 +01:00
|
|
|
|
|
|
|
|
|
|
namespace Content.IntegrationTests.Tests.Utility
|
|
|
|
|
|
{
|
|
|
|
|
|
[TestFixture]
|
|
|
|
|
|
[TestOf(typeof(EntitySystemExtensions))]
|
2022-06-19 20:22:28 -07:00
|
|
|
|
public sealed class EntitySystemExtensionsTest
|
2021-02-13 17:52:06 +01:00
|
|
|
|
{
|
|
|
|
|
|
private const string BlockerDummyId = "BlockerDummy";
|
|
|
|
|
|
|
2023-08-05 16:16:48 +12:00
|
|
|
|
[TestPrototypes]
|
|
|
|
|
|
private const string Prototypes = $@"
|
2021-02-13 17:52:06 +01:00
|
|
|
|
- type: entity
|
|
|
|
|
|
id: {BlockerDummyId}
|
|
|
|
|
|
name: {BlockerDummyId}
|
|
|
|
|
|
components:
|
|
|
|
|
|
- type: Physics
|
2021-12-01 18:32:37 +11:00
|
|
|
|
- type: Fixtures
|
2021-03-08 04:09:59 +11:00
|
|
|
|
fixtures:
|
2023-05-06 16:26:15 +10:00
|
|
|
|
fix1:
|
|
|
|
|
|
shape:
|
|
|
|
|
|
!type:PhysShapeAabb
|
|
|
|
|
|
bounds: ""-0.49,-0.49,0.49,0.49""
|
|
|
|
|
|
mask:
|
|
|
|
|
|
- Impassable
|
2021-02-13 17:52:06 +01:00
|
|
|
|
";
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
|
public async Task Test()
|
|
|
|
|
|
{
|
2023-08-25 02:56:51 +02:00
|
|
|
|
await using var pair = await PoolManager.GetServerClient();
|
|
|
|
|
|
var server = pair.Server;
|
2021-02-13 17:52:06 +01:00
|
|
|
|
|
2023-08-25 04:13:11 +02:00
|
|
|
|
var testMap = await pair.CreateTestMap();
|
2022-06-21 07:44:19 -07:00
|
|
|
|
var mapCoordinates = testMap.MapCoords;
|
|
|
|
|
|
var entityCoordinates = testMap.GridCoords;
|
|
|
|
|
|
|
2021-02-13 17:52:06 +01:00
|
|
|
|
var sEntityManager = server.ResolveDependency<IEntityManager>();
|
2021-07-21 21:15:12 +10:00
|
|
|
|
var broady = server.ResolveDependency<IEntitySystemManager>().GetEntitySystem<SharedBroadphaseSystem>();
|
2021-02-13 17:52:06 +01:00
|
|
|
|
|
|
|
|
|
|
await server.WaitAssertion(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
// Nothing blocking it, only entity is the grid
|
2023-07-05 21:54:25 -07:00
|
|
|
|
Assert.Multiple(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
Assert.That(sEntityManager.SpawnIfUnobstructed(null, entityCoordinates, CollisionGroup.Impassable), Is.Not.Null);
|
|
|
|
|
|
Assert.That(sEntityManager.TrySpawnIfUnobstructed(null, entityCoordinates, CollisionGroup.Impassable, out var entity));
|
|
|
|
|
|
Assert.That(entity, Is.Not.Null);
|
|
|
|
|
|
});
|
2021-02-13 17:52:06 +01:00
|
|
|
|
|
|
|
|
|
|
// Nothing blocking it, only entity is the grid
|
2023-07-05 21:54:25 -07:00
|
|
|
|
Assert.Multiple(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
Assert.That(sEntityManager.SpawnIfUnobstructed(null, mapCoordinates, CollisionGroup.Impassable), Is.Not.Null);
|
|
|
|
|
|
Assert.That(sEntityManager.TrySpawnIfUnobstructed(null, mapCoordinates, CollisionGroup.Impassable, out var entity));
|
|
|
|
|
|
Assert.That(entity, Is.Not.Null);
|
|
|
|
|
|
});
|
2021-02-13 17:52:06 +01:00
|
|
|
|
|
|
|
|
|
|
// Spawn a blocker with an Impassable mask
|
|
|
|
|
|
sEntityManager.SpawnEntity(BlockerDummyId, entityCoordinates);
|
2021-03-08 04:09:59 +11:00
|
|
|
|
broady.Update(0.016f);
|
2021-02-13 17:52:06 +01:00
|
|
|
|
|
|
|
|
|
|
// Cannot spawn something with an Impassable layer
|
2023-07-05 21:54:25 -07:00
|
|
|
|
Assert.Multiple(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
Assert.That(sEntityManager.SpawnIfUnobstructed(null, entityCoordinates, CollisionGroup.Impassable), Is.Null);
|
|
|
|
|
|
Assert.That(sEntityManager.TrySpawnIfUnobstructed(null, entityCoordinates, CollisionGroup.Impassable, out var entity), Is.False);
|
|
|
|
|
|
Assert.That(entity, Is.Null);
|
|
|
|
|
|
});
|
2021-02-13 17:52:06 +01:00
|
|
|
|
|
2023-07-05 21:54:25 -07:00
|
|
|
|
Assert.Multiple(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
Assert.That(sEntityManager.SpawnIfUnobstructed(null, mapCoordinates, CollisionGroup.Impassable), Is.Null);
|
|
|
|
|
|
Assert.That(sEntityManager.TrySpawnIfUnobstructed(null, mapCoordinates, CollisionGroup.Impassable, out var entity), Is.False);
|
|
|
|
|
|
Assert.That(entity, Is.Null);
|
|
|
|
|
|
});
|
2021-02-13 17:52:06 +01:00
|
|
|
|
|
|
|
|
|
|
// Other layers are fine
|
2023-07-05 21:54:25 -07:00
|
|
|
|
Assert.Multiple(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
Assert.That(sEntityManager.SpawnIfUnobstructed(null, entityCoordinates, CollisionGroup.MidImpassable), Is.Not.Null);
|
|
|
|
|
|
Assert.That(sEntityManager.TrySpawnIfUnobstructed(null, entityCoordinates, CollisionGroup.MidImpassable, out var entity));
|
|
|
|
|
|
Assert.That(entity, Is.Not.Null);
|
|
|
|
|
|
});
|
2021-02-13 17:52:06 +01:00
|
|
|
|
|
2023-07-05 21:54:25 -07:00
|
|
|
|
Assert.Multiple(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
Assert.That(sEntityManager.SpawnIfUnobstructed(null, mapCoordinates, CollisionGroup.MidImpassable), Is.Not.Null);
|
|
|
|
|
|
Assert.That(sEntityManager.TrySpawnIfUnobstructed(null, mapCoordinates, CollisionGroup.MidImpassable, out var entity));
|
|
|
|
|
|
Assert.That(entity, Is.Not.Null);
|
|
|
|
|
|
});
|
2021-02-13 17:52:06 +01:00
|
|
|
|
});
|
2023-08-25 02:56:51 +02:00
|
|
|
|
await pair.CleanReturnAsync();
|
2021-02-13 17:52:06 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|