Fix bitrotted command descriptions.

This commit is contained in:
Paul Chote
2013-12-12 20:29:56 +13:00
parent 8f71861a6b
commit ffcfe051e0
2 changed files with 42 additions and 24 deletions

View File

@@ -26,6 +26,7 @@ namespace OpenRA.Utility
{ {
public static class Command public static class Command
{ {
[Desc("KEY", "Get value of KEY from settings.yaml")]
public static void Settings(string[] args) public static void Settings(string[] args)
{ {
if (args.Length < 2) if (args.Length < 2)
@@ -41,6 +42,7 @@ namespace OpenRA.Utility
Console.WriteLine(result); Console.WriteLine(result);
} }
[Desc("PNGFILE [PNGFILE ...]", "Combine a list of PNG images into a SHP")]
public static void ConvertPngToShp(string[] args) public static void ConvertPngToShp(string[] args)
{ {
var dest = args[1].Split('-').First() + ".shp"; var dest = args[1].Split('-').First() + ".shp";
@@ -71,6 +73,8 @@ namespace OpenRA.Utility
return bytes; 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) public static void ConvertShpToPng(string[] args)
{ {
var src = args[1]; var src = args[1];
@@ -136,6 +140,7 @@ namespace OpenRA.Utility
Console.WriteLine("Saved {0}-[0..{1}].png", prefix, count - 1); 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) public static void ExtractFiles(string[] args)
{ {
var mod = args[1]; var mod = args[1];
@@ -165,6 +170,7 @@ namespace OpenRA.Utility
Math.Abs((int)ca.B - (int)cb.B); 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) public static void RemapShp(string[] args)
{ {
var remap = new Dictionary<int, int>(); var remap = new Dictionary<int, int>();
@@ -213,6 +219,8 @@ namespace OpenRA.Utility
srcImage.Frames.Select(im => im.Data.Select(px => (byte)remap[px]).ToArray())); 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) public static void TransposeShp(string[] args)
{ {
var srcImage = ShpReader.Load(args[1]); var srcImage = ShpReader.Load(args[1]);
@@ -243,6 +251,7 @@ namespace OpenRA.Utility
return t.Name; return t.Name;
} }
[Desc("MOD", "Generate trait documentation in MarkDown format.")]
public static void ExtractTraitDocs(string[] args) public static void ExtractTraitDocs(string[] args)
{ {
Game.modData = new ModData(args[1]); Game.modData = new ModData(args[1]);
@@ -288,12 +297,14 @@ namespace OpenRA.Utility
Console.WriteLine("```"); Console.WriteLine("```");
} }
[Desc("MAPFILE", "Generate hash of specified oramap file.")]
public static void GetMapHash(string[] args) public static void GetMapHash(string[] args)
{ {
var result = new Map(args[1]).Uid; var result = new Map(args[1]).Uid;
Console.WriteLine(result); Console.WriteLine(result);
} }
[Desc("MAPFILE", "Render PNG minimap of specified oramap file.")]
public static void GenerateMinimap(string[] args) public static void GenerateMinimap(string[] args)
{ {
var map = new Map(args[1]); var map = new Map(args[1]);
@@ -312,6 +323,7 @@ namespace OpenRA.Utility
Console.WriteLine(dest + " saved."); Console.WriteLine(dest + " saved.");
} }
[Desc("MAPFILE", "MOD", "Upgrade a version 5 map to version 6.")]
public static void UpgradeMap(string[] args) public static void UpgradeMap(string[] args)
{ {
var map = args[1]; var map = args[1];

View File

@@ -10,35 +10,37 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.IO; using System.IO;
using OpenRA.FileFormats;
namespace OpenRA.Utility namespace OpenRA.Utility
{ {
class Program class Program
{ {
static Dictionary<string, Action<string[]>> Actions = new Dictionary<string, Action<string[]>>()
{
{ "--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) static void Main(string[] args)
{ {
var actions = new Dictionary<string, Action<string[]>>()
{
{ "--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; } if (args.Length == 0) { PrintUsage(); return; }
Log.LogPath = Platform.SupportDir + "Logs" + Path.DirectorySeparatorChar; Log.LogPath = Platform.SupportDir + "Logs" + Path.DirectorySeparatorChar;
try try
{ {
var action = Exts.WithDefault(_ => PrintUsage(), () => actions[args[0]]); var action = Exts.WithDefault(_ => PrintUsage(), () => Actions[args[0]]);
action(args); action(args);
} }
catch (Exception e) catch (Exception e)
@@ -56,15 +58,19 @@ namespace OpenRA.Utility
{ {
Console.WriteLine("Usage: OpenRA.Utility.exe [OPTION] [ARGS]"); Console.WriteLine("Usage: OpenRA.Utility.exe [OPTION] [ARGS]");
Console.WriteLine(); Console.WriteLine();
Console.WriteLine(" --settings-value KEY Get value of KEY from settings.yaml"); foreach (var a in Actions)
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"); var descParts = a.Value.Method.GetCustomAttributes<DescAttribute>(true)
Console.WriteLine(" --extract MOD[,MOD]* FILES Extract files from mod packages to the current directory"); .SelectMany(d => d.Lines);
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."); if (!descParts.Any())
Console.WriteLine(" --docs MOD Generate trait documentation in MarkDown format."); continue;
Console.WriteLine(" --map-hash MAPFILE Generate hash of specified oramap file.");
Console.WriteLine(" --minimap MAPFILE [MOD] Render PNG minimap of specified oramap file."); 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) static string GetNamedArg(string[] args, string arg)