diff --git a/Resources/Locale/en-US/commands.ftl b/Resources/Locale/en-US/commands.ftl index 896973262..c49d2d187 100644 --- a/Resources/Locale/en-US/commands.ftl +++ b/Resources/Locale/en-US/commands.ftl @@ -9,6 +9,7 @@ cmd-parse-failure-float = {$arg} is not a valid float. cmd-parse-failure-bool = {$arg} is not a valid bool. cmd-parse-failure-uid = {$arg} is not a valid entity UID. cmd-parse-failure-mapid = {$arg} is not a valid MapId. +cmd-parse-failure-grid = {$arg} is not a valid grid. cmd-parse-failure-entity-exist = UID {$arg} does not correspond to an existing entity. cmd-error-file-not-found = Could not find file: {$file}. diff --git a/Robust.Shared/Console/Commands/TeleportCommands.cs b/Robust.Shared/Console/Commands/TeleportCommands.cs index fd868b557..86e296979 100644 --- a/Robust.Shared/Console/Commands/TeleportCommands.cs +++ b/Robust.Shared/Console/Commands/TeleportCommands.cs @@ -125,7 +125,11 @@ public sealed class TeleportToCommand : LocalizedCommands [NotNullWhen(true)] out EntityUid? victimUid, [NotNullWhen(true)] out TransformComponent? transform) { - if (NetEntity.TryParse(str, out var uidNet) && _entities.TryGetEntity(uidNet, out var uid) && _entities.TryGetComponent(uid, out transform)) + if (NetEntity.TryParse(str, out var uidNet) + && _entities.TryGetEntity(uidNet, out var uid) + && _entities.TryGetComponent(uid, out transform) + && !_entities.HasComponent(uid) + && !_entities.HasComponent(uid)) { victimUid = uid; return true; @@ -191,37 +195,70 @@ sealed class TpGridCommand : LocalizedCommands [Dependency] private readonly IMapManager _map = default!; public override string Command => "tpgrid"; + public override string Description => Loc.GetString("cmd-tpgrid-desc"); + public override string Help => Loc.GetString("cmd-tpgrid-help"); public override bool RequireServerOrSingleplayer => true; public override void Execute(IConsoleShell shell, string argStr, string[] args) { if (args.Length is < 3 or > 4) { - shell.WriteError($"Usage: {Help}"); + shell.WriteError(Loc.GetString("cmd-invalid-arg-number-error")); + return; + } + + if (!NetEntity.TryParse(args[0], out var gridIdNet)) + { + shell.WriteError(Loc.GetString("cmd-parse-failure-uid", ("arg", args[0]))); + return; + } + + if (!_ent.TryGetEntity(gridIdNet, out var uid) + || !_ent.HasComponent(uid) + || _ent.HasComponent(uid)) + { + shell.WriteError(Loc.GetString("cmd-parse-failure-grid", ("arg", args[0]))); return; } - var gridIdNet = NetEntity.Parse(args[0]); var xPos = float.Parse(args[1], CultureInfo.InvariantCulture); var yPos = float.Parse(args[2], CultureInfo.InvariantCulture); - if (!_ent.TryGetEntity(gridIdNet, out var gridId) || !_ent.EntityExists(gridId)) + var gridXform = _ent.GetComponent(uid.Value); + + var mapId = gridXform.MapID; + + if (args.Length > 3) { - shell.WriteError($"Entity does not exist: {args[0]}"); + if (!int.TryParse(args[3], out var map)) + { + shell.WriteError(Loc.GetString("cmd-parse-failure-mapid", ("arg", args[3]))); + return; + } + + mapId = new MapId(map); + } + + var id = _map.GetMapEntityId(mapId); + if (id == EntityUid.Invalid) + { + shell.WriteError(Loc.GetString("cmd-parse-failure-mapid", ("arg", mapId.Value))); return; } - if (!_ent.HasComponent(gridId)) + var pos = new EntityCoordinates(_map.GetMapEntityId(mapId), new Vector2(xPos, yPos)); + _ent.System().SetCoordinates(uid.Value, pos); + } + + public override CompletionResult GetCompletion(IConsoleShell shell, string[] args) + { + return args.Length switch { - shell.WriteError($"No grid found with id {args[0]}"); - return; - } - - var gridXform = _ent.GetComponent(gridId.Value); - var mapId = args.Length == 4 ? new MapId(int.Parse(args[3])) : gridXform.MapID; - - gridXform.Coordinates = new EntityCoordinates(_map.GetMapEntityId(mapId), new Vector2(xPos, yPos)); - - shell.WriteLine("Grid was teleported."); + 1 => CompletionResult.FromHintOptions(CompletionHelper.Components(args[^1], _ent), ""), + 2 => CompletionResult.FromHint(""), + 3 => CompletionResult.FromHint(""), + 4 => CompletionResult.FromHintOptions(CompletionHelper.MapIds(_ent), "[MapId]"), + _ => CompletionResult.Empty + }; } } diff --git a/Robust.Shared/Console/CompletionHelper.cs b/Robust.Shared/Console/CompletionHelper.cs index 25e8603f4..440e66e61 100644 --- a/Robust.Shared/Console/CompletionHelper.cs +++ b/Robust.Shared/Console/CompletionHelper.cs @@ -144,31 +144,12 @@ public static class CompletionHelper public static IEnumerable MapUids(IEntityManager? entManager = null) { - IoCManager.Resolve(ref entManager); - - var query = entManager.AllEntityQueryEnumerator(); - while (query.MoveNext(out var uid, out _)) - { - yield return new CompletionOption(uid.ToString()); - } + return Components(string.Empty, entManager); } public static IEnumerable NetEntities(string text, IEntityManager? entManager = null) { - IoCManager.Resolve(ref entManager); - - foreach (var ent in entManager.GetEntities()) - { - if (!entManager.TryGetNetEntity(ent, out var netEntity)) - continue; - - var netString = netEntity.Value.ToString(); - - if (!netString.StartsWith(text)) - continue; - - yield return new CompletionOption(netString); - } + return Components(text, entManager); } public static IEnumerable Components(string text, IEntityManager? entManager = null) where T : IComponent @@ -187,7 +168,7 @@ public static class CompletionHelper if (!netString.StartsWith(text)) continue; - yield return new CompletionOption(netString); + yield return new CompletionOption(netString, metadata.EntityName); } } }