Add autocompletion and confirmation to docking command (#14806)

This commit is contained in:
metalgearsloth 2023-03-23 23:50:50 +11:00 committed by GitHub
parent 635aa7e999
commit 86edcb960d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 7 deletions

View File

@ -12,41 +12,65 @@ public sealed class DockCommand : IConsoleCommand
[Dependency] private readonly IEntityManager _entManager = default!;
public string Command => "dock";
public string Description => $"Attempts to dock 2 airlocks together. Doesn't check whether it is valid.";
public string Help => $"{Command} <airlock entityuid1> <airlock entityuid2>";
public string Description => Loc.GetString("cmd-dock-desc");
public string Help => Loc.GetString("cmd-dock-help");
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (args.Length != 2)
{
shell.WriteError($"Invalid number of args supplied");
shell.WriteError(Loc.GetString("cmd-dock-args"));
return;
}
if (!EntityUid.TryParse(args[0], out var airlock1))
{
shell.WriteError($"Invalid EntityUid {args[0]}");
shell.WriteError(Loc.GetString("cmd-dock-invalid", ("entity", args[0])));
return;
}
if (!EntityUid.TryParse(args[1], out var airlock2))
{
shell.WriteError($"Invalid EntityUid {args[1]}");
shell.WriteError(Loc.GetString("cmd-dock-invalid", ("entity", args[1])));
return;
}
if (!_entManager.TryGetComponent(airlock1, out DockingComponent? dock1))
{
shell.WriteError($"No docking component found on {airlock1}");
shell.WriteError(Loc.GetString("cmd-dock-found", ("airlock", airlock1)));
return;
}
if (!_entManager.TryGetComponent(airlock2, out DockingComponent? dock2))
{
shell.WriteError($"No docking component found on {airlock2}");
shell.WriteError(Loc.GetString("cmd-dock-found", ("airlock", airlock2)));
return;
}
var dockSystem = _entManager.System<DockingSystem>();
dockSystem.Dock(airlock1, dock1, airlock2, dock2);
if (dock1.DockedWith == airlock2)
{
shell.WriteLine(Loc.GetString("cmd-dock-success"));
}
else
{
shell.WriteError(Loc.GetString("cmd-dock-fail"));
}
}
public CompletionResult GetCompletion(IConsoleShell shell, string[] args)
{
if (args.Length == 1)
{
return CompletionResult.FromOptions(CompletionHelper.Components<DockingComponent>(args[0], _entManager));
}
if (args.Length == 2)
{
return CompletionResult.FromOptions(CompletionHelper.Components<DockingComponent>(args[1], _entManager));
}
return CompletionResult.Empty;
}
}

View File

@ -1,2 +1,11 @@
docking-component-dock = Dock
docking-component-undock = Undock
cmd-dock-desc = Attempts to dock 2 airlocks together. Doesn't check whether it is valid.
cmd-dock-help = dock <airlock entityuid1> <airlock entityuid2>
cmd-dock-args = Invalid number of args
cmd-dock-invalid = Invalid EntityUid {$entity}
cmd-dock-found = No docking component found on {$airlock}
cmd-dock-success = Successfully docked
cmd-dock-fail = Unable to dock