added serialization of the texture atlas data for texture packer's save function.

This commit is contained in:
Harrison Deng 2018-12-08 17:05:21 -06:00
parent 34ef18f682
commit 5c0e81e363

View File

@ -8,6 +8,7 @@ using RecrownedAthenaeum.Pipeline.NinePatch;
using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing;
using SixLabors.Primitives; using SixLabors.Primitives;
using System.Linq; using System.Linq;
using Newtonsoft.Json;
namespace RecrownedAthenaeum.Tools.TextureAtlas namespace RecrownedAthenaeum.Tools.TextureAtlas
{ {
@ -85,8 +86,9 @@ namespace RecrownedAthenaeum.Tools.TextureAtlas
/// <summary> /// <summary>
/// Renders the build into a PNG file and generates the respective <see cref="TextureAtlasData"/> meant for serialization and later to be loaded. /// Renders the build into a PNG file and generates the respective <see cref="TextureAtlasData"/> meant for serialization and later to be loaded.
/// </summary> /// </summary>
/// <param name="output"></param> /// <param name="output">directory to output to.</param>
public void Save(string output) /// <param name="atlasName">name of atlas.</param>
public void Save(string output, string atlasName)
{ {
GraphicsOptions gOptions = new GraphicsOptions(); GraphicsOptions gOptions = new GraphicsOptions();
@ -104,13 +106,17 @@ namespace RecrownedAthenaeum.Tools.TextureAtlas
regions[i].ninePatchData = imageH.ninePatchData; regions[i].ninePatchData = imageH.ninePatchData;
atlasTexture.Mutate(img => img.DrawImage(gOptions, imageH.image, new Point(imageH.x, imageH.y))); 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); 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) public void SetNinePatch(string fileName, int a, int b, int c, int d)