From d73db03c72f8d2aac78ca4923312962492a42b1a Mon Sep 17 00:00:00 2001 From: Harrison Deng Date: Sat, 8 Dec 2018 17:06:11 -0600 Subject: [PATCH] command for texture packer added. --- .../RecrownedAthenaeum.Tools.csproj | 1 + .../TextureAtlasTools/TexturePackerCommand.cs | 46 +++++++++++++++++-- 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/RecrownedAthenaeum.ConsoleTools/RecrownedAthenaeum.Tools.csproj b/RecrownedAthenaeum.ConsoleTools/RecrownedAthenaeum.Tools.csproj index 8b581b6..b394c1a 100644 --- a/RecrownedAthenaeum.ConsoleTools/RecrownedAthenaeum.Tools.csproj +++ b/RecrownedAthenaeum.ConsoleTools/RecrownedAthenaeum.Tools.csproj @@ -10,6 +10,7 @@ + diff --git a/RecrownedAthenaeum.ConsoleTools/TextureAtlasTools/TexturePackerCommand.cs b/RecrownedAthenaeum.ConsoleTools/TextureAtlasTools/TexturePackerCommand.cs index 14265b9..8206a80 100644 --- a/RecrownedAthenaeum.ConsoleTools/TextureAtlasTools/TexturePackerCommand.cs +++ b/RecrownedAthenaeum.ConsoleTools/TextureAtlasTools/TexturePackerCommand.cs @@ -1,17 +1,57 @@ 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 void Run(string[] arguments) { - throw new NotImplementedException(); + 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."); + } + } } } }