2018-12-05 08:28:09 +00:00
|
|
|
|
using Microsoft.Xna.Framework.Content;
|
|
|
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
|
|
|
using Newtonsoft.Json;
|
2019-01-20 07:07:52 +00:00
|
|
|
|
using RecrownedAthenaeum.Data;
|
2019-01-16 01:33:22 +00:00
|
|
|
|
using RecrownedAthenaeum.SpecialTypes;
|
2018-12-05 08:28:09 +00:00
|
|
|
|
|
2019-01-21 03:45:15 +00:00
|
|
|
|
namespace RecrownedAthenaeum.ContentReaders
|
2018-12-05 08:28:09 +00:00
|
|
|
|
{
|
2019-01-16 01:33:22 +00:00
|
|
|
|
class TextureAtlasDataReader : ContentTypeReader<TextureAtlas>
|
2018-12-05 08:28:09 +00:00
|
|
|
|
{
|
2019-01-16 01:33:22 +00:00
|
|
|
|
protected override TextureAtlas Read(ContentReader input, TextureAtlas existingInstance)
|
2018-12-05 08:28:09 +00:00
|
|
|
|
{
|
2019-01-14 04:05:34 +00:00
|
|
|
|
string serialized = input.ReadString();
|
|
|
|
|
TextureAtlasData atlasData = JsonConvert.DeserializeObject<TextureAtlasData>(serialized);
|
2019-01-20 07:07:52 +00:00
|
|
|
|
Texture2D atlasTexture = input.ContentManager.Load<Texture2D>(atlasData.textureName);
|
2019-01-16 01:33:22 +00:00
|
|
|
|
TextureAtlas atlas = new TextureAtlas(atlasTexture, GenerateAtlasRegionsFromData(atlasData, atlasTexture));
|
2018-12-05 08:28:09 +00:00
|
|
|
|
|
2019-01-16 01:33:22 +00:00
|
|
|
|
return atlas;
|
|
|
|
|
}
|
2018-12-05 08:28:09 +00:00
|
|
|
|
|
2019-01-16 01:33:22 +00:00
|
|
|
|
public TextureAtlas.Region[] GenerateAtlasRegionsFromData(TextureAtlasData textureAtlasData, Texture2D atlasTexture)
|
|
|
|
|
{
|
|
|
|
|
TextureAtlas.Region[] regions = new TextureAtlas.Region[textureAtlasData.regions.Length];
|
2018-12-05 08:28:09 +00:00
|
|
|
|
for (int regionID = 0; regionID < regions.Length; regionID++)
|
|
|
|
|
{
|
2019-01-16 01:33:22 +00:00
|
|
|
|
TextureAtlasData.AtlasRegionData regionData = textureAtlasData.regions[regionID];
|
|
|
|
|
NinePatch nPatch = null;
|
2018-12-05 08:28:09 +00:00
|
|
|
|
if (regionData.ninePatchData != null)
|
|
|
|
|
{
|
|
|
|
|
NinePatchData nPatchData = regionData.ninePatchData;
|
2019-01-16 01:33:22 +00:00
|
|
|
|
nPatch = new NinePatch(atlasTexture, nPatchData.left, nPatchData.right, nPatchData.bottom, nPatchData.bottom);
|
2018-12-05 08:28:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-01-16 01:33:22 +00:00
|
|
|
|
regions[regionID] = new TextureAtlas.Region(regionData.name, regionData.location, nPatch, atlasTexture);
|
2018-12-05 08:28:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-01-16 01:33:22 +00:00
|
|
|
|
return regions;
|
2018-12-05 08:28:09 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|