Add selecting maps to render when running MapRenderer, fix rendering multiple maps (#11783)

This commit is contained in:
DrSmugleaf
2022-10-09 07:36:18 +02:00
committed by GitHub
parent c3af9f53dd
commit b62ee2b1b4
4 changed files with 94 additions and 20 deletions

View File

@@ -5,9 +5,11 @@ using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Content.MapRenderer.Extensions;
using Content.IntegrationTests;
using Content.MapRenderer.Painters;
using Content.Server.Maps;
using Newtonsoft.Json;
using Robust.Shared.Prototypes;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Formats.Webp;
@@ -15,8 +17,9 @@ namespace Content.MapRenderer
{
internal class Program
{
private const string MapsAddedEnvKey = "FILES_ADDED";
private const string MapsModifiedEnvKey = "FILES_MODIFIED";
private const string NoMapsChosenMessage = "No maps were chosen";
private static readonly Func<string, string> ChosenMapIdNotIntMessage = id => $"The chosen id is not a valid integer: {id}";
private static readonly Func<int, string> NoMapFoundWithIdMessage = id => $"No map found with chosen id: {id}";
private static readonly MapPainter MapPainter = new();
@@ -24,7 +27,73 @@ namespace Content.MapRenderer
{
if (args.Length == 0)
{
Console.WriteLine("Didn't specify any maps to paint! Provide map names (as map prototype names).");
await using var server = await PoolManager.GetServerClient();
var mapIds = server.Pair.Server
.ResolveDependency<IPrototypeManager>()
.EnumeratePrototypes<GameMapPrototype>()
.Select(map => map.ID)
.ToArray();
Array.Sort(mapIds);
Console.WriteLine("Didn't specify any maps to paint, select one, multiple separated by commas or \"all\":");
Console.WriteLine(string.Join('\n', mapIds.Select((id, i) => $"({i}): {id}")));
var input = Console.ReadLine();
if (input == null)
{
Console.WriteLine(NoMapsChosenMessage);
return;
}
var selectedIds = new List<int>();
if (input is "all" or "\"all\"")
{
selectedIds = Enumerable.Range(0, mapIds.Length).ToList();
}
else
{
var inputArray = input.Split(',');
if (inputArray.Length == 0)
{
Console.WriteLine(NoMapsChosenMessage);
return;
}
foreach (var idString in inputArray)
{
if (!int.TryParse(idString.Trim(), out var id))
{
Console.WriteLine(ChosenMapIdNotIntMessage(idString));
return;
}
selectedIds.Add(id);
}
}
var selectedMapPrototypes = new List<string>();
foreach (var id in selectedIds)
{
if (id < 0 || id >= mapIds.Length)
{
Console.WriteLine(NoMapFoundWithIdMessage(id));
return;
}
selectedMapPrototypes.Add(mapIds[id]);
}
var argsLength = args.Length;
Array.Resize(ref args, argsLength + selectedMapPrototypes.Count);
selectedMapPrototypes.CopyTo(args, argsLength);
if (selectedMapPrototypes.Count == 0)
{
Console.WriteLine(NoMapsChosenMessage);
return;
}
Console.WriteLine($"Selected maps: {string.Join(", ", selectedMapPrototypes)}");
}
if (!CommandLineArguments.TryParse(args, out var arguments))
@@ -35,7 +104,6 @@ namespace Content.MapRenderer
private static async Task Run(CommandLineArguments arguments)
{
Console.WriteLine($"Creating images for {arguments.Maps.Count} maps");
var mapNames = new List<string>();
@@ -43,7 +111,7 @@ namespace Content.MapRenderer
{
Console.WriteLine($"Painting map {map}");
var mapViewerData = new MapViewerData()
var mapViewerData = new MapViewerData
{
Id = map,
Name = Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(map)
@@ -53,7 +121,7 @@ namespace Content.MapRenderer
var directory = Path.Combine(arguments.OutputPath, map);
Directory.CreateDirectory(directory);
int i = 0;
var i = 0;
await foreach (var renderedGrid in MapPainter.Paint(map))
{
var grid = renderedGrid.Image;