recrownedgtk/RecrownedAthenaeum/ContentReaders/NinePatchDataReader.cs
2019-01-21 22:18:22 -06:00

26 lines
1.0 KiB
C#

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<NinePatch>
{
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<NinePatchData>(Encoding.ASCII.GetString(input.ReadBytes(input.ReadInt32())));
NinePatch ninePatch = new NinePatch(texture, ninePatchData.left, ninePatchData.right, ninePatchData.bottom, ninePatchData.top);
return ninePatch;
}
}
}