Files
RobustToolbox/Robust.UnitTesting/Server/GameObjects/Components/TransformIntegration_Test.cs
T
c79217ab66 Rework SetWorldPosition (#4915)
* Remove ents from containers for worldpos updates

Avoids bugs from content not checking for this every time. Physics and anything else important manually uses localposition updates so shouldn't adversely impact performance that much.

* Fixes

* Fix grid pos

* Also fix the joint setter

* Add both

* Update Robust.Shared/GameObjects/Systems/SharedTransformSystem.Component.cs

Co-authored-by: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com>

---------

Co-authored-by: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com>
2024-03-29 16:49:26 +11:00

61 lines
2.2 KiB
C#

using System.Numerics;
using NUnit.Framework;
using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
using Robust.Shared.Map;
namespace Robust.UnitTesting.Server.GameObjects.Components;
[TestFixture]
public sealed class TransformIntegration_Test
{
/// <summary>
/// Asserts that calling SetWorldPosition while in a container correctly removes the entity from its container.
/// </summary>
[Test]
public void WorldPositionContainerSet()
{
var factory = RobustServerSimulation.NewSimulation();
var sim = factory.InitializeInstance();
var entManager = sim.Resolve<IEntityManager>();
var mapManager = sim.Resolve<IMapManager>();
var containerSystem = entManager.System<SharedContainerSystem>();
var xformSystem = entManager.System<SharedTransformSystem>();
var map1Id = mapManager.CreateMap();
var map1 = mapManager.GetMapEntityId(map1Id);
var ent1 = entManager.SpawnEntity(null, new EntityCoordinates(map1, Vector2.Zero));
var ent2 = entManager.SpawnEntity(null, new EntityCoordinates(map1, Vector2.Zero));
var ent3 = entManager.SpawnEntity(null, new EntityCoordinates(map1, Vector2.Zero));
var container = containerSystem.EnsureContainer<ContainerSlot>(ent1, "a");
// Assert that setting worldpos updates parent correctly.
containerSystem.Insert(ent2, container, force: true);
Assert.That(containerSystem.IsEntityInContainer(ent2));
xformSystem.SetWorldPosition(ent2, Vector2.One);
Assert.That(!containerSystem.IsEntityInContainer(ent2));
Assert.That(xformSystem.GetWorldPosition(ent2), Is.EqualTo(Vector2.One));
// Assert that you can set recursively contained (but not directly contained) entities correctly.
containerSystem.Insert(ent2, container);
xformSystem.SetParent(ent3, ent2);
Assert.That(xformSystem.GetParentUid(ent3), Is.EqualTo(ent2));
xformSystem.SetWorldPosition(ent3, Vector2.One);
Assert.That(xformSystem.GetParentUid(ent3), Is.EqualTo(map1));
Assert.That(xformSystem.GetWorldPosition(ent3).Equals(Vector2.One));
// Cleanup
entManager.DeleteEntity(map1);
}
}