refactor
This commit is contained in:
17
RecrownedAthenaeum/ContentReaders/NinePatchDataReader.cs
Normal file
17
RecrownedAthenaeum/ContentReaders/NinePatchDataReader.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using Microsoft.Xna.Framework.Content;
|
||||
using Newtonsoft.Json;
|
||||
using System.Text;
|
||||
|
||||
namespace RecrownedAthenaeum.ContentReaders
|
||||
{
|
||||
class NinePatchDataReader : ContentTypeReader<SpecialTypes.NinePatch>
|
||||
{
|
||||
protected override SpecialTypes.NinePatch Read(ContentReader input, SpecialTypes.NinePatch existingInstance)
|
||||
{
|
||||
int length = input.ReadInt32();
|
||||
byte[] bytes = input.ReadBytes(length);
|
||||
|
||||
return JsonConvert.DeserializeObject<SpecialTypes.NinePatch>(Encoding.UTF8.GetString(bytes));
|
||||
}
|
||||
}
|
||||
}
|
40
RecrownedAthenaeum/ContentReaders/TextureAtlasDataReader.cs
Normal file
40
RecrownedAthenaeum/ContentReaders/TextureAtlasDataReader.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using Microsoft.Xna.Framework.Content;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Newtonsoft.Json;
|
||||
using RecrownedAthenaeum.Data;
|
||||
using RecrownedAthenaeum.SpecialTypes;
|
||||
|
||||
namespace RecrownedAthenaeum.ContentReaders
|
||||
{
|
||||
class TextureAtlasDataReader : ContentTypeReader<TextureAtlas>
|
||||
{
|
||||
protected override TextureAtlas Read(ContentReader input, TextureAtlas existingInstance)
|
||||
{
|
||||
string serialized = input.ReadString();
|
||||
TextureAtlasData atlasData = JsonConvert.DeserializeObject<TextureAtlasData>(serialized);
|
||||
Texture2D atlasTexture = input.ContentManager.Load<Texture2D>(atlasData.textureName);
|
||||
TextureAtlas atlas = new TextureAtlas(atlasTexture, GenerateAtlasRegionsFromData(atlasData, atlasTexture));
|
||||
|
||||
return atlas;
|
||||
}
|
||||
|
||||
public TextureAtlas.Region[] GenerateAtlasRegionsFromData(TextureAtlasData textureAtlasData, Texture2D atlasTexture)
|
||||
{
|
||||
TextureAtlas.Region[] regions = new TextureAtlas.Region[textureAtlasData.regions.Length];
|
||||
for (int regionID = 0; regionID < regions.Length; regionID++)
|
||||
{
|
||||
TextureAtlasData.AtlasRegionData regionData = textureAtlasData.regions[regionID];
|
||||
NinePatch nPatch = null;
|
||||
if (regionData.ninePatchData != null)
|
||||
{
|
||||
NinePatchData nPatchData = regionData.ninePatchData;
|
||||
nPatch = new NinePatch(atlasTexture, nPatchData.left, nPatchData.right, nPatchData.bottom, nPatchData.bottom);
|
||||
}
|
||||
|
||||
regions[regionID] = new TextureAtlas.Region(regionData.name, regionData.location, nPatch, atlasTexture);
|
||||
}
|
||||
|
||||
return regions;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user