diff --git a/RecrownedAthenaeum.Tools/CommandProcessor/EngineCommand.cs b/RecrownedAthenaeum.Tools/CommandProcessor/EngineCommand.cs index d11eae9..7e41ca6 100644 --- a/RecrownedAthenaeum.Tools/CommandProcessor/EngineCommand.cs +++ b/RecrownedAthenaeum.Tools/CommandProcessor/EngineCommand.cs @@ -162,6 +162,7 @@ namespace RecrownedAthenaeum.Tools.CommandProcessor for (int i = 0; i < commandArguments.Length; i++) { helpBuilder.Append(commandArguments[i].invokeString); + if (commandArguments[i].required) helpBuilder.Append('*'); if (i == commandArguments.Length - 2) { helpBuilder.Append(", and "); @@ -172,6 +173,7 @@ namespace RecrownedAthenaeum.Tools.CommandProcessor } } helpBuilder.Append('.'); + helpBuilder.AppendLine(" [* are required arguments.]"); } return helpBuilder.ToString(); } diff --git a/RecrownedAthenaeum.Tools/NinePatchTools/NinePatchCommand.cs b/RecrownedAthenaeum.Tools/NinePatchTools/NinePatchCommand.cs index dc39b3a..1069974 100644 --- a/RecrownedAthenaeum.Tools/NinePatchTools/NinePatchCommand.cs +++ b/RecrownedAthenaeum.Tools/NinePatchTools/NinePatchCommand.cs @@ -47,11 +47,12 @@ namespace RecrownedAthenaeum.Tools.NinePatchTools NinePatchData npData = new NinePatchData(Path.GetFileName(imagePath), leftBound, rightBound, bottomBound, topBound); string serialized = JsonConvert.SerializeObject(npData, Formatting.Indented); - - File.Move(imagePath, Path.GetFileNameWithoutExtension(imagePath) + "-texture" + Path.GetExtension(imagePath)); + string modifiedPath = Directory.GetParent(imagePath) + Path.PathSeparator.ToString() + Path.GetFileNameWithoutExtension(imagePath) + "-texture" + Path.GetExtension(imagePath); + File.Move(imagePath, modifiedPath); File.WriteAllText(outPath + ".9p", serialized); ConsoleUtilities.WriteWrappedLine("Done. Written to \"" + outPath + "\" with values: left = " + leftBound + " right = " + rightBound + " top = " + topBound + " bottom = " + bottomBound); + ConsoleUtilities.WriteWrappedLine("Image renamed to: " + Path.GetFileName(modifiedPath)); } } } diff --git a/RecrownedAthenaeum.Tools/TextureAtlasTools/TexturePacker.cs b/RecrownedAthenaeum.Tools/TextureAtlasTools/TexturePacker.cs index e98f67d..6de197b 100644 --- a/RecrownedAthenaeum.Tools/TextureAtlasTools/TexturePacker.cs +++ b/RecrownedAthenaeum.Tools/TextureAtlasTools/TexturePacker.cs @@ -22,12 +22,12 @@ namespace RecrownedAthenaeum.Tools.TextureAtlas int powLimit; Node masterNode; - Dictionary imageHandlersDictionary; + List imageHandlers; Dictionary ninePatchDictionary; int tpl; int TexturePowerLength { get { return tpl; } set { TextureLength = (int)Math.Pow(2, value); tpl = value; } } public int TextureLength { get; private set; } - public int TexturesFound { get { return imageHandlersDictionary.Count; } } + public int TexturesFound { get { return imageHandlers.Count; } } /// /// Machine to pack multiple textures into one large texture. /// @@ -52,8 +52,9 @@ namespace RecrownedAthenaeum.Tools.TextureAtlas for (int pathID = 0; pathID < paths.Length; pathID++) { SupportedExtensions extension; - if (Enum.TryParse(Path.GetExtension(paths[pathID]).ToLower().Substring(1), out extension)) + if (Enum.TryParse(Path.GetExtension(paths[pathID]).ToLower().Substring(1), out extension)) { + ConsoleUtilities.WriteWrappedLine("Reading texture data for: " + paths[pathID]); ImageHandler image = new ImageHandler(paths[pathID]); imageHandlers.Add(image); minAreaRequired += image.Area; @@ -72,11 +73,7 @@ namespace RecrownedAthenaeum.Tools.TextureAtlas } } imageHandlers.Sort(); - this.imageHandlersDictionary = new Dictionary(); - foreach (ImageHandler imageHandler in imageHandlers) - { - this.imageHandlersDictionary.Add(imageHandler.Name, imageHandler); - } + this.imageHandlers = imageHandlers; } /// @@ -88,7 +85,7 @@ namespace RecrownedAthenaeum.Tools.TextureAtlas masterNode = new Node(); masterNode.region.Width = TextureLength; masterNode.region.Height = TextureLength; - Queue imageHandlerQueue = new Queue(imageHandlersDictionary.Values); + Queue imageHandlerQueue = new Queue(imageHandlers); ImageHandler imageHandler; while (imageHandlerQueue.TryDequeue(out imageHandler)) { @@ -104,9 +101,14 @@ namespace RecrownedAthenaeum.Tools.TextureAtlas imageHandlerQueue.Clear(); Build(AutoCorrectAtlasSize); } - if (ninePatchDictionary != null && ninePatchDictionary.ContainsKey(imageHandler.Name)) + if (ninePatchDictionary != null && ninePatchDictionary.ContainsKey(imageHandler.name)) { - imageHandler.ninePatchData = ninePatchDictionary[imageHandler.Name]; + NinePatchData npd = ninePatchDictionary[imageHandler.name]; + imageHandler.ninePatchData = npd; + if (npd.textureName.Contains("-texture")) + { + imageHandler.name = imageHandler.name.Remove(imageHandler.name.IndexOf("-texture"), 8); + } } } @@ -121,11 +123,11 @@ namespace RecrownedAthenaeum.Tools.TextureAtlas { GraphicsOptions gOptions = new GraphicsOptions(); - TextureAtlasData.AtlasRegionData[] regions = new TextureAtlasData.AtlasRegionData[imageHandlersDictionary.Count]; + TextureAtlasData.AtlasRegionData[] regions = new TextureAtlasData.AtlasRegionData[TexturesFound]; using (Image atlasTexture = new Image(TextureLength, TextureLength)) { - ImageHandler[] imageHandlers = this.imageHandlersDictionary.Values.ToArray(); + ImageHandler[] imageHandlers = this.imageHandlers.ToArray(); for (int i = 0; i < imageHandlers.Length; i++) { @@ -133,8 +135,8 @@ namespace RecrownedAthenaeum.Tools.TextureAtlas ImageHandler ih = imageHandlers[i]; regions[i].SetBounds(ih.x, ih.y, ih.Width, ih.Height); regions[i].ninePatchData = ih.ninePatchData; - regions[i].ninePatchData.textureName = null; - regions[i].name = Path.GetFileNameWithoutExtension(ih.Name); + if (regions[i].ninePatchData != null) regions[i].ninePatchData.textureName = null; + regions[i].name = Path.GetFileNameWithoutExtension(ih.name); using (Image image = Image.Load(ih.path)) { atlasTexture.Mutate(img => img.DrawImage(gOptions, image, new Point(ih.x, ih.y))); @@ -152,14 +154,26 @@ namespace RecrownedAthenaeum.Tools.TextureAtlas public void SetNinePatch(string fileName, int a, int b, int c, int d) { - ImageHandler imageHandler = imageHandlersDictionary[fileName]; NinePatchData ninePatchData = new NinePatchData(fileName, a, b, c, d); - imageHandler.ninePatchData = ninePatchData; + RetrieveImageHandler(fileName).ninePatchData = ninePatchData; } - public void RemoveNinePatch(string fileName) + public void RemoveNinePatch(string name) { - imageHandlersDictionary[fileName].ninePatchData = null; + + RetrieveImageHandler(name).ninePatchData = null; + } + + private ImageHandler RetrieveImageHandler(string name) + { + for (int i = 0; i < TexturesFound; i++) + { + if (imageHandlers[i].name == name) + { + return imageHandlers[i]; + } + } + throw new ArgumentException("Couldn't find texture with name: " + name); } private class Node @@ -247,15 +261,16 @@ namespace RecrownedAthenaeum.Tools.TextureAtlas public readonly string path; public readonly IImageInfo image; public int Area { get { return image.Width * image.Height; } } - public string Name { get { return Path.GetFileName(path); } } + public string name; public int Width { get { return image.Width; } } public int Height { get { return image.Height; } } public int x, y; public NinePatchData ninePatchData; - internal ImageHandler(String path) + internal ImageHandler(string path) { this.path = path; + name = Path.GetFileName(path); try { using (FileStream stream = new FileStream(path, FileMode.Open)) diff --git a/RecrownedAthenaeum.Tools/TextureAtlasTools/TexturePackerCommand.cs b/RecrownedAthenaeum.Tools/TextureAtlasTools/TexturePackerCommand.cs index 1b66be3..38e371e 100644 --- a/RecrownedAthenaeum.Tools/TextureAtlasTools/TexturePackerCommand.cs +++ b/RecrownedAthenaeum.Tools/TextureAtlasTools/TexturePackerCommand.cs @@ -7,7 +7,8 @@ namespace RecrownedAthenaeum.Tools.TextureAtlasTools { class TexturePackerCommand : EngineCommand { - + private const int DMP = 9; + private const int DSP = 6; public TexturePackerCommand() : base("texturepacker") { 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."; @@ -16,8 +17,8 @@ namespace RecrownedAthenaeum.Tools.TextureAtlasTools new EngineCommandArgument("-i", "for input directory containing the textures.", true), new EngineCommandArgument("-o", "Path for output files. Points to non-existent file. Will create texture and definitions file with name.", true), 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\"."), - 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("-sp", "Starting power for one side of the texture. Default is " + DSP + "."), + new EngineCommandArgument("-mp", "Maximum power for one side of the texture. Default is " + DMP + "."), new EngineCommandArgument("-dau", "Disables automatically upscaling the texture."), }; } @@ -27,8 +28,8 @@ namespace RecrownedAthenaeum.Tools.TextureAtlasTools TexturePacker texturePacker = null; string path = null; - int mp = 9; - int sp = 6; + int mp = DMP; + int sp = DSP; bool dau = false; string output = null; @@ -48,7 +49,7 @@ namespace RecrownedAthenaeum.Tools.TextureAtlasTools 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 + "."); + ConsoleUtilities.WriteWrappedLine("Please enter a valid starting power of two for 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;