Add autocomplete to nukearm (#14819)
This commit is contained in:
@@ -4,17 +4,17 @@ using Content.Shared.Administration;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Console;
|
||||
|
||||
namespace Content.Server.Nuke.Commands
|
||||
{
|
||||
namespace Content.Server.Nuke.Commands;
|
||||
|
||||
[UsedImplicitly]
|
||||
[AdminCommand(AdminFlags.Fun)]
|
||||
public sealed class ToggleNukeCommand : IConsoleCommand
|
||||
public sealed class ToggleNukeCommand : LocalizedCommands
|
||||
{
|
||||
public string Command => "nukearm";
|
||||
public string Description => "Toggle nuclear bomb timer. You can set timer directly. Uid is optional.";
|
||||
public string Help => "nukearm <timer> <uid>";
|
||||
[Dependency] private readonly IEntityManager _entManager = default!;
|
||||
|
||||
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
public override string Command => "nukearm";
|
||||
|
||||
public override void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
EntityUid bombUid;
|
||||
NukeComponent? bomb = null;
|
||||
@@ -29,20 +29,22 @@ namespace Content.Server.Nuke.Commands
|
||||
}
|
||||
else
|
||||
{
|
||||
var entManager = IoCManager.Resolve<IEntityManager>();
|
||||
var bombs = entManager.EntityQuery<NukeComponent>();
|
||||
var query = _entManager.EntityQueryEnumerator<NukeComponent>();
|
||||
|
||||
while (query.MoveNext(out bombUid, out bomb))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
bomb = bombs.FirstOrDefault();
|
||||
if (bomb == null)
|
||||
{
|
||||
shell.WriteError("Can't find any entity with a NukeComponent");
|
||||
shell.WriteError(Loc.GetString("cmd-nukearm-not-found"));
|
||||
return;
|
||||
}
|
||||
|
||||
bombUid = bomb.Owner;
|
||||
}
|
||||
|
||||
var nukeSys = EntitySystem.Get<NukeSystem>();
|
||||
var nukeSys = _entManager.System<NukeSystem>();
|
||||
|
||||
if (args.Length >= 1)
|
||||
{
|
||||
if (!float.TryParse(args[0], out var timer))
|
||||
@@ -56,5 +58,19 @@ namespace Content.Server.Nuke.Commands
|
||||
|
||||
nukeSys.ToggleBomb(bombUid, bomb);
|
||||
}
|
||||
|
||||
public override CompletionResult GetCompletion(IConsoleShell shell, string[] args)
|
||||
{
|
||||
if (args.Length == 1)
|
||||
{
|
||||
return CompletionResult.FromHint(Loc.GetString(Loc.GetString("cmd-nukearm-1-help")));
|
||||
}
|
||||
|
||||
if (args.Length == 2)
|
||||
{
|
||||
return CompletionResult.FromHintOptions(CompletionHelper.Components<NukeComponent>(args[1]), Loc.GetString("cmd-nukearm-2-help"));
|
||||
}
|
||||
|
||||
return CompletionResult.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
6
Resources/Locale/en-US/nuke/nuke-command.ftl
Normal file
6
Resources/Locale/en-US/nuke/nuke-command.ftl
Normal file
@@ -0,0 +1,6 @@
|
||||
cmd-nukearm-desc = Toggle nuclear bomb timer. You can set timer directly. Uid is optional.
|
||||
cmd-nukearm-help = nukearm <timer> <uid>
|
||||
cmd-nukearm-not-found = Can't find any entity with a NukeComponent.
|
||||
|
||||
cmd-nukearm-1-help = Time (in seconds)
|
||||
cmd-nukearm-2-help = Nuke
|
||||
Reference in New Issue
Block a user