Cleanup WarpCommand (#36088)

* EntityCoordinates.GetGridUid -> SharedTransformSystem.GetGrid

* EntityCoordinates.GetMapId -> SharedTransformSystem.GetMapId

* Hey look, there's been a bug here this whole time

* TransformComponent.Coordinates.set -> SharedTransformSystem.SetCoordinates

* Now actually working!

* Formatting why not

* Remove unneeded GetComponent
This commit is contained in:
Tayrtahn
2025-03-25 22:17:46 -04:00
committed by GitHub
parent 9ca6353dcd
commit 462519b7da

View File

@@ -48,7 +48,7 @@ namespace Content.Server.Administration.Commands
} }
else else
{ {
if (player.Status != SessionStatus.InGame || player.AttachedEntity is not {Valid: true} playerEntity) if (player.Status != SessionStatus.InGame || player.AttachedEntity is not { Valid: true } playerEntity)
{ {
shell.WriteLine("You are not in-game!"); shell.WriteLine("You are not in-game!");
return; return;
@@ -57,14 +57,16 @@ namespace Content.Server.Administration.Commands
var currentMap = _entManager.GetComponent<TransformComponent>(playerEntity).MapID; var currentMap = _entManager.GetComponent<TransformComponent>(playerEntity).MapID;
var currentGrid = _entManager.GetComponent<TransformComponent>(playerEntity).GridUid; var currentGrid = _entManager.GetComponent<TransformComponent>(playerEntity).GridUid;
var xformSystem = _entManager.System<SharedTransformSystem>();
var found = GetWarpPointByName(location) var found = GetWarpPointByName(location)
.OrderBy(p => p.Item1, Comparer<EntityCoordinates>.Create((a, b) => .OrderBy(p => p.Item1, Comparer<EntityCoordinates>.Create((a, b) =>
{ {
// Sort so that warp points on the same grid/map are first. // Sort so that warp points on the same grid/map are first.
// So if you have two maps loaded with the same warp points, // So if you have two maps loaded with the same warp points,
// it will prefer the warp points on the map you're currently on. // it will prefer the warp points on the map you're currently on.
var aGrid = a.GetGridUid(_entManager); var aGrid = xformSystem.GetGrid(a);
var bGrid = b.GetGridUid(_entManager); var bGrid = xformSystem.GetGrid(b);
if (aGrid == bGrid) if (aGrid == bGrid)
{ {
@@ -81,8 +83,8 @@ namespace Content.Server.Administration.Commands
return 1; return 1;
} }
var mapA = a.GetMapId(_entManager); var mapA = xformSystem.GetMapId(a);
var mapB = a.GetMapId(_entManager); var mapB = xformSystem.GetMapId(b);
if (mapA == mapB) if (mapA == mapB)
{ {
@@ -117,10 +119,8 @@ namespace Content.Server.Administration.Commands
return; return;
} }
var xform = _entManager.GetComponent<TransformComponent>(playerEntity); xformSystem.SetCoordinates(playerEntity, coords);
var xformSystem = _entManager.System<SharedTransformSystem>(); xformSystem.AttachToGridOrMap(playerEntity);
xform.Coordinates = coords;
xformSystem.AttachToGridOrMap(playerEntity, xform);
if (_entManager.TryGetComponent(playerEntity, out PhysicsComponent? physics)) if (_entManager.TryGetComponent(playerEntity, out PhysicsComponent? physics))
{ {
_entManager.System<SharedPhysicsSystem>().SetLinearVelocity(playerEntity, Vector2.Zero, body: physics); _entManager.System<SharedPhysicsSystem>().SetLinearVelocity(playerEntity, Vector2.Zero, body: physics);