using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; using Newtonsoft.Json; using RecrownedAthenaeum.Pipeline.NinePatch; using RecrownedAthenaeum.Pipeline.TextureAtlas; using System.Text; namespace RecrownedAthenaeum.Pipeline { class TextureAtlasDataReader : ContentTypeReader { protected override DataTypes.TextureAtlas Read(ContentReader input, DataTypes.TextureAtlas existingInstance) { string serialized = input.ReadString(); TextureAtlasData atlasData = JsonConvert.DeserializeObject(serialized); DataTypes.TextureAtlas atlas; Texture2D atlasTexture = input.ContentManager.Load(atlasData.textureName); DataTypes.TextureAtlas.TextureAtlasRegion[] regions = new DataTypes.TextureAtlas.TextureAtlasRegion[atlasData.regions.Length]; for (int regionID = 0; regionID < regions.Length; regionID++) { TextureAtlasData.TextureAtlasRegion regionData = atlasData.regions[regionID]; DataTypes.NinePatch nPatch = null; if (regionData.ninePatchData != null) { NinePatchData nPatchData = regionData.ninePatchData; nPatch = new DataTypes.NinePatch(atlasTexture, nPatchData.left, nPatchData.right, nPatchData.down, nPatchData.down); } regions[regionID] = new DataTypes.TextureAtlas.TextureAtlasRegion(regionData.name, regionData.location, nPatch, atlasTexture); } atlas = new DataTypes.TextureAtlas(atlasTexture, regions); return atlas; } } }