]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Add autocompletion and confirmation to docking command (#14806)
authormetalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Thu, 23 Mar 2023 12:50:50 +0000 (23:50 +1100)
committerGitHub <noreply@github.com>
Thu, 23 Mar 2023 12:50:50 +0000 (23:50 +1100)
Content.Server/Shuttles/DockCommand.cs
Resources/Locale/en-US/shuttles/docking.ftl

index 7b6c354584f055e0f51db39a7fc3dcab4702d24b..1f6d7440a872d095c02584e35778f7404e61ebb9 100644 (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;
     }
 }
index 3b8429c3fb3844617fcef4bf4d69fd2377a81629..037922582941cd4919bcb16fea074b4055def347 100644 (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