From 5c0e81e363dbf1b42116ceee2bdf900d9b4b95fa Mon Sep 17 00:00:00 2001 From: Harrison Deng Date: Sat, 8 Dec 2018 17:05:21 -0600 Subject: [PATCH] added serialization of the texture atlas data for texture packer's save function. --- .../TextureAtlasTools/TexturePacker.cs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/RecrownedAthenaeum.ConsoleTools/TextureAtlasTools/TexturePacker.cs b/RecrownedAthenaeum.ConsoleTools/TextureAtlasTools/TexturePacker.cs index 353c3a4..a745e0f 100644 --- a/RecrownedAthenaeum.ConsoleTools/TextureAtlasTools/TexturePacker.cs +++ b/RecrownedAthenaeum.ConsoleTools/TextureAtlasTools/TexturePacker.cs @@ -8,6 +8,7 @@ using RecrownedAthenaeum.Pipeline.NinePatch; using SixLabors.ImageSharp.Processing; using SixLabors.Primitives; using System.Linq; +using Newtonsoft.Json; namespace RecrownedAthenaeum.Tools.TextureAtlas { @@ -85,8 +86,9 @@ namespace RecrownedAthenaeum.Tools.TextureAtlas /// /// Renders the build into a PNG file and generates the respective meant for serialization and later to be loaded. /// - /// - public void Save(string output) + /// directory to output to. + /// name of atlas. + public void Save(string output, string atlasName) { GraphicsOptions gOptions = new GraphicsOptions(); @@ -104,13 +106,17 @@ namespace RecrownedAthenaeum.Tools.TextureAtlas regions[i].ninePatchData = imageH.ninePatchData; atlasTexture.Mutate(img => img.DrawImage(gOptions, imageH.image, new Point(imageH.x, imageH.y))); } - using (FileStream stream = new FileStream(output, FileMode.Create)) + using (FileStream stream = new FileStream(output + atlasName + ".png", FileMode.Create)) { atlasTexture.SaveAsPng(stream); } } + string serialized = JsonConvert.SerializeObject(new TextureAtlasData(atlasName + ".png", regions)); - + using (StreamWriter stream = new StreamWriter(output + atlasName + ".tatlas")) + { + stream.WriteLine(serialized); + } } public void SetNinePatch(string fileName, int a, int b, int c, int d)