]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Add autocomplete to setgamepreset command (#15399)
authorNemanja <98561806+EmoGarbage404@users.noreply.github.com>
Fri, 14 Apr 2023 01:06:06 +0000 (21:06 -0400)
committerGitHub <noreply@github.com>
Fri, 14 Apr 2023 01:06:06 +0000 (18:06 -0700)
* Add autocomplete to setgamepreset

* better ordering

Content.Server/GameTicking/Commands/SetGamePresetCommand.cs
Resources/Locale/en-US/game-ticking/set-game-preset-command.ftl

index f13ae6e3f3a02e55757dca1bad9572fd4130b7a8..83736bd92b0ef311304fd774109da43e13ae5256 100644 (file)
@@ -1,12 +1,18 @@
-using Content.Server.Administration;
+using System.Linq;
+using Content.Server.Administration;
+using Content.Server.GameTicking.Presets;
 using Content.Shared.Administration;
 using Robust.Shared.Console;
+using Robust.Shared.Prototypes;
 
 namespace Content.Server.GameTicking.Commands
 {
     [AdminCommand(AdminFlags.Round)]
-    sealed class SetGamePresetCommand : IConsoleCommand
+    public sealed class SetGamePresetCommand : IConsoleCommand
     {
+        [Dependency] private readonly IEntityManager _entity = default!;
+        [Dependency] private readonly IPrototypeManager _prototype = default!;
+
         public string Command => "setgamepreset";
         public string Description => Loc.GetString("set-game-preset-command-description", ("command", Command));
         public string Help => Loc.GetString("set-game-preset-command-help-text", ("command", Command));
@@ -19,7 +25,7 @@ namespace Content.Server.GameTicking.Commands
                 return;
             }
 
-            var ticker = EntitySystem.Get<GameTicker>();
+            var ticker = _entity.System<GameTicker>();
 
             if (!ticker.TryFindGamePreset(args[0], out var preset))
             {
@@ -30,5 +36,23 @@ namespace Content.Server.GameTicking.Commands
             ticker.SetGamePreset(preset);
             shell.WriteLine(Loc.GetString("set-game-preset-preset-set", ("preset", preset.ID)));
         }
+
+        public CompletionResult GetCompletion(IConsoleShell shell, string[] args)
+        {
+            if (args.Length == 1)
+            {
+                var gamePresets = _prototype.EnumeratePrototypes<GamePresetPrototype>()
+                    .OrderBy(p => p.ID);
+                var options = new List<string>();
+                foreach (var preset in gamePresets)
+                {
+                    options.Add(preset.ID);
+                    options.AddRange(preset.Alias);
+                }
+
+                return CompletionResult.FromHintOptions(options, "<id>");
+            }
+            return CompletionResult.Empty;
+        }
     }
 }
index c6c93f2927a83e00479a742ee13a0c9211ab8f5b..46049643cb577ccc98516b717482331af1aab9fc 100644 (file)
@@ -1,2 +1,5 @@
+set-game-preset-command-description = Sets the game preset for the current round.
+set-game-preset-command-help-text = setgamepreset <id>
+
 set-game-preset-preset-error = Unable to find game preset "{$preset}"
 set-game-preset-preset-set = Set game preset to "{$preset}"