mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-09-15 14:52:35 +02:00
* Move MapManager queries to SharedMapSystem Moves all variants of FindGridsIntersecting/TryFindGridAt to SharedMapSystem Hollows out the MapManager methods and converts them into relays to SharedMapSystem * Move CreateGrid to SharedMapSystem Moves the functionality for CreateGrid and its variants to SharedMapSystem Hollows out the MapManager methods and converts them into relays for the SharedMapSystem methods Obsoletes them too Also moves over the GetAllMapGrids and GetAllGrids methods * Move RaiseOnTileChanged to SharedMapSystem Also moves the SuppressOnTileChanged flag member to SharedMapSystem Hollows out and obsoletes the MapManager versions * Move default value constants to SharedMapSystem * Converts map pausing events into LocalizedEntityCommands * Move MapManager related delegates/structs to SharedMapSystem Moves the GridCreationOptions struct to the same namespace as SharedMapSystem and converts it into a record struct Move the GridCallback delegates to the same namespace as SharedMapSystem * Move CullDeletionHistory to SharedMapSystem Well, that was less painful than I thought it would be * Actually obsolete the NetworkedMapManager method * Rename file * Doc comments for new SharedMapSystem methods * Doc comment * Doc comments * Fix access * Purge all references to IMapManagerInternal * Cull easy IMapManager references * The rest * Purge IMapManager * Private internal FindGridsIntersecting method * please die * 41 * notes --------- Co-authored-by: ArtisticRoomba <145879011+ArtisticRoomba@users.noreply.github.com>
88 lines
4.2 KiB
C#
88 lines
4.2 KiB
C#
using System.Numerics;
|
|
using System.Threading.Tasks;
|
|
using NUnit.Framework;
|
|
using Robust.Server.GameObjects;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.Map;
|
|
using Robust.Shared.Maths;
|
|
|
|
namespace Robust.UnitTesting.Shared.TransformTests;
|
|
|
|
internal sealed class GridTraversalTest : RobustIntegrationTest
|
|
{
|
|
[Test]
|
|
public async Task TestSpawnTraversal()
|
|
{
|
|
var server = StartServer();
|
|
await server.WaitIdleAsync();
|
|
|
|
var sEntMan = server.ResolveDependency<IEntityManager>();
|
|
var xforms = sEntMan.System<SharedTransformSystem>();
|
|
var mapSys = sEntMan.System<MapSystem>();
|
|
|
|
// Set up entities
|
|
MapId mapId = default!;
|
|
EntityUid map = default;
|
|
EntityUid grid = default;
|
|
Vector2 gridMapPos = default;
|
|
await server.WaitPost(() =>
|
|
{
|
|
map = sEntMan.System<SharedMapSystem>().CreateMap(out mapId);
|
|
var gridComp = mapSys.CreateGridEntity(mapId);
|
|
grid = gridComp.Owner;
|
|
mapSys.SetTile(grid, gridComp, Vector2i.Zero, new Tile(1));
|
|
var gridCentre = new EntityCoordinates(grid, .5f, .5f);
|
|
gridMapPos = xforms.ToMapCoordinates(gridCentre).Position;
|
|
});
|
|
|
|
for (int i = 0; i < 10; i++)
|
|
{
|
|
await server.WaitRunTicks(1);
|
|
}
|
|
|
|
await server.WaitPost(() =>
|
|
{
|
|
// Spawn an entity using map coordinates will get parented to the grid when spawning on the grid.
|
|
var entity = sEntMan.SpawnEntity(null, new MapCoordinates(gridMapPos, mapId));
|
|
Assert.That(sEntMan.GetComponent<TransformComponent>(entity).MapUid, Is.EqualTo(map));
|
|
Assert.That(sEntMan.GetComponent<TransformComponent>(entity).GridUid, Is.EqualTo(grid));
|
|
Assert.That(sEntMan.GetComponent<TransformComponent>(entity).ParentUid, Is.EqualTo(grid));
|
|
sEntMan.Deleted(entity);
|
|
|
|
// Spawning using map entity coords will still parent to the grid when spawning on the grid.
|
|
entity = sEntMan.SpawnEntity(null, new EntityCoordinates(map, gridMapPos));
|
|
Assert.That(sEntMan.GetComponent<TransformComponent>(entity).MapUid, Is.EqualTo(map));
|
|
Assert.That(sEntMan.GetComponent<TransformComponent>(entity).GridUid, Is.EqualTo(grid));
|
|
Assert.That(sEntMan.GetComponent<TransformComponent>(entity).ParentUid, Is.EqualTo(grid));
|
|
sEntMan.Deleted(entity);
|
|
|
|
// and using local grid coords also works.
|
|
entity = sEntMan.SpawnEntity(null, new EntityCoordinates(grid, 0.5f, 0.5f));
|
|
Assert.That(sEntMan.GetComponent<TransformComponent>(entity).MapUid, Is.EqualTo(map));
|
|
Assert.That(sEntMan.GetComponent<TransformComponent>(entity).GridUid, Is.EqualTo(grid));
|
|
Assert.That(sEntMan.GetComponent<TransformComponent>(entity).ParentUid, Is.EqualTo(grid));
|
|
sEntMan.Deleted(entity);
|
|
|
|
// Spawning an entity far away from the grid will leave it parented to the map.
|
|
entity = sEntMan.SpawnEntity(null, new MapCoordinates(new Vector2(100f, 100f), mapId));
|
|
Assert.That(sEntMan.GetComponent<TransformComponent>(entity).MapUid, Is.EqualTo(map));
|
|
Assert.That(sEntMan.GetComponent<TransformComponent>(entity).GridUid, Is.Null);
|
|
Assert.That(sEntMan.GetComponent<TransformComponent>(entity).ParentUid, Is.EqualTo(map));
|
|
sEntMan.Deleted(entity);
|
|
|
|
entity = sEntMan.SpawnEntity(null, new EntityCoordinates(map, new Vector2(100f, 100f)));
|
|
Assert.That(sEntMan.GetComponent<TransformComponent>(entity).MapUid, Is.EqualTo(map));
|
|
Assert.That(sEntMan.GetComponent<TransformComponent>(entity).GridUid, Is.Null);
|
|
Assert.That(sEntMan.GetComponent<TransformComponent>(entity).ParentUid, Is.EqualTo(map));
|
|
sEntMan.Deleted(entity);
|
|
|
|
entity = sEntMan.SpawnEntity(null, new EntityCoordinates(grid, 100f, 100f));
|
|
Assert.That(sEntMan.GetComponent<TransformComponent>(entity).MapUid, Is.EqualTo(map));
|
|
Assert.That(sEntMan.GetComponent<TransformComponent>(entity).GridUid, Is.Null);
|
|
Assert.That(sEntMan.GetComponent<TransformComponent>(entity).ParentUid, Is.EqualTo(map));
|
|
sEntMan.Deleted(entity);
|
|
});
|
|
}
|
|
}
|
|
|