Station command improvements (#17431)

* Fix renamestation command not working

* Console completions for station commands
This commit is contained in:
Pieter-Jan Briers
2023-06-20 15:05:26 +02:00
committed by GitHub
parent ec71f1bc8e
commit 50c278b022
4 changed files with 75 additions and 1 deletions

View File

@@ -1,3 +1,4 @@
using Content.Server.Commands;
using Content.Server.Station.Components;
using Content.Server.Station.Systems;
using Content.Shared.Administration;
@@ -58,4 +59,26 @@ public sealed class AdjustStationJobCommand : IConsoleCommand
stationJobs.TrySetJobSlot(station, job, amount, true);
}
public CompletionResult GetCompletion(IConsoleShell shell, string[] args)
{
if (args.Length == 1)
{
var options = ContentCompletionHelper.StationIds(_entityManager);
return CompletionResult.FromHintOptions(options, "<station id>");
}
if (args.Length == 2)
{
var options = CompletionHelper.PrototypeIDs<JobPrototype>();
return CompletionResult.FromHintOptions(options, "<job id>");
}
if (args.Length == 3)
{
return CompletionResult.FromHint("<amount>");
}
return CompletionResult.Empty;
}
}

View File

@@ -1,3 +1,4 @@
using Content.Server.Commands;
using Content.Server.Station.Components;
using Content.Server.Station.Systems;
using Content.Shared.Administration;
@@ -40,4 +41,15 @@ public sealed class ListStationJobsCommand : IConsoleCommand
shell.WriteLine($"{job}: {amountText}");
}
}
public CompletionResult GetCompletion(IConsoleShell shell, string[] args)
{
if (args.Length == 1)
{
var options = ContentCompletionHelper.StationIds(_entityManager);
return CompletionResult.FromHintOptions(options, "<station id>");
}
return CompletionResult.Empty;
}
}

View File

@@ -1,3 +1,4 @@
using Content.Server.Commands;
using Content.Server.Station.Components;
using Content.Server.Station.Systems;
using Content.Shared.Administration;
@@ -27,7 +28,7 @@ public sealed class RenameStationCommand : IConsoleCommand
var stationSystem = _entSysManager.GetEntitySystem<StationSystem>();
if (!EntityUid.TryParse(args[0], out var station) || _entityManager.HasComponent<StationDataComponent>(station))
if (!EntityUid.TryParse(args[0], out var station) || !_entityManager.HasComponent<StationDataComponent>(station))
{
shell.WriteError(Loc.GetString("shell-argument-station-id-invalid", ("index", 1)));
return;
@@ -35,4 +36,20 @@ public sealed class RenameStationCommand : IConsoleCommand
stationSystem.RenameStation(station, args[1]);
}
public CompletionResult GetCompletion(IConsoleShell shell, string[] args)
{
if (args.Length == 1)
{
var options = ContentCompletionHelper.StationIds(_entityManager);
return CompletionResult.FromHintOptions(options, "<station id>");
}
if (args.Length == 2)
{
return CompletionResult.FromHint("<name>");
}
return CompletionResult.Empty;
}
}

View File

@@ -0,0 +1,22 @@
using Content.Server.Station.Components;
using Robust.Shared.Console;
namespace Content.Server.Commands;
/// <summary>
/// Helper functions for programming console command completions.
/// </summary>
public static class ContentCompletionHelper
{
/// <summary>
/// Return all stations, with their ID as value and name as hint.
/// </summary>
public static IEnumerable<CompletionOption> StationIds(IEntityManager entityManager)
{
var query = entityManager.EntityQueryEnumerator<StationDataComponent, MetaDataComponent>();
while (query.MoveNext(out var uid, out _, out var metaData))
{
yield return new CompletionOption(uid.ToString(), metaData.EntityName);
}
}
}