recrownedgtk/RecrownedAthenaeum/ContentReaders/NinePatchDataReader.cs

29 lines
1.1 KiB
C#
Raw Normal View History

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;
2019-01-21 03:45:15 +00:00
namespace RecrownedAthenaeum.ContentReaders
{
class NinePatchDataReader : ContentTypeReader<NinePatch>
{
2019-02-25 04:44:02 +00:00
public static GraphicsDevice graphicsDevice;
protected override NinePatch Read(ContentReader input, NinePatch existingInstance)
{
2019-02-25 04:44:02 +00:00
if (graphicsDevice == null) graphicsDevice = Configuration.GraphicsDeviceManager.GraphicsDevice;
Texture2D texture;
using (MemoryStream stream = new MemoryStream(input.ReadBytes(input.ReadInt32())))
{
2019-02-25 04:44:02 +00:00
texture = Texture2D.FromStream(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;
}
}
}