QoL for the MapRenderer tool (#11921)
This commit is contained in:
@@ -27,6 +27,8 @@ namespace Content.MapRenderer
|
|||||||
{
|
{
|
||||||
if (args.Length == 0)
|
if (args.Length == 0)
|
||||||
{
|
{
|
||||||
|
Console.WriteLine("Didn't specify any maps to paint! Loading the map list...");
|
||||||
|
|
||||||
await using var server = await PoolManager.GetServerClient();
|
await using var server = await PoolManager.GetServerClient();
|
||||||
var mapIds = server.Pair.Server
|
var mapIds = server.Pair.Server
|
||||||
.ResolveDependency<IPrototypeManager>()
|
.ResolveDependency<IPrototypeManager>()
|
||||||
@@ -36,8 +38,10 @@ namespace Content.MapRenderer
|
|||||||
|
|
||||||
Array.Sort(mapIds);
|
Array.Sort(mapIds);
|
||||||
|
|
||||||
Console.WriteLine("Didn't specify any maps to paint, select one, multiple separated by commas or \"all\":");
|
Console.WriteLine("Map List");
|
||||||
Console.WriteLine(string.Join('\n', mapIds.Select((id, i) => $"({i}): {id}")));
|
Console.WriteLine(string.Join('\n', mapIds.Select((id, i) => $"{i,3}: {id}")));
|
||||||
|
Console.WriteLine("Select one, multiple separated by commas or \"all\":");
|
||||||
|
Console.Write("> ");
|
||||||
var input = Console.ReadLine();
|
var input = Console.ReadLine();
|
||||||
if (input == null)
|
if (input == null)
|
||||||
{
|
{
|
||||||
@@ -119,44 +123,52 @@ namespace Content.MapRenderer
|
|||||||
|
|
||||||
mapViewerData.ParallaxLayers.Add(LayerGroup.DefaultParallax());
|
mapViewerData.ParallaxLayers.Add(LayerGroup.DefaultParallax());
|
||||||
var directory = Path.Combine(arguments.OutputPath, map);
|
var directory = Path.Combine(arguments.OutputPath, map);
|
||||||
Directory.CreateDirectory(directory);
|
|
||||||
|
|
||||||
var i = 0;
|
var i = 0;
|
||||||
await foreach (var renderedGrid in MapPainter.Paint(map))
|
try
|
||||||
{
|
{
|
||||||
var grid = renderedGrid.Image;
|
await foreach (var renderedGrid in MapPainter.Paint(map))
|
||||||
Directory.CreateDirectory(directory);
|
|
||||||
|
|
||||||
var fileName = Path.GetFileNameWithoutExtension(map);
|
|
||||||
var savePath = $"{directory}{Path.DirectorySeparatorChar}{fileName}-{i}.{arguments.Format.ToString()}";
|
|
||||||
|
|
||||||
Console.WriteLine($"Writing grid of size {grid.Width}x{grid.Height} to {savePath}");
|
|
||||||
|
|
||||||
switch (arguments.Format)
|
|
||||||
{
|
{
|
||||||
case OutputFormat.webp:
|
var grid = renderedGrid.Image;
|
||||||
var encoder = new WebpEncoder
|
Directory.CreateDirectory(directory);
|
||||||
{
|
|
||||||
Method = WebpEncodingMethod.BestQuality,
|
|
||||||
FileFormat = WebpFileFormatType.Lossless,
|
|
||||||
TransparentColorMode = WebpTransparentColorMode.Preserve
|
|
||||||
};
|
|
||||||
|
|
||||||
await grid.SaveAsync(savePath, encoder);
|
var fileName = Path.GetFileNameWithoutExtension(map);
|
||||||
break;
|
var savePath = $"{directory}{Path.DirectorySeparatorChar}{fileName}-{i}.{arguments.Format.ToString()}";
|
||||||
|
|
||||||
default:
|
Console.WriteLine($"Writing grid of size {grid.Width}x{grid.Height} to {savePath}");
|
||||||
case OutputFormat.png:
|
|
||||||
await grid.SaveAsPngAsync(savePath);
|
switch (arguments.Format)
|
||||||
break;
|
{
|
||||||
|
case OutputFormat.webp:
|
||||||
|
var encoder = new WebpEncoder
|
||||||
|
{
|
||||||
|
Method = WebpEncodingMethod.BestQuality,
|
||||||
|
FileFormat = WebpFileFormatType.Lossless,
|
||||||
|
TransparentColorMode = WebpTransparentColorMode.Preserve
|
||||||
|
};
|
||||||
|
|
||||||
|
await grid.SaveAsync(savePath, encoder);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
case OutputFormat.png:
|
||||||
|
await grid.SaveAsPngAsync(savePath);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
grid.Dispose();
|
||||||
|
|
||||||
|
mapViewerData.Grids.Add(new GridLayer(renderedGrid, Path.Combine(map, Path.GetFileName(savePath))));
|
||||||
|
|
||||||
|
mapNames.Add(fileName);
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
grid.Dispose();
|
catch (Exception ex)
|
||||||
|
{
|
||||||
mapViewerData.Grids.Add(new GridLayer(renderedGrid, Path.Combine(map, Path.GetFileName(savePath))));
|
Console.WriteLine($"Painting map {map} failed due to an internal exception:");
|
||||||
|
Console.WriteLine(ex);
|
||||||
mapNames.Add(fileName);
|
continue;
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (arguments.ExportViewerJson)
|
if (arguments.ExportViewerJson)
|
||||||
@@ -168,7 +180,8 @@ namespace Content.MapRenderer
|
|||||||
|
|
||||||
var mapNamesString = $"[{string.Join(',', mapNames.Select(s => $"\"{s}\""))}]";
|
var mapNamesString = $"[{string.Join(',', mapNames.Select(s => $"\"{s}\""))}]";
|
||||||
Console.WriteLine($@"::set-output name=map_names::{mapNamesString}");
|
Console.WriteLine($@"::set-output name=map_names::{mapNamesString}");
|
||||||
Console.WriteLine($"Created {arguments.Maps.Count} map images.");
|
Console.WriteLine($"Processed {arguments.Maps.Count} maps.");
|
||||||
|
Console.WriteLine($"It's now safe to manually exit the process (automatic exit in a few moments...)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user