mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-14 19:29:36 +01:00
Prevent /tpgrid from moving grids to nullspace (#4798)
* Prevent `/tpgrid` from moving grids to nullspace * Undo breaking change * a
This commit is contained in:
@@ -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}.
|
||||
|
||||
@@ -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<MapComponent>(uid)
|
||||
&& !_entities.HasComponent<MapGridComponent>(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<MapGridComponent>(uid)
|
||||
|| _ent.HasComponent<MapComponent>(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<TransformComponent>(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<MapGridComponent>(gridId))
|
||||
var pos = new EntityCoordinates(_map.GetMapEntityId(mapId), new Vector2(xPos, yPos));
|
||||
_ent.System<SharedTransformSystem>().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<TransformComponent>(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<MapGridComponent>(args[^1], _ent), "<GridUid>"),
|
||||
2 => CompletionResult.FromHint("<x>"),
|
||||
3 => CompletionResult.FromHint("<y>"),
|
||||
4 => CompletionResult.FromHintOptions(CompletionHelper.MapIds(_ent), "[MapId]"),
|
||||
_ => CompletionResult.Empty
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,31 +144,12 @@ public static class CompletionHelper
|
||||
|
||||
public static IEnumerable<CompletionOption> MapUids(IEntityManager? entManager = null)
|
||||
{
|
||||
IoCManager.Resolve(ref entManager);
|
||||
|
||||
var query = entManager.AllEntityQueryEnumerator<MapComponent>();
|
||||
while (query.MoveNext(out var uid, out _))
|
||||
{
|
||||
yield return new CompletionOption(uid.ToString());
|
||||
}
|
||||
return Components<MapComponent>(string.Empty, entManager);
|
||||
}
|
||||
|
||||
public static IEnumerable<CompletionOption> 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<MetaDataComponent>(text, entManager);
|
||||
}
|
||||
|
||||
public static IEnumerable<CompletionOption> Components<T>(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user