Added setup system. Changed reader and writer for texture atlas and nine patch to have image and serialized data be in same file. Some refactors occurred as well.

This commit is contained in:
2019-01-21 19:56:51 -06:00
parent fbf6c5d1aa
commit ea6b3cf9e3
18 changed files with 145 additions and 111 deletions

View File

@@ -1,15 +1,25 @@
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<SpecialTypes.NinePatch>
class NinePatchDataReader : ContentTypeReader<NinePatch>
{
protected override SpecialTypes.NinePatch Read(ContentReader input, SpecialTypes.NinePatch existingInstance)
protected override NinePatch Read(ContentReader input, NinePatch existingInstance)
{
string serialized = input.ReadString();
return JsonConvert.DeserializeObject<SpecialTypes.NinePatch>(serialized);
Texture2D texture;
using (MemoryStream stream = new MemoryStream(input.ReadBytes(input.ReadInt32())))
{
texture = Texture2D.FromStream(Setup.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;
}
}
}

View File

@@ -4,6 +4,7 @@ using Newtonsoft.Json;
using RecrownedAthenaeum.Data;
using RecrownedAthenaeum.SpecialTypes;
using System.IO;
using System.Text;
namespace RecrownedAthenaeum.ContentReaders
{
@@ -11,9 +12,14 @@ namespace RecrownedAthenaeum.ContentReaders
{
protected override TextureAtlas Read(ContentReader input, TextureAtlas existingInstance)
{
string serialized = input.ReadString();
TextureAtlasData atlasData = JsonConvert.DeserializeObject<TextureAtlasData>(serialized);
Texture2D atlasTexture = input.ContentManager.Load<Texture2D>(Path.GetFileNameWithoutExtension(atlasData.textureName));
TextureAtlasData atlasData;
Texture2D atlasTexture;
using (MemoryStream stream = new MemoryStream(input.ReadBytes(input.ReadInt32())))
{
atlasTexture = Texture2D.FromStream(Setup.graphicsDeviceManager.GraphicsDevice, stream);
}
string serialized = Encoding.ASCII.GetString(input.ReadBytes(input.ReadInt32()));
atlasData = JsonConvert.DeserializeObject<TextureAtlasData>(serialized);
TextureAtlas atlas = new TextureAtlas(atlasTexture, GenerateAtlasRegionsFromData(atlasData, atlasTexture));
return atlas;
@@ -35,10 +41,9 @@ namespace RecrownedAthenaeum.ContentReaders
if (regionData.ninePatchData != null)
{
NinePatchData nPatchData = regionData.ninePatchData;
nPatch = new NinePatch(atlasTexture, nPatchData.left, nPatchData.right, nPatchData.bottom, nPatchData.bottom);
nPatch = new NinePatch(atlasTexture, nPatchData.left, nPatchData.right, nPatchData.bottom, nPatchData.bottom, regionData.bounds);
}
regions[regionID] = new TextureAtlas.Region(regionData.name, regionData.location, nPatch, atlasTexture);
regions[regionID] = new TextureAtlas.Region(regionData.name, regionData.bounds, nPatch, atlasTexture);
}
return regions;