improved command argument system.
This commit is contained in:
@@ -10,33 +10,23 @@ namespace RecrownedAthenaeum.Tools.TextureAtlasTools
|
||||
class TexturePackerCommand : EngineCommand
|
||||
{
|
||||
|
||||
public TexturePackerCommand() : base("texturepacker") { }
|
||||
|
||||
public override string Help(string argument)
|
||||
public TexturePackerCommand() : base("texturepacker")
|
||||
{
|
||||
switch (argument)
|
||||
{
|
||||
case null:
|
||||
return "Packs a given directory composed of png and jpg files into an atlas. Can also add 9patch properties. Possible arguments are \"-i\", \"-o\", \"-mp\", \"-dau\", and \"-9p\". Refer to \"help\" for more info.";
|
||||
case "-i":
|
||||
return "-i : Path for input directory containing the textures. Required.";
|
||||
case "-o":
|
||||
return "-o : Path for output files. Points to non-existent file. Will create texture and definitions file with name. Required.";
|
||||
case "-9p":
|
||||
return "-9p : Can be used multiple times for defining a 9patch. This parameter requires a name, left patch, right patch, top patch, and bottom patch in the format name,a,b,c,d. Optional.";
|
||||
case "-sp":
|
||||
return "-sp : starting power for one side of the texture. Default is 8.";
|
||||
case "-mp":
|
||||
return "-mp : Maximum power for one side of the texture. Default is 8.";
|
||||
case "-dau":
|
||||
return "-dau : disables automatically upscaling the texture.";
|
||||
default:
|
||||
return argument + " is not a valid argument. Type \"help texturepacker to see general help and list of arguments.\"";
|
||||
}
|
||||
arguments = new EngineCommandArgument[6] {
|
||||
new EngineCommandArgument("-i", "for input directory containing the textures. Required."),
|
||||
new EngineCommandArgument("-o", "Path for output files. Points to non-existent file. Will create texture and definitions file with name. Required."),
|
||||
new EngineCommandArgument("-9p", "Can be used multiple times for defining a 9patch. This parameter requires a name, left patch, right patch, top patch, and bottom patch in the format name,a,b,c,d. Optional."),
|
||||
new EngineCommandArgument("-sp", "Starting power for one side of the texture. Default is 8."),
|
||||
new EngineCommandArgument("-mp", "Maximum power for one side of the texture. Default is 8."),
|
||||
new EngineCommandArgument("-dau", "Disables automatically upscaling the texture."),
|
||||
};
|
||||
|
||||
help = "Packs a given directory composed of png and jpg files into an atlas. Can also add 9patch properties. Runnig without arguments triggers interactive mode.";
|
||||
}
|
||||
|
||||
public override void Run(string[] arguments)
|
||||
{
|
||||
|
||||
TexturePacker texturePacker = null;
|
||||
string path = null;
|
||||
int mp = 8;
|
||||
@@ -44,72 +34,47 @@ namespace RecrownedAthenaeum.Tools.TextureAtlasTools
|
||||
bool dau = false;
|
||||
string output = null;
|
||||
|
||||
if (arguments == null) throw new ArgumentException("Requires arguments. Type \"help texturepacker\" for more info.");
|
||||
if (arguments == null)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
path = arguments[1 + IndexOfArgumentIn("-i", arguments)];
|
||||
int.TryParse(arguments[IndexOfArgumentIn("-mp", arguments) + 1], out mp);
|
||||
int.TryParse(arguments[IndexOfArgumentIn("-sp", arguments) + 1], out sp);
|
||||
output = arguments[IndexOfArgumentIn("-o", arguments) + 1];
|
||||
if (HasArgument("-dau", arguments)) dau = true;
|
||||
|
||||
texturePacker = new TexturePacker(path, mp, sp);
|
||||
ConsoleUtilities.WriteWrappedLine("Calculated minimum texture size: " + texturePacker.TextureLength + "x" + texturePacker.TextureLength + " with a total of " + texturePacker.TexturesFound + " textures.");
|
||||
|
||||
try
|
||||
{
|
||||
texturePacker.Build(!dau);
|
||||
}
|
||||
catch (InvalidOperationException e)
|
||||
{
|
||||
throw new ArgumentException(e.Message);
|
||||
}
|
||||
|
||||
for (int i = 0; i < arguments.Length; i++)
|
||||
{
|
||||
if (arguments[i] == "-i")
|
||||
if (arguments[i] == "-9p")
|
||||
{
|
||||
if (i + 1 == arguments.Length) throw new ArgumentException("-i is not followed by path for input directory.");
|
||||
path = arguments[i + 1];
|
||||
}
|
||||
if (arguments[i] == "-mp")
|
||||
{
|
||||
if (i + 1 >= arguments.Length || !int.TryParse(arguments[i + 1], out mp)) throw new ArgumentException("mp is not followed by maximum power.");
|
||||
}
|
||||
if (arguments[i] == "-sp")
|
||||
{
|
||||
if (i + 1 >= arguments.Length || !int.TryParse(arguments[i + 1], out sp)) throw new ArgumentException("sp is not followed by maximum power.");
|
||||
}
|
||||
if (arguments[i] == "-o")
|
||||
{
|
||||
if (i + 1 >= arguments.Length) throw new ArgumentException("-o is not followed by path for output files. (eg. path/to/file where file is the name for the atlas.)");
|
||||
output = arguments[i + 1];
|
||||
}
|
||||
|
||||
if (i == arguments.Length - 1 && output == null)
|
||||
{
|
||||
throw new ArgumentException("no -o argument found to specify output.");
|
||||
}
|
||||
|
||||
if (arguments[i] == "-dau") dau = true;
|
||||
}
|
||||
texturePacker = new TexturePacker(path, mp, sp);
|
||||
ConsoleUtilities.WriteWrappedLine("Calculated minimum texture size: " + texturePacker.TextureLength + "x" + texturePacker.TextureLength + " with a total of " + texturePacker.TexturesFound + " textures.");
|
||||
if (texturePacker != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
texturePacker.Build(!dau);
|
||||
}
|
||||
catch (InvalidOperationException e)
|
||||
{
|
||||
throw new ArgumentException(e.Message);
|
||||
}
|
||||
|
||||
for (int i = 0; i < arguments.Length; i++)
|
||||
{
|
||||
if (arguments[i] == "-9p")
|
||||
if (i + 5 >= arguments.Length) throw new ArgumentException("-9p is not followed by proper specifiers for a 9Patch (format: \"-9p textureName,a,b,c,d\" where a, b, c, and d are integers definining the border regions for the 9patch.)");
|
||||
string[] nPatchArgs = arguments[i + 1].Split(',');
|
||||
try
|
||||
{
|
||||
if (i + 5 >= arguments.Length) throw new ArgumentException("-9p is not followed by proper specifiers for a 9Patch (format: \"-9p textureName,a,b,c,d\" where a, b, c, and d are integers definining the border regions for the 9patch.)");
|
||||
string[] nPatchArgs = arguments[i + 1].Split(',');
|
||||
try
|
||||
{
|
||||
texturePacker.SetNinePatch(nPatchArgs[0], int.Parse(nPatchArgs[1]), int.Parse(nPatchArgs[2]), int.Parse(nPatchArgs[3]), int.Parse(nPatchArgs[4]));
|
||||
}
|
||||
catch (FormatException)
|
||||
{
|
||||
throw new ArgumentException("-9p argument parameters must be in the format \"-9p textureName,a,b,c,d\" where a, b, c, and d are integers definining the border regions for the 9patch.");
|
||||
}
|
||||
texturePacker.SetNinePatch(nPatchArgs[0], int.Parse(nPatchArgs[1]), int.Parse(nPatchArgs[2]), int.Parse(nPatchArgs[3]), int.Parse(nPatchArgs[4]));
|
||||
}
|
||||
catch (FormatException)
|
||||
{
|
||||
throw new ArgumentException("-9p argument parameters must be in the format \"-9p textureName,a,b,c,d\" where a, b, c, and d are integers definining the border regions for the 9patch.");
|
||||
}
|
||||
}
|
||||
texturePacker.Save(Path.GetDirectoryName(output), Path.GetFileName(output));
|
||||
Console.WriteLine("Complete. Final texture size: " + texturePacker.TextureLength + "x" + texturePacker.TextureLength + ".");
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ArgumentException("-i not specified.");
|
||||
}
|
||||
texturePacker.Save(Path.GetDirectoryName(output), Path.GetFileName(output));
|
||||
Console.WriteLine("Complete. Final texture size: " + texturePacker.TextureLength + "x" + texturePacker.TextureLength + ".");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user