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:
@@ -10,8 +10,8 @@ public sealed class CommandLineArguments
|
|||||||
public List<string> Maps { get; set; } = new();
|
public List<string> Maps { get; set; } = new();
|
||||||
public OutputFormat Format { get; set; } = OutputFormat.png;
|
public OutputFormat Format { get; set; } = OutputFormat.png;
|
||||||
public bool ExportViewerJson { get; set; } = false;
|
public bool ExportViewerJson { get; set; } = false;
|
||||||
|
|
||||||
public string OutputPath { get; set; } = DirectoryExtensions.MapImages().FullName;
|
public string OutputPath { get; set; } = DirectoryExtensions.MapImages().FullName;
|
||||||
|
public bool ArgumentsAreFileNames { get; set; } = false;
|
||||||
|
|
||||||
public static bool TryParse(IReadOnlyList<string> args, [NotNullWhen(true)] out CommandLineArguments? parsed)
|
public static bool TryParse(IReadOnlyList<string> args, [NotNullWhen(true)] out CommandLineArguments? parsed)
|
||||||
{
|
{
|
||||||
@@ -20,7 +20,8 @@ public sealed class CommandLineArguments
|
|||||||
if (args.Count == 0)
|
if (args.Count == 0)
|
||||||
{
|
{
|
||||||
PrintHelp();
|
PrintHelp();
|
||||||
return false;
|
//Returns true here so the user can select what maps they want to render
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
using var enumerator = args.GetEnumerator();
|
using var enumerator = args.GetEnumerator();
|
||||||
@@ -53,6 +54,11 @@ public sealed class CommandLineArguments
|
|||||||
parsed.OutputPath = enumerator.Current;
|
parsed.OutputPath = enumerator.Current;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case "-f":
|
||||||
|
case "--files":
|
||||||
|
parsed.ArgumentsAreFileNames = true;
|
||||||
|
break;
|
||||||
|
|
||||||
case "-h":
|
case "-h":
|
||||||
case "--help":
|
case "--help":
|
||||||
PrintHelp();
|
PrintHelp();
|
||||||
@@ -64,6 +70,13 @@ public sealed class CommandLineArguments
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (parsed.ArgumentsAreFileNames && parsed.Maps.Count == 0)
|
||||||
|
{
|
||||||
|
Console.WriteLine("No file names specified!");
|
||||||
|
PrintHelp();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,6 +93,9 @@ Options:
|
|||||||
-o / --output <output path>
|
-o / --output <output path>
|
||||||
Changes the path the rendered maps will get saved to.
|
Changes the path the rendered maps will get saved to.
|
||||||
Defaults to Resources/MapImages
|
Defaults to Resources/MapImages
|
||||||
|
-f / --files
|
||||||
|
This option tells the map renderer that you supplied a list of map file names instead of their ids.
|
||||||
|
Example: Content.MapRenderer -f box.yml bagel.yml
|
||||||
-h / --help
|
-h / --help
|
||||||
Displays this help text");
|
Displays this help text");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,10 +25,14 @@ namespace Content.MapRenderer
|
|||||||
|
|
||||||
internal static async Task Main(string[] args)
|
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...");
|
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>()
|
||||||
@@ -87,9 +91,7 @@ namespace Content.MapRenderer
|
|||||||
selectedMapPrototypes.Add(mapIds[id]);
|
selectedMapPrototypes.Add(mapIds[id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
var argsLength = args.Length;
|
arguments.Maps.AddRange(selectedMapPrototypes);
|
||||||
Array.Resize(ref args, argsLength + selectedMapPrototypes.Count);
|
|
||||||
selectedMapPrototypes.CopyTo(args, argsLength);
|
|
||||||
|
|
||||||
if (selectedMapPrototypes.Count == 0)
|
if (selectedMapPrototypes.Count == 0)
|
||||||
{
|
{
|
||||||
@@ -100,8 +102,37 @@ namespace Content.MapRenderer
|
|||||||
Console.WriteLine($"Selected maps: {string.Join(", ", selectedMapPrototypes)}");
|
Console.WriteLine($"Selected maps: {string.Join(", ", selectedMapPrototypes)}");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!CommandLineArguments.TryParse(args, out var arguments))
|
if (arguments.ArgumentsAreFileNames)
|
||||||
return;
|
{
|
||||||
|
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);
|
await Run(arguments);
|
||||||
}
|
}
|
||||||
@@ -123,7 +154,7 @@ 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);
|
||||||
|
|
||||||
var i = 0;
|
var i = 0;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user