mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-09-16 07:12:27 +02:00
* Removed SnapGridOffset, there is only center now. * SnapGridComponent methods are now static. * Removed SnapGridComponent.OnPositionChanged. * Refactored static functions off SnapGridComponent to MapGrid. Refactored away usages of SnapGridComponent.Position. * Added Transform.Anchored for checking if an entity is a tile entity. More refactoring for static MapGrid functions. * Static snapgrid methods on MapGrid are no longer static. * Removed IMapGrid.SnapSize, it is now always equal to the IMapGrid.TileSize. * Add setter to ITransformComponent.Anchored. Removed direct references to SnapGridComponent from content. * Grid functions now deal with EntityUids instead of SnapGridComponents. Began renaming public API functions from SnapGrid to Anchor. * Add some unit tests. * SnapGridComponent now anchors itself in startup, instead of Initialize (sending directed events in init is an error).
52 lines
1.7 KiB
C#
52 lines
1.7 KiB
C#
using NUnit.Framework;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.Map;
|
|
using Robust.Shared.Maths;
|
|
using Robust.UnitTesting.Server;
|
|
|
|
namespace Robust.UnitTesting.Shared.GameObjects.Systems
|
|
{
|
|
[TestFixture, Parallelizable]
|
|
class TransformSystemTests
|
|
{
|
|
private static ISimulation SimulationFactory()
|
|
{
|
|
var sim = RobustServerSimulation
|
|
.NewSimulation()
|
|
.InitializeInstance();
|
|
|
|
// Adds the map with id 1, and spawns entity 1 as the map entity.
|
|
sim.AddMap(1);
|
|
|
|
return sim;
|
|
}
|
|
|
|
/// <summary>
|
|
/// When the local position of the transform changes, a MoveEvent is raised.
|
|
/// </summary>
|
|
[Test]
|
|
public void OnMove_LocalPosChanged_RaiseMoveEvent()
|
|
{
|
|
var sim = SimulationFactory();
|
|
var entMan = sim.Resolve<IEntityManager>();
|
|
|
|
var subscriber = new Subscriber();
|
|
int calledCount = 0;
|
|
entMan.EventBus.SubscribeEvent<MoveEvent>(EventSource.Local, subscriber, MoveEventHandler);
|
|
var ent1 = entMan.SpawnEntity(null, new MapCoordinates(Vector2.Zero, new MapId(1)));
|
|
|
|
ent1.Transform.LocalPosition = Vector2.One;
|
|
|
|
Assert.That(calledCount, Is.EqualTo(1));
|
|
void MoveEventHandler(MoveEvent ev)
|
|
{
|
|
calledCount++;
|
|
Assert.That(ev.OldPosition, Is.EqualTo(new EntityCoordinates(new EntityUid(1), Vector2.Zero)));
|
|
Assert.That(ev.NewPosition, Is.EqualTo(new EntityCoordinates(new EntityUid(1), Vector2.One)));
|
|
}
|
|
}
|
|
|
|
private class Subscriber : IEntityEventSubscriber { }
|
|
}
|
|
}
|