untested texture atlas pipeline system complete.
This commit is contained in:
59
RecrownedAthenaeum/Pipeline/TextureAtlasDataReader.cs
Normal file
59
RecrownedAthenaeum/Pipeline/TextureAtlasDataReader.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
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[] compressedBytes = input.ReadBytes(length);
|
||||
byte[] decompressedBytes;
|
||||
using (MemoryStream inStream = new MemoryStream(compressedBytes))
|
||||
{
|
||||
using (GZipStream gZStream = new GZipStream(inStream, CompressionLevel.Optimal))
|
||||
{
|
||||
using (MemoryStream outStream = new MemoryStream())
|
||||
{
|
||||
gZStream.CopyTo(outStream);
|
||||
decompressedBytes = outStream.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
TextureAtlasData atlasData = JsonConvert.DeserializeObject<TextureAtlasData>(Encoding.UTF8.GetString(decompressedBytes));
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user