48 lines
1.9 KiB
C#
48 lines
1.9 KiB
C#
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();
|
|
byte[] bytes = input.ReadBytes(length);
|
|
TextureAtlasData atlasData = JsonConvert.DeserializeObject<TextureAtlasData>(Encoding.UTF8.GetString(bytes));
|
|
|
|
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;
|
|
nPatch = new DataTypes.NinePatch(atlasTexture, nPatchData.a, nPatchData.b, nPatchData.c, nPatchData.d);
|
|
}
|
|
|
|
regions[regionID] = new DataTypes.TextureAtlas.TextureAtlasRegion(regionData.name, regionData.location, nPatch, atlasTexture);
|
|
}
|
|
|
|
atlas = new DataTypes.TextureAtlas(atlasTexture, regions);
|
|
|
|
return atlas;
|
|
}
|
|
}
|
|
}
|