Make the mapping command take the next available map id if one isn't given (#1998)

* Make the mapping command take the next available map id if one isn't given, draft

* Remove todo

* Update clientside mapping command

* Address reviews
This commit is contained in:
DrSmugleaf
2020-09-10 00:12:39 +02:00
committed by GitHub
parent 96a04d271a
commit f7a5bad839
2 changed files with 38 additions and 10 deletions

View File

@@ -90,11 +90,11 @@ namespace Content.Client.Commands
{
public string Command => "mapping";
public string Description => "Creates and teleports you to a new uninitialized map for mapping.";
public string Help => $"Usage: {Command} <id> <mapname>";
public string Help => $"Usage: {Command} <mapname> / {Command} <id> <mapname>";
public bool Execute(IDebugConsole console, params string[] args)
{
if (args.Length != 2)
if (args.Length == 0)
{
console.AddLine(Help);
return false;

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Content.Server.Interfaces.GameTicking;
using Content.Server.Players;
using Content.Shared.Maps;
@@ -321,7 +322,7 @@ namespace Content.Server.GameTicking
{
public string Command => "mapping";
public string Description => "Creates and teleports you to a new uninitialized map for mapping.";
public string Help => $"Usage: {Command} <id> <mapname>";
public string Help => $"Usage: {Command} <mapname> / {Command} <id> <mapname>";
public void Execute(IConsoleShell shell, IPlayerSession player, string[] args)
{
@@ -331,18 +332,45 @@ namespace Content.Server.GameTicking
return;
}
if (args.Length != 2)
var mapManager = IoCManager.Resolve<IMapManager>();
int mapId;
string mapName;
switch (args.Length)
{
case 1:
if (player.AttachedEntity == null)
{
shell.SendText(player, "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.SendText(player, $"{args[0]} is not a valid integer.");
return;
}
mapId = id;
mapName = args[1];
break;
default:
shell.SendText(player, Help);
return;
}
shell.ExecuteCommand(player, $"addmap {args[0]} false");
shell.ExecuteCommand(player, $"loadbp {args[0]} \"{CommandParsing.Escape(args[1])}\"");
shell.ExecuteCommand(player, $"addmap {mapId} false");
shell.ExecuteCommand(player, $"loadbp {mapId} \"{CommandParsing.Escape(mapName)}\"");
shell.ExecuteCommand(player, $"aghost");
shell.ExecuteCommand(player, $"tp 0 0 {args[0]}");
shell.ExecuteCommand(player, $"tp 0 0 {mapId}");
shell.SendText(player, $"Created unloaded map from file {args[1]} with id {args[0]}. Use \"savebp 4 foo.yml\" to save it.");
var newGridId = mapManager.GetAllGrids().Max(g => (int) g.Index);
shell.SendText(player, $"Created unloaded map from file {mapName} with id {mapId}. Use \"savebp {newGridId} foo.yml\" to save the new grid as a map.");
}
}