From cdfdcff5a29efeeabed972d66dbc8675d5211b13 Mon Sep 17 00:00:00 2001 From: MilenVolf Date: Wed, 4 Dec 2024 00:21:50 +0300 Subject: [PATCH 1/3] Replace obsolete TransformComponent.Anchored set --- Robust.Shared/GameObjects/EntityManager.cs | 4 ++-- .../Systems/SharedTransformSystem.Component.cs | 9 ++++++++- .../GameObjects/Systems/AnchoredSystemTests.cs | 17 +++++++++-------- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/Robust.Shared/GameObjects/EntityManager.cs b/Robust.Shared/GameObjects/EntityManager.cs index 6aa976d10b9..7f7af060e15 100644 --- a/Robust.Shared/GameObjects/EntityManager.cs +++ b/Robust.Shared/GameObjects/EntityManager.cs @@ -335,7 +335,7 @@ public virtual EntityUid CreateEntityUninitialized(string? prototypeName, MapCoo if (coordinates.MapId == MapId.Nullspace) { transform._parent = EntityUid.Invalid; - transform.Anchored = false; + _xforms.Unanchor(newEntity); return newEntity; } @@ -886,7 +886,7 @@ private protected void LoadEntity(EntityUid entity, IEntityLoadContext? context, public void InitializeAndStartEntity(EntityUid entity, MapId? mapId = null) { - var doMapInit = _mapManager.IsMapInitialized(mapId ?? TransformQuery.GetComponent(entity).MapID); + var doMapInit = _mapSystem.IsInitialized(mapId ?? TransformQuery.GetComponent(entity).MapID); InitializeAndStartEntity(entity, doMapInit); } diff --git a/Robust.Shared/GameObjects/Systems/SharedTransformSystem.Component.cs b/Robust.Shared/GameObjects/Systems/SharedTransformSystem.Component.cs index 92888a839c1..28648ea14b4 100644 --- a/Robust.Shared/GameObjects/Systems/SharedTransformSystem.Component.cs +++ b/Robust.Shared/GameObjects/Systems/SharedTransformSystem.Component.cs @@ -768,7 +768,14 @@ internal void OnHandleState(EntityUid uid, TransformComponent xform, ref Compone } else { - xform.Anchored = newState.Anchored; + if (xform.Anchored) + { + AnchorEntity(uid, xform); + } + else + { + Unanchor(uid, xform); + } } if (oldAnchored != newState.Anchored && xform.Initialized) diff --git a/Robust.UnitTesting/Shared/GameObjects/Systems/AnchoredSystemTests.cs b/Robust.UnitTesting/Shared/GameObjects/Systems/AnchoredSystemTests.cs index 236c9469357..35a9d274270 100644 --- a/Robust.UnitTesting/Shared/GameObjects/Systems/AnchoredSystemTests.cs +++ b/Robust.UnitTesting/Shared/GameObjects/Systems/AnchoredSystemTests.cs @@ -89,7 +89,8 @@ private sealed class AnchorOnInitTestSystem : EntitySystem public override void Initialize() { base.Initialize(); - SubscribeLocalEvent((e, _, _) => Transform(e).Anchored = true); + SubscribeLocalEvent((e, _, _) => + EntityManager.EntitySysManager.GetEntitySystem().AnchorEntity(e)); } } @@ -198,7 +199,7 @@ public void OnAnchored_Parent_SetToGrid() // Act sim.System().ResetCounters(); - sim.Transform(ent1).Anchored = true; + xformSys.AnchorEntity(ent1); Assert.That(sim.Transform(ent1).ParentUid, Is.EqualTo(grid.Owner)); sim.System().AssertMoved(); traversal.Enabled = true; @@ -237,7 +238,7 @@ public void OnAnchored_NonEmptyTile_Anchors() mapSys.SetTile(grid, tileIndices, new Tile(1)); // Act - sim.Transform(ent1).Anchored = true; + xformSys.AnchorEntity(ent1); Assert.That(mapSys.GetAnchoredEntities(grid, tileIndices).First(), Is.EqualTo(ent1)); Assert.That(mapSys.GetTileRef(grid, tileIndices).Tile, Is.Not.EqualTo(Tile.Empty)); @@ -263,12 +264,12 @@ public void Anchored_SetPosition_Nop() mapSys.SetTile(grid, mapSys.TileIndicesFor(grid, coordinates), new Tile(1)); var ent1 = sim.SpawnEntity(null, coordinates); // this raises MoveEvent, subscribe after - sim.Transform(ent1).Anchored = true; + xformSys.AnchorEntity(ent1); sim.System().FailOnMove = true; // Act - sim.Transform(ent1).WorldPosition = new Vector2(99, 99); - sim.Transform(ent1).LocalPosition = new Vector2(99, 99); + xformSys.SetWorldPosition(ent1, new Vector2(99, 99)); + xformSys.SetLocalPosition(ent1, new Vector2(99, 99)); Assert.That(xformSys.GetMapCoordinates(ent1), Is.EqualTo(coordinates)); sim.System().FailOnMove = false; @@ -309,7 +310,7 @@ public void Anchored_SetParentSame_Nop() var ent1 = entMan.SpawnEntity(null, coords); var tileIndices = mapSys.TileIndicesFor(grid, sim.Transform(ent1).Coordinates); mapSys.SetTile(grid, tileIndices, new Tile(1)); - sim.Transform(ent1).Anchored = true; + xformSys.AnchorEntity(ent1); // Act xformSys.SetParent(ent1, grid.Owner); @@ -428,7 +429,7 @@ public void OnUnanchored_HasPhysicsComp_IsDynamicBody() var tileIndices = mapSys.TileIndicesFor(grid, sim.Transform(ent1).Coordinates); mapSys.SetTile(grid, tileIndices, new Tile(1)); var physComp = entMan.AddComponent(ent1); - sim.Transform(ent1).Anchored = true; + xformSys.AnchorEntity(ent1); // Act xformSys.Unanchor(ent1); From 87af025c0c83153b0c6462465b7d92ae213d1d82 Mon Sep 17 00:00:00 2001 From: MilenVolf Date: Wed, 4 Dec 2024 17:27:21 +0300 Subject: [PATCH 2/3] Return part of the check from the old setter --- .../Systems/SharedTransformSystem.Component.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Robust.Shared/GameObjects/Systems/SharedTransformSystem.Component.cs b/Robust.Shared/GameObjects/Systems/SharedTransformSystem.Component.cs index 28648ea14b4..d4cb4f0fb2e 100644 --- a/Robust.Shared/GameObjects/Systems/SharedTransformSystem.Component.cs +++ b/Robust.Shared/GameObjects/Systems/SharedTransformSystem.Component.cs @@ -124,8 +124,13 @@ public bool AnchorEntity(Entity entity, Entity Date: Wed, 4 Dec 2024 17:29:04 +0300 Subject: [PATCH 3/3] I give up on this It reparents and rises move event, that were not used in obsolete setter --- .../Shared/GameObjects/Systems/AnchoredSystemTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Robust.UnitTesting/Shared/GameObjects/Systems/AnchoredSystemTests.cs b/Robust.UnitTesting/Shared/GameObjects/Systems/AnchoredSystemTests.cs index 35a9d274270..19921e4dd1b 100644 --- a/Robust.UnitTesting/Shared/GameObjects/Systems/AnchoredSystemTests.cs +++ b/Robust.UnitTesting/Shared/GameObjects/Systems/AnchoredSystemTests.cs @@ -268,7 +268,7 @@ public void Anchored_SetPosition_Nop() sim.System().FailOnMove = true; // Act - xformSys.SetWorldPosition(ent1, new Vector2(99, 99)); + sim.Transform(ent1).WorldPosition = new Vector2(99, 99); xformSys.SetLocalPosition(ent1, new Vector2(99, 99)); Assert.That(xformSys.GetMapCoordinates(ent1), Is.EqualTo(coordinates));