Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace obsolete TransformComponent.Anchored set #5548

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Robust.Shared/GameObjects/EntityManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,13 @@ public bool AnchorEntity(Entity<TransformComponent> entity, Entity<MapGridCompon
if (grid == null)
{
if (!TryComp(entity.Comp.GridUid, out MapGridComponent? gridComp))
return false;
grid = (entity.Comp.GridUid.Value, gridComp);
{
if (!_mapManager.TryFindGridAt(GetMapCoordinates(entity.Comp), out var gridUid, out var gridMapComp))
return false;
grid = (gridUid, gridMapComp);
}
else
grid = (entity.Comp.GridUid.Value, gridComp);
Comment on lines +127 to +133
Copy link
Contributor

@metalgearsloth metalgearsloth Jan 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one I'm a bit suss on because it will fallback to the slowpath where previously it would just return false. Ideally this shouldn't even be happening because the entity itself should already have a griduid.

}

var tileIndices = _map.TileIndicesFor(grid.Value, grid.Value, entity.Comp.Coordinates);
Expand Down Expand Up @@ -767,7 +772,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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ private sealed class AnchorOnInitTestSystem : EntitySystem
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<AnchorOnInitComponent, ComponentInit>((e, _, _) => Transform(e).Anchored = true);
SubscribeLocalEvent<AnchorOnInitComponent, ComponentInit>((e, _, _) =>
EntityManager.EntitySysManager.GetEntitySystem<SharedTransformSystem>().AnchorEntity(e));
}
}

Expand Down Expand Up @@ -198,7 +199,7 @@ public void OnAnchored_Parent_SetToGrid()

// Act
sim.System<MoveEventTestSystem>().ResetCounters();
sim.Transform(ent1).Anchored = true;
xformSys.AnchorEntity(ent1);
Assert.That(sim.Transform(ent1).ParentUid, Is.EqualTo(grid.Owner));
sim.System<MoveEventTestSystem>().AssertMoved();
traversal.Enabled = true;
Expand Down Expand Up @@ -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));
Expand All @@ -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<MoveEventTestSystem>().FailOnMove = true;

// Act
sim.Transform(ent1).WorldPosition = new Vector2(99, 99);
sim.Transform(ent1).LocalPosition = new Vector2(99, 99);
xformSys.SetLocalPosition(ent1, new Vector2(99, 99));

Assert.That(xformSys.GetMapCoordinates(ent1), Is.EqualTo(coordinates));
sim.System<MoveEventTestSystem>().FailOnMove = false;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<PhysicsComponent>(ent1);
sim.Transform(ent1).Anchored = true;
xformSys.AnchorEntity(ent1);

// Act
xformSys.Unanchor(ent1);
Expand Down
Loading