2018-12-05 08:28:09 +00:00
|
|
|
|
using Microsoft.Xna.Framework.Content;
|
|
|
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using RecrownedAthenaeum.DataTypes;
|
|
|
|
|
using RecrownedAthenaeum.Pipeline.NinePatch;
|
|
|
|
|
using RecrownedAthenaeum.Pipeline.TextureAtlas;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.IO.Compression;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace RecrownedAthenaeum.Pipeline
|
|
|
|
|
{
|
|
|
|
|
class TextureAtlasDataReader : ContentTypeReader<DataTypes.TextureAtlas>
|
|
|
|
|
{
|
|
|
|
|
protected override DataTypes.TextureAtlas Read(ContentReader input, DataTypes.TextureAtlas existingInstance)
|
|
|
|
|
{
|
|
|
|
|
int length = input.ReadInt32();
|
2018-12-23 17:04:11 +00:00
|
|
|
|
byte[] bytes = input.ReadBytes(length);
|
|
|
|
|
TextureAtlasData atlasData = JsonConvert.DeserializeObject<TextureAtlasData>(Encoding.UTF8.GetString(bytes));
|
2018-12-05 08:28:09 +00:00
|
|
|
|
|
|
|
|
|
DataTypes.TextureAtlas atlas;
|
|
|
|
|
Texture2D atlasTexture = input.ContentManager.Load<Texture2D>(atlasData.textureName);
|
|
|
|
|
DataTypes.TextureAtlas.TextureAtlasRegion[] regions = new DataTypes.TextureAtlas.TextureAtlasRegion[atlasData.regions.Length];
|
|
|
|
|
|
|
|
|
|
for (int regionID = 0; regionID < regions.Length; regionID++)
|
|
|
|
|
{
|
|
|
|
|
TextureAtlasData.TextureAtlasRegion regionData = atlasData.regions[regionID];
|
|
|
|
|
DataTypes.NinePatch nPatch = null;
|
|
|
|
|
if (regionData.ninePatchData != null)
|
|
|
|
|
{
|
|
|
|
|
NinePatchData nPatchData = regionData.ninePatchData;
|
2018-12-29 06:29:31 +00:00
|
|
|
|
nPatch = new DataTypes.NinePatch(atlasTexture, nPatchData.left, nPatchData.right, nPatchData.down, nPatchData.down);
|
2018-12-05 08:28:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
regions[regionID] = new DataTypes.TextureAtlas.TextureAtlasRegion(regionData.name, regionData.location, nPatch, atlasTexture);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
atlas = new DataTypes.TextureAtlas(atlasTexture, regions);
|
|
|
|
|
|
|
|
|
|
return atlas;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|