recrownedathenaeum/RecrownedAthenaeum/Pipeline/TextureAtlasDataReader.cs

38 lines
1.6 KiB
C#
Raw Normal View History

using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Newtonsoft.Json;
using RecrownedAthenaeum.Serializable;
namespace RecrownedAthenaeum.Pipeline
{
2019-01-15 23:33:55 +00:00
class TextureAtlasDataReader : ContentTypeReader<SpecialTypes.TextureAtlas>
{
2019-01-15 23:33:55 +00:00
protected override SpecialTypes.TextureAtlas Read(ContentReader input, SpecialTypes.TextureAtlas existingInstance)
{
string serialized = input.ReadString();
TextureAtlasData atlasData = JsonConvert.DeserializeObject<TextureAtlasData>(serialized);
2019-01-15 23:33:55 +00:00
SpecialTypes.TextureAtlas atlas;
Texture2D atlasTexture = input.ContentManager.Load<Texture2D>(atlasData.textureName);
2019-01-15 23:33:55 +00:00
SpecialTypes.TextureAtlas.TextureAtlasRegion[] regions = new SpecialTypes.TextureAtlas.TextureAtlasRegion[atlasData.regions.Length];
for (int regionID = 0; regionID < regions.Length; regionID++)
{
2019-01-15 05:38:50 +00:00
TextureAtlasData.AtlasRegionData regionData = atlasData.regions[regionID];
2019-01-15 23:33:55 +00:00
SpecialTypes.NinePatch nPatch = null;
if (regionData.ninePatchData != null)
{
NinePatchData nPatchData = regionData.ninePatchData;
2019-01-15 23:33:55 +00:00
nPatch = new SpecialTypes.NinePatch(atlasTexture, nPatchData.left, nPatchData.right, nPatchData.bottom, nPatchData.bottom);
}
2019-01-15 23:33:55 +00:00
regions[regionID] = new SpecialTypes.TextureAtlas.TextureAtlasRegion(regionData.name, regionData.location, nPatch, atlasTexture);
}
2019-01-15 23:33:55 +00:00
atlas = new SpecialTypes.TextureAtlas(atlasTexture, regions);
return atlas;
}
}
}