Added basic interactive mode to texture packer command.

This commit is contained in:
Harrison Deng 2018-12-29 01:10:40 -06:00
parent d154f1f749
commit c62361da2f

View File

@ -12,7 +12,9 @@ namespace RecrownedAthenaeum.Tools.TextureAtlasTools
public TexturePackerCommand() : base("texturepacker") public TexturePackerCommand() : base("texturepacker")
{ {
arguments = new EngineCommandArgument[6] { help = "Packs a given directory composed of png and jpg files into an atlas. Can also add 9patch properties. Images with the associated \".9p\" files will automatically be defined in the resulting .tatlas file, but can be overwritten by use of the \"-9p\" argument.";
arguments = new EngineCommandArgument[7] {
new EngineCommandArgument("-interactive", "runs in interactive mode. Ninepatches must still be defined with arguments or previously defined with associated \".9p\" files. Other arguments will be ignored."),
new EngineCommandArgument("-i", "for input directory containing the textures. Required."), 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("-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("-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."),
@ -21,7 +23,6 @@ namespace RecrownedAthenaeum.Tools.TextureAtlasTools
new EngineCommandArgument("-dau", "Disables automatically upscaling the texture."), 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. Running without arguments triggers interactive mode.";
} }
public override void Run(string[] arguments) public override void Run(string[] arguments)
@ -29,21 +30,49 @@ namespace RecrownedAthenaeum.Tools.TextureAtlasTools
TexturePacker texturePacker = null; TexturePacker texturePacker = null;
string path = null; string path = null;
int mp = 8; int mp = 9;
int sp = 8; int sp = 6;
bool dau = false; bool dau = false;
string output = null; string output = null;
if (arguments == null) if (HasArgument("-interactive", arguments))
{ {
string input;
ConsoleUtilities.WriteWrappedLine("Texture packer interactive mode triggered. Type \"q\" at any time to exit.");
ConsoleUtilities.WriteWrappedLine("Please enter path of folder containing the textures to be packed.");
input = Console.ReadLine();
if (input == "q") return;
path = input;
ConsoleUtilities.WriteWrappedLine("Please enter output path of file name.");
input = Console.ReadLine();
if (input == "q") return;
output = input;
do
{
ConsoleUtilities.WriteWrappedLine("Please enter a valid starting power of two of the lengths of the resulting texture atlas. Leave blank for default of " + sp + ".");
input = Console.ReadLine();
if (input == "q") return;
if (input.Length == 0) break;
} while (!int.TryParse(input, out sp));
do
{
ConsoleUtilities.WriteWrappedLine("Please enter a valid maximum power by two of the lengths of the resulting texture atlas. Leave blank for default of " + mp + ".");
input = Console.ReadLine();
if (input == "q") return;
if (input.Length == 0) break;
} while (!int.TryParse(input, out mp));
}
else
{
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;
} }
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); texturePacker = new TexturePacker(path, mp, sp);
ConsoleUtilities.WriteWrappedLine("Calculated minimum texture size: " + texturePacker.TextureLength + "x" + texturePacker.TextureLength + " with a total of " + texturePacker.TexturesFound + " textures."); ConsoleUtilities.WriteWrappedLine("Calculated minimum texture size: " + texturePacker.TextureLength + "x" + texturePacker.TextureLength + " with a total of " + texturePacker.TexturesFound + " textures.");