diff --git a/RecrownedAthenaeum.ConsoleTools/TextureAtlasTools/TexturePacker.cs b/RecrownedAthenaeum.ConsoleTools/TextureAtlasTools/TexturePacker.cs index 9136c7c..fcba488 100644 --- a/RecrownedAthenaeum.ConsoleTools/TextureAtlasTools/TexturePacker.cs +++ b/RecrownedAthenaeum.ConsoleTools/TextureAtlasTools/TexturePacker.cs @@ -24,6 +24,7 @@ namespace RecrownedAthenaeum.Tools.TextureAtlas int powLimit; Node masterNode; Dictionary imageHandlersDictionary; + Dictionary ninePatchDictionary; int tpl; int TexturePowerLength { get { return tpl; } set { TextureLength = (int)Math.Pow(2, value); tpl = value; } } public int TextureLength { get; private set; } @@ -37,7 +38,15 @@ namespace RecrownedAthenaeum.Tools.TextureAtlas internal TexturePacker(string rootDirectoryPath, int powLimit = 12, int startingPower = 8) { this.powLimit = powLimit; - string[] paths = Directory.GetFiles(rootDirectoryPath); + string[] paths; + try + { + paths = Directory.GetFiles(rootDirectoryPath); + + } catch (DirectoryNotFoundException) + { + throw new ArgumentException("Path " + rootDirectoryPath + " couldn't be found."); + } TexturePowerLength = startingPower; List imageHandlers = new List(); int minAreaRequired = 0; @@ -49,11 +58,20 @@ namespace RecrownedAthenaeum.Tools.TextureAtlas ImageHandler image = new ImageHandler(paths[pathID]); imageHandlers.Add(image); minAreaRequired += image.Area; - while (minAreaRequired > TextureLength*TextureLength) + while (minAreaRequired > TextureLength * TextureLength) { TexturePowerLength++; } } + else if (Path.GetExtension(paths[pathID]).ToLower() == ".9p") + { + if (ninePatchDictionary == null) ninePatchDictionary = new Dictionary(); + using (StreamReader streamReader = new StreamReader(paths[pathID])) + { + NinePatchData npData = JsonConvert.DeserializeObject(streamReader.ReadLine()); + ninePatchDictionary.Add(npData.textureName, npData); + } + } } imageHandlers.Sort(); this.imageHandlersDictionary = new Dictionary(); @@ -88,8 +106,12 @@ namespace RecrownedAthenaeum.Tools.TextureAtlas imageHandlerQueue.Clear(); Build(AutoCorrectAtlasSize); } - + if (ninePatchDictionary.ContainsKey(imageHandler.Name)) + { + imageHandler.ninePatchData = ninePatchDictionary[imageHandler.Name]; + } } + } ///