Map renderer file name option (#12463)

* Add option for supplying map names instead of ids as argument

* Allow options to be used with the map selector
This commit is contained in:
Julian Giebel
2022-11-08 15:03:34 +01:00
committed by GitHub
parent c847fe7219
commit ac99f4dd5e
2 changed files with 57 additions and 10 deletions

View File

@@ -25,10 +25,14 @@ namespace Content.MapRenderer
internal static async Task Main(string[] args)
{
if (args.Length == 0)
if (!CommandLineArguments.TryParse(args, out var arguments))
return;
if (arguments.Maps.Count == 0)
{
Console.WriteLine("Didn't specify any maps to paint! Loading the map list...");
await using var server = await PoolManager.GetServerClient();
var mapIds = server.Pair.Server
.ResolveDependency<IPrototypeManager>()
@@ -87,9 +91,7 @@ namespace Content.MapRenderer
selectedMapPrototypes.Add(mapIds[id]);
}
var argsLength = args.Length;
Array.Resize(ref args, argsLength + selectedMapPrototypes.Count);
selectedMapPrototypes.CopyTo(args, argsLength);
arguments.Maps.AddRange(selectedMapPrototypes);
if (selectedMapPrototypes.Count == 0)
{
@@ -100,8 +102,37 @@ namespace Content.MapRenderer
Console.WriteLine($"Selected maps: {string.Join(", ", selectedMapPrototypes)}");
}
if (!CommandLineArguments.TryParse(args, out var arguments))
return;
if (arguments.ArgumentsAreFileNames)
{
Console.WriteLine("Retrieving map ids by map file names...");
Console.Write("Fetching map prototypes... ");
await using var server = await PoolManager.GetServerClient();
var mapPrototypes = server.Pair.Server
.ResolveDependency<IPrototypeManager>()
.EnumeratePrototypes<GameMapPrototype>()
.ToArray();
Console.WriteLine("[Done]");
var ids = new List<string>();
foreach (var mapPrototype in mapPrototypes)
{
if (arguments.Maps.Contains(mapPrototype.MapPath.Filename))
{
ids.Add(mapPrototype.ID);
Console.WriteLine($"Found map: {mapPrototype.MapName}");
}
}
if (ids.Count == 0)
{
await Console.Error.WriteLineAsync("Found no maps for the given file names!");
return;
}
arguments.Maps = ids;
}
await Run(arguments);
}
@@ -123,7 +154,7 @@ namespace Content.MapRenderer
mapViewerData.ParallaxLayers.Add(LayerGroup.DefaultParallax());
var directory = Path.Combine(arguments.OutputPath, map);
var i = 0;
try
{