diff --git a/OpenRA.Utility/Command.cs b/OpenRA.Utility/Command.cs index 190cca9037..58897b2cfb 100644 --- a/OpenRA.Utility/Command.cs +++ b/OpenRA.Utility/Command.cs @@ -26,6 +26,7 @@ namespace OpenRA.Utility { public static class Command { + [Desc("KEY", "Get value of KEY from settings.yaml")] public static void Settings(string[] args) { if (args.Length < 2) @@ -41,6 +42,7 @@ namespace OpenRA.Utility Console.WriteLine(result); } + [Desc("PNGFILE [PNGFILE ...]", "Combine a list of PNG images into a SHP")] public static void ConvertPngToShp(string[] args) { var dest = args[1].Split('-').First() + ".shp"; @@ -71,6 +73,8 @@ namespace OpenRA.Utility return bytes; } + [Desc("SPRITEFILE PALETTE [--noshadow] [--nopadding]", + "Convert a shp/tmp/R8 to a series of PNGs, optionally removing shadow")] public static void ConvertShpToPng(string[] args) { var src = args[1]; @@ -136,6 +140,7 @@ namespace OpenRA.Utility Console.WriteLine("Saved {0}-[0..{1}].png", prefix, count - 1); } + [Desc("MOD FILES", "Extract files from mod packages to the current directory")] public static void ExtractFiles(string[] args) { var mod = args[1]; @@ -165,6 +170,7 @@ namespace OpenRA.Utility Math.Abs((int)ca.B - (int)cb.B); } + [Desc("SRCMOD:PAL DESTMOD:PAL SRCSHP DESTSHP", "Remap SHPs to another palette")] public static void RemapShp(string[] args) { var remap = new Dictionary(); @@ -213,6 +219,8 @@ namespace OpenRA.Utility srcImage.Frames.Select(im => im.Data.Select(px => (byte)remap[px]).ToArray())); } + [Desc("SRCSHP DESTSHP START N M [START N M ...]", + "Transpose the N*M block of frames starting at START.")] public static void TransposeShp(string[] args) { var srcImage = ShpReader.Load(args[1]); @@ -243,6 +251,7 @@ namespace OpenRA.Utility return t.Name; } + [Desc("MOD", "Generate trait documentation in MarkDown format.")] public static void ExtractTraitDocs(string[] args) { Game.modData = new ModData(args[1]); @@ -288,12 +297,14 @@ namespace OpenRA.Utility Console.WriteLine("```"); } + [Desc("MAPFILE", "Generate hash of specified oramap file.")] public static void GetMapHash(string[] args) { var result = new Map(args[1]).Uid; Console.WriteLine(result); } + [Desc("MAPFILE", "Render PNG minimap of specified oramap file.")] public static void GenerateMinimap(string[] args) { var map = new Map(args[1]); @@ -312,6 +323,7 @@ namespace OpenRA.Utility Console.WriteLine(dest + " saved."); } + [Desc("MAPFILE", "MOD", "Upgrade a version 5 map to version 6.")] public static void UpgradeMap(string[] args) { var map = args[1]; diff --git a/OpenRA.Utility/Program.cs b/OpenRA.Utility/Program.cs index 13f191603f..7ff9c3831d 100644 --- a/OpenRA.Utility/Program.cs +++ b/OpenRA.Utility/Program.cs @@ -10,35 +10,37 @@ using System; using System.Collections.Generic; +using System.Linq; using System.IO; +using OpenRA.FileFormats; namespace OpenRA.Utility { class Program { + static Dictionary> Actions = new Dictionary>() + { + { "--settings-value", Command.Settings }, + { "--shp", Command.ConvertPngToShp }, + { "--png", Command.ConvertShpToPng }, + { "--extract", Command.ExtractFiles }, + { "--remap", Command.RemapShp }, + { "--transpose", Command.TransposeShp }, + { "--docs", Command.ExtractTraitDocs }, + { "--map-hash", Command.GetMapHash }, + { "--map-preview", Command.GenerateMinimap }, + { "--map-upgrade", Command.UpgradeMap }, + }; + static void Main(string[] args) { - var actions = new Dictionary>() - { - { "--settings-value", Command.Settings }, - { "--shp", Command.ConvertPngToShp }, - { "--png", Command.ConvertShpToPng }, - { "--extract", Command.ExtractFiles }, - { "--remap", Command.RemapShp }, - { "--transpose", Command.TransposeShp }, - { "--docs", Command.ExtractTraitDocs }, - { "--map-hash", Command.GetMapHash }, - { "--map-preview", Command.GenerateMinimap }, - { "--map-upgrade", Command.UpgradeMap }, - }; - if (args.Length == 0) { PrintUsage(); return; } Log.LogPath = Platform.SupportDir + "Logs" + Path.DirectorySeparatorChar; try { - var action = Exts.WithDefault(_ => PrintUsage(), () => actions[args[0]]); + var action = Exts.WithDefault(_ => PrintUsage(), () => Actions[args[0]]); action(args); } catch (Exception e) @@ -56,15 +58,19 @@ namespace OpenRA.Utility { Console.WriteLine("Usage: OpenRA.Utility.exe [OPTION] [ARGS]"); Console.WriteLine(); - Console.WriteLine(" --settings-value KEY Get value of KEY from settings.yaml"); - Console.WriteLine(" --shp PNGFILE [PNGFILE ...] Combine a list of PNG images into a SHP"); - Console.WriteLine(" --png SPRITEFILE PALETTE [--noshadow] [--nopadding] Convert a shp/tmp/R8 to a series of PNGs, optionally removing shadow"); - Console.WriteLine(" --extract MOD[,MOD]* FILES Extract files from mod packages to the current directory"); - Console.WriteLine(" --remap SRCMOD:PAL DESTMOD:PAL SRCSHP DESTSHP Remap SHPs to another palette"); - Console.WriteLine(" --transpose SRCSHP DESTSHP START N M [START N M ...] Transpose the N*M block of frames starting at START."); - Console.WriteLine(" --docs MOD Generate trait documentation in MarkDown format."); - Console.WriteLine(" --map-hash MAPFILE Generate hash of specified oramap file."); - Console.WriteLine(" --minimap MAPFILE [MOD] Render PNG minimap of specified oramap file."); + foreach (var a in Actions) + { + var descParts = a.Value.Method.GetCustomAttributes(true) + .SelectMany(d => d.Lines); + + if (!descParts.Any()) + continue; + + var args = descParts.Take(descParts.Count() - 1).JoinWith(" "); + var desc = descParts.Last(); + + Console.WriteLine(" {0} {1} ({2})", a.Key, args, desc); + } } static string GetNamedArg(string[] args, string arg)