update mapping command (#6925)

This commit is contained in:
Leon Friedrich
2022-02-28 14:21:15 +13:00
committed by GitHub
parent 71fccfdd97
commit 9a54ea67c4
2 changed files with 44 additions and 69 deletions

View File

@@ -72,30 +72,4 @@ namespace Content.Client.Commands
EntitySystem.Get<PopupSystem>().PopupCursor(message); EntitySystem.Get<PopupSystem>().PopupCursor(message);
} }
} }
internal sealed class MappingCommand : IConsoleCommand
{
public string Command => "mapping";
public string Description => "Creates and teleports you to a new uninitialized map for mapping.";
public string Help => $"Usage: {Command} <mapname> / {Command} <id> <mapname>";
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (args.Length == 0)
{
shell.WriteLine(Help);
return;
}
#if DEBUG
shell.WriteError("WARNING: The client is using a debug build. You are risking losing your changes.");
#endif
shell.ConsoleHost.RegisteredCommands["togglelight"].Execute(shell, string.Empty, Array.Empty<string>());
shell.ConsoleHost.RegisteredCommands["showsubfloorforever"].Execute(shell, string.Empty, Array.Empty<string>());
shell.ConsoleHost.RegisteredCommands["showmarkers"].Execute(shell, string.Empty, Array.Empty<string>());
shell.RemoteExecuteCommand(argStr);
}
}
} }

View File

@@ -1,16 +1,11 @@
// ReSharper disable once RedundantUsingDirective // ReSharper disable once RedundantUsingDirective
// Used to warn the player in big red letters in debug mode // Used to warn the player in big red letters in debug mode
using System.Linq;
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.Shared.Console; using Robust.Shared.Console;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map; using Robust.Shared.Map;
using Robust.Shared.Prototypes;
using Robust.Shared.Timing;
using Robust.Shared.Utility; using Robust.Shared.Utility;
namespace Content.Server.GameTicking.Commands namespace Content.Server.GameTicking.Commands
@@ -22,7 +17,7 @@ namespace Content.Server.GameTicking.Commands
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 => "Creates and teleports you to a new uninitialized map for mapping.";
public string Help => $"Usage: {Command} <mapname> / {Command} <id> <mapname>"; public string Help => $"Usage: {Command} [mapname] [id]";
public void Execute(IConsoleShell shell, string argStr, string[] args) public void Execute(IConsoleShell shell, string argStr, string[] args)
{ {
@@ -33,65 +28,71 @@ namespace Content.Server.GameTicking.Commands
return; return;
} }
if (args.Length > 2)
{
shell.WriteLine(Help);
return;
}
#if DEBUG #if DEBUG
shell.WriteError("WARNING: The server is using a debug build. You are risking losing your changes."); shell.WriteError("WARNING: The server is using a debug build. You are risking losing your changes.");
#endif #endif
var mapManager = IoCManager.Resolve<IMapManager>(); var mapManager = IoCManager.Resolve<IMapManager>();
int mapId; MapId mapId;
string mapName;
switch (args.Length) // Get the map ID to use
if (args.Length == 2)
{ {
case 1: if (!int.TryParse(args[1], out var id))
if (player.AttachedEntity == null) {
{ shell.WriteError($"{args[1]} is not a valid integer.");
shell.WriteError("The map name argument cannot be omitted if you have no entity.");
return;
}
mapId = (int) mapManager.NextMapId();
mapName = args[0];
break;
case 2:
if (!int.TryParse(args[0], out var id))
{
shell.WriteError($"{args[0]} is not a valid integer.");
return;
}
mapId = id;
mapName = args[1];
break;
default:
shell.WriteLine(Help);
return; return;
}
mapId = new MapId(id);
if (mapManager.MapExists(mapId))
{
shell.WriteError($"Map {mapId} already exists");
return;
}
}
else
{
mapId = mapManager.NextMapId();
} }
// loadmap checks for this on its own but we want to avoid running our other commands. // either load a map or create a new one.
if (mapManager.MapExists(new MapId(mapId))) if (args.Length == 0)
shell.ExecuteCommand($"addmap {mapId}");
else
shell.ExecuteCommand($"loadmap {mapId} \"{CommandParsing.Escape(args[0])}\"");
// was the map actually created?
if (!mapManager.MapExists(mapId))
{ {
shell.WriteError($"Map {mapId} already exists"); shell.WriteError($"An error occurred when creating the new map.");
return; return;
} }
shell.ExecuteCommand("sudo cvar events.enabled false"); // map successfully created. run misc helpful mapping commands
shell.ExecuteCommand($"loadmap {mapId} \"{CommandParsing.Escape(mapName)}\" true"); if (player.AttachedEntity is { Valid: true } playerEntity &&
if (player.AttachedEntity is {Valid: true} playerEntity &&
_entities.GetComponent<MetaDataComponent>(playerEntity).EntityPrototype?.ID != "AdminObserver") _entities.GetComponent<MetaDataComponent>(playerEntity).EntityPrototype?.ID != "AdminObserver")
{ {
shell.ExecuteCommand("aghost"); shell.ExecuteCommand("aghost");
} }
shell.ExecuteCommand("sudo cvar events.enabled false");
shell.ExecuteCommand($"tp 0 0 {mapId}"); shell.ExecuteCommand($"tp 0 0 {mapId}");
shell.RemoteExecuteCommand("showmarkers"); shell.RemoteExecuteCommand("showmarkers");
shell.RemoteExecuteCommand("togglelight");
shell.RemoteExecuteCommand("showsubfloorforever");
mapManager.SetMapPaused(mapId, true);
var newGrid = mapManager.GetAllGrids().OrderByDescending(g => (int) g.Index).First(); if (args.Length != 0)
shell.WriteLine($"Created uninitialized map from file {args[0]} with id {mapId}.");
mapManager.SetMapPaused(newGrid.ParentMapId, true); else
shell.WriteLine($"Created a new uninitialized map with id {mapId}.");
shell.WriteLine($"Created unloaded map from file {mapName} with id {mapId}. Use \"savebp {newGrid.Index} foo.yml\" to save the new grid as a map.");
} }
} }
} }