Add loc strings and completions to mapping command (#8726)

This commit is contained in:
Leon Friedrich
2022-06-09 14:38:31 +12:00
committed by GitHub
parent 08e1d3cd66
commit 1e5da87262
2 changed files with 58 additions and 14 deletions

View File

@@ -4,9 +4,12 @@
using Content.Server.Administration; using Content.Server.Administration;
using Content.Shared.Administration; using Content.Shared.Administration;
using Robust.Server.Player; using Robust.Server.Player;
using Robust.Server.Console.Commands;
using Robust.Shared.Console; using Robust.Shared.Console;
using Robust.Shared.Map; using Robust.Shared.Map;
using Robust.Shared.Utility; using Robust.Shared.Utility;
using Robust.Shared.ContentPack;
using System.Linq;
namespace Content.Server.GameTicking.Commands namespace Content.Server.GameTicking.Commands
{ {
@@ -16,14 +19,29 @@ namespace Content.Server.GameTicking.Commands
[Dependency] private readonly IEntityManager _entities = default!; [Dependency] private readonly IEntityManager _entities = default!;
public string Command => "mapping"; public string Command => "mapping";
public string Description => "Creates and teleports you to a new uninitialized map for mapping."; public string Description => Loc.GetString("cmd-mapping-desc");
public string Help => $"Usage: {Command} <MapID> <Path>"; public string Help => Loc.GetString("cmd-mapping-help");
public CompletionResult GetCompletion(IConsoleShell shell, string[] args)
{
switch (args.Length)
{
case 1:
return CompletionResult.FromHint(Loc.GetString("cmd-hint-mapping-id"));
case 2:
var res = IoCManager.Resolve<IResourceManager>();
var opts = CompletionHelper.UserFilePath(args[1], res.UserData)
.Concat(CompletionHelper.ContentFilePath(args[1], res));
return CompletionResult.FromHintOptions(opts, Loc.GetString("cmd-hint-mapping-path"));
}
return CompletionResult.Empty;
}
public void Execute(IConsoleShell shell, string argStr, string[] args) public void Execute(IConsoleShell shell, string argStr, string[] args)
{ {
if (shell.Player is not IPlayerSession player) if (shell.Player is not IPlayerSession player)
{ {
shell.WriteError("Only players can use this command"); shell.WriteError(Loc.GetString("cmd-savemap-server"));
return; return;
} }
@@ -34,7 +52,7 @@ namespace Content.Server.GameTicking.Commands
} }
#if DEBUG #if DEBUG
shell.WriteError("WARNING: The server is using a debug build. You are risking losing your changes."); shell.WriteError(Loc.GetString("cmd-mapping-warning"));
#endif #endif
var mapManager = IoCManager.Resolve<IMapManager>(); var mapManager = IoCManager.Resolve<IMapManager>();
@@ -43,26 +61,34 @@ namespace Content.Server.GameTicking.Commands
// Get the map ID to use // Get the map ID to use
if (args.Length is 1 or 2) if (args.Length is 1 or 2)
{ {
if (!int.TryParse(args[0], out var id))
if (!int.TryParse(args[0], out var intMapId))
{ {
shell.WriteError($"{args[0]} is not a valid integer."); shell.WriteError(Loc.GetString("cmd-mapping-failure-integer", ("arg", args[0])));
return; return;
} }
mapId = new MapId(id); mapId = new MapId(intMapId);
if (mapManager.MapExists(mapId))
// no loading null space
if (mapId == MapId.Nullspace)
{ {
shell.WriteError($"Map {mapId} already exists"); shell.WriteError(Loc.GetString("cmd-mapping-nullspace"));
return; return;
} }
if (mapManager.MapExists(mapId))
{
shell.WriteError(Loc.GetString("cmd-mapping-exists", ("mapId", mapId)));
return;
}
} }
else else
{ {
mapId = mapManager.NextMapId(); mapId = mapManager.NextMapId();
} }
DebugTools.Assert(args.Length <= 2);
// either load a map or create a new one. // either load a map or create a new one.
if (args.Length <= 1) if (args.Length <= 1)
shell.ExecuteCommand($"addmap {mapId} false"); shell.ExecuteCommand($"addmap {mapId} false");
@@ -72,7 +98,7 @@ namespace Content.Server.GameTicking.Commands
// was the map actually created? // was the map actually created?
if (!mapManager.MapExists(mapId)) if (!mapManager.MapExists(mapId))
{ {
shell.WriteError($"An error occurred when creating the new map."); shell.WriteError(Loc.GetString("cmd-mapping-error"));
return; return;
} }
@@ -89,9 +115,9 @@ namespace Content.Server.GameTicking.Commands
mapManager.SetMapPaused(mapId, true); mapManager.SetMapPaused(mapId, true);
if (args.Length == 2) if (args.Length == 2)
shell.WriteLine($"Created uninitialized map from file {args[1]} with id {mapId}."); shell.WriteLine(Loc.GetString("cmd-mapping-success-load",("mapId",mapId),("path", args[1])));
else else
shell.WriteLine($"Created a new uninitialized map with id {mapId}."); shell.WriteLine(Loc.GetString("cmd-mapping-success", ("mapId", mapId)));
} }
} }
} }

View File

@@ -0,0 +1,18 @@
cmd-mapping-desc = Create or load a map and teleports you to it.
cmd-mapping-help = Usage: mapping [MapID] [Path]
cmd-mapping-server = Only players can use this command.
cmd-mapping-error = An error occurred when creating the new map.
cmd-mapping-success-load = Created uninitialized map from file {$path} with id {$mapId}.
cmd-mapping-success = Created uninitialized map with id {$mapId}.
cmd-mapping-warning = WARNING: The server is using a debug build. You are risking losing your changes.
# duplicate text from engine load/save map commands.
# I CBF making this PR depend on that one.
cmd-mapping-failure-integer = {$arg} is not a valid integer.
cmd-mapping-failure-float = {$arg} is not a valid float.
cmd-mapping-failure-bool = {$arg} is not a valid bool.
cmd-mapping-nullspace = You cannot load into map 0.
cmd-hint-mapping-id = [MapID]
cmd-hint-mapping-path = [Path]
cmd-mapping-exists = Map {$mapId} already exists.