mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 03:30:53 +01:00
Add AttachToGridOrMap test (#3625)
Closes https://github.com/space-wizards/RobustToolbox/issues/3624
This commit is contained in:
@@ -43,5 +43,32 @@ namespace Robust.UnitTesting.Shared.GameObjects
|
||||
|
||||
Assert.That(invWorldMatrix, Is.EqualTo(xform2.InvWorldMatrix));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Asserts that when AttachToGridOrMap is called the entity remains in the same position.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void AttachToGridOrMap()
|
||||
{
|
||||
var server = RobustServerSimulation.NewSimulation().InitializeInstance();
|
||||
|
||||
var entManager = server.Resolve<IEntityManager>();
|
||||
var mapManager = server.Resolve<IMapManager>();
|
||||
|
||||
var mapId = mapManager.CreateMap();
|
||||
var grid = mapManager.CreateGrid(mapId);
|
||||
grid.SetTile(new Vector2i(0, 0), new Tile(1));
|
||||
var gridXform = entManager.GetComponent<TransformComponent>(grid.Owner);
|
||||
gridXform.LocalPosition = new Vector2(0f, 100f);
|
||||
|
||||
var ent1 = entManager.SpawnEntity(null, new EntityCoordinates(grid.Owner, Vector2.One * grid.TileSize / 2));
|
||||
var ent2 = entManager.SpawnEntity(null, new EntityCoordinates(ent1, Vector2.Zero));
|
||||
|
||||
var xform2 = entManager.GetComponent<TransformComponent>(ent2);
|
||||
Assert.That(xform2.WorldPosition, Is.EqualTo(new Vector2(0.5f, 100.5f)));
|
||||
|
||||
xform2.AttachToGridOrMap();
|
||||
Assert.That(xform2.LocalPosition, Is.EqualTo(Vector2.One * grid.TileSize / 2));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user