* Fix MapRenderer integration test usage to properly show output. Added an ITestContextLike interface that can be used to properly run the integration test infrastructure OUTSIDE A TEST. * Use System.Test.Json instead of Newtonsoft.Json for MapRenderer * Fix map renderer JSON output being broken I love not testing or even reading the surrounding code. * Fix un-reusable integration instances getting leaked. The pair state was always getting set to Ready even if the instance was killed, meaning it was getting put back into the pool even if killed. * Mark map renderer integration instances as destructive to avoid memory leak. * Fix file specification handling. Map file specification is now backwards compatible again (loose filename match to search prototypes). It also supports proper direct OS filename arguments. The former is the fallback scenario is extremely important for the map server still. Cleaned up the way that target map files are passed through the application, so mixed file/prototype specifications are now handled properly (which can be caused by the fallback behavior). Fixes JSON data export to use the proper user-facing map name. This only works if a prototype ID is specified *or* the legacy file behavior is used. Restructured MapPainter into an instance that has multiple functions called on it, so not all data has to be passed through a single Paint() call. Clean up the godawful map/grid detection code. Now we just load both in a single call, because yes you can do that. This relies on LogOrphanedGrids = false in the map loader options, which I think is fine for our purposes. Improved error handling in much of the program. * Fix duplicate map names in map renderer output I'm not sure *what* this output is used for, but I'm sure having it duplicated per grid isn't intentional. * Make maprenderer command line parsing bail on unknown - options * Fix incorrect docs for --viewer maprenderer argument It doesn't change directory layout * Fix parallax layer specification to not use imgur as a fucking CDN Files are now copied to a separate folder _parallax, and these files are referenced by the parallax configuration. Parallax data is only output when instructed to via --parallax. This will break parallax on current map server builds, but it should be graceful. Also, that's fucking good considering we shouldn't be using imgur links. Purge it. * Fix incorrect assert in test pair clean return * Restore other map viewer parallax layers, fix attribution. * This isn't a valid copyright statement but the validator forces me to enter something here.
137 lines
4.1 KiB
C#
137 lines
4.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics.CodeAnalysis;
|
|
using Content.MapRenderer.Extensions;
|
|
|
|
namespace Content.MapRenderer;
|
|
|
|
public sealed class CommandLineArguments
|
|
{
|
|
public List<string> Maps { get; set; } = new();
|
|
public OutputFormat Format { get; set; } = OutputFormat.png;
|
|
public bool ExportViewerJson { get; set; } = false;
|
|
public string OutputPath { get; set; } = DirectoryExtensions.MapImages().FullName;
|
|
public bool ArgumentsAreFileNames { get; set; } = false;
|
|
public bool ShowMarkers { get; set; } = false;
|
|
public bool OutputParallax { get; set; } = false;
|
|
|
|
public static bool TryParse(IReadOnlyList<string> args, [NotNullWhen(true)] out CommandLineArguments? parsed)
|
|
{
|
|
parsed = new CommandLineArguments();
|
|
|
|
if (args.Count == 0)
|
|
{
|
|
PrintHelp();
|
|
//Returns true here so the user can select what maps they want to render
|
|
return true;
|
|
}
|
|
|
|
using var enumerator = args.GetEnumerator();
|
|
|
|
while (enumerator.MoveNext())
|
|
{
|
|
var argument = enumerator.Current;
|
|
switch (argument)
|
|
{
|
|
case "--format":
|
|
enumerator.MoveNext();
|
|
|
|
if (!Enum.TryParse<OutputFormat>(enumerator.Current, out var format))
|
|
{
|
|
Console.WriteLine("Invalid format specified for option: {0}", argument);
|
|
parsed = null;
|
|
return false;
|
|
}
|
|
|
|
parsed.Format = format;
|
|
break;
|
|
|
|
case "--viewer":
|
|
parsed.ExportViewerJson = true;
|
|
break;
|
|
|
|
case "-o":
|
|
case "--output":
|
|
enumerator.MoveNext();
|
|
parsed.OutputPath = enumerator.Current;
|
|
break;
|
|
|
|
case "-f":
|
|
case "--files":
|
|
parsed.ArgumentsAreFileNames = true;
|
|
break;
|
|
|
|
case "-m":
|
|
case "--markers":
|
|
parsed.ShowMarkers = true;
|
|
break;
|
|
|
|
case "-h":
|
|
case "--help":
|
|
PrintHelp();
|
|
return false;
|
|
|
|
case "--parallax":
|
|
parsed.OutputParallax = true;
|
|
break;
|
|
|
|
default:
|
|
if (argument.StartsWith('-'))
|
|
{
|
|
Console.WriteLine($"Unknown argument: {argument}");
|
|
return false;
|
|
}
|
|
|
|
parsed.Maps.Add(argument);
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (parsed.ArgumentsAreFileNames && parsed.Maps.Count == 0)
|
|
{
|
|
Console.WriteLine("No file names specified!");
|
|
PrintHelp();
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public static void PrintHelp()
|
|
{
|
|
Console.WriteLine(@"Content.MapRenderer <options> [map names]
|
|
Options:
|
|
--format <png|webp>
|
|
Specifies the format the map images will be exported as.
|
|
Defaults to: png
|
|
--viewer
|
|
Causes the map renderer to create the map.json files required for use with the map viewer.
|
|
-o / --output <output path>
|
|
Changes the path the rendered maps will get saved to.
|
|
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 /Maps/box.yml /Maps/bagel.yml
|
|
-m / --markers
|
|
Show hidden markers on map render. Defaults to false.
|
|
--parallax
|
|
Output images and data used for map viewer parallax.
|
|
-h / --help
|
|
Displays this help text");
|
|
}
|
|
}
|
|
|
|
public sealed class CommandLineArgumentException : Exception
|
|
{
|
|
public CommandLineArgumentException(string? message) : base(message)
|
|
{
|
|
}
|
|
}
|
|
|
|
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
|
public enum OutputFormat
|
|
{
|
|
png,
|
|
webp
|
|
}
|