using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; using Newtonsoft.Json; using RecrownedAthenaeum.Data; using RecrownedAthenaeum.SpecialTypes; using System.IO; using System.Text; namespace RecrownedAthenaeum.ContentReaders { class NinePatchDataReader : ContentTypeReader { protected override NinePatch Read(ContentReader input, NinePatch existingInstance) { Texture2D texture; using (MemoryStream stream = new MemoryStream(input.ReadBytes(input.ReadInt32()))) { texture = Texture2D.FromStream(Configuration.GraphicsDeviceManager.GraphicsDevice, stream); } NinePatchData ninePatchData = JsonConvert.DeserializeObject(Encoding.ASCII.GetString(input.ReadBytes(input.ReadInt32()))); NinePatch ninePatch = new NinePatch(texture, ninePatchData.left, ninePatchData.right, ninePatchData.bottom, ninePatchData.top); return ninePatch; } } }