67 lines
3.1 KiB
C#
67 lines
3.1 KiB
C#
using RecrownedAthenaeum.Tools.CommandProcessor;
|
|
using RecrownedAthenaeum.Tools.TextureAtlas;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Text;
|
|
|
|
namespace RecrownedAthenaeum.Tools.TextureAtlasTools
|
|
{
|
|
class TexturePackerCommand : ICommandEngineCommand
|
|
{
|
|
TexturePacker texturePacker;
|
|
|
|
public string Help(string argument)
|
|
{
|
|
return "Packs a given directory composed of png and jpg files into an atlas. Can also add 9patch properties.\n" +
|
|
"-i path for input directory containing the textures. Required." +
|
|
"-o path for output files. Should point to a non-existent file with no extension as the extension will be created for both the atlas definition file and texture file. Required.\n" +
|
|
"-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.";
|
|
}
|
|
|
|
public void Run(string[] arguments)
|
|
{
|
|
for (int i = 0; i < arguments.Length; i++)
|
|
{
|
|
if (arguments[i] == "-i")
|
|
{
|
|
if (i + 1 >= arguments.Length) throw new ArgumentException("-i is not followed by path for input directory.");
|
|
texturePacker = new TexturePacker((arguments[i + 1]));
|
|
}
|
|
}
|
|
texturePacker.Build();
|
|
|
|
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
|
|
{
|
|
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.");
|
|
}
|
|
}
|
|
}
|
|
|
|
for (int i = 0; i < arguments.Length; i++)
|
|
{
|
|
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.)");
|
|
texturePacker.Save(Path.GetDirectoryName(arguments[i + 1]), Path.GetFileName(arguments[i + 1]));
|
|
return;
|
|
}
|
|
|
|
if (i == arguments.Length - 1)
|
|
{
|
|
throw new ArgumentException("no -o argument found to specify output.");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|