Exposes function to generate regions from data and texture.
This commit is contained in:
parent
823b210c75
commit
cc0203f111
@ -2,36 +2,39 @@
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Newtonsoft.Json;
|
||||
using RecrownedAthenaeum.Serializable;
|
||||
using RecrownedAthenaeum.SpecialTypes;
|
||||
|
||||
namespace RecrownedAthenaeum.Pipeline
|
||||
{
|
||||
class TextureAtlasDataReader : ContentTypeReader<SpecialTypes.TextureAtlas>
|
||||
class TextureAtlasDataReader : ContentTypeReader<TextureAtlas>
|
||||
{
|
||||
protected override SpecialTypes.TextureAtlas Read(ContentReader input, SpecialTypes.TextureAtlas existingInstance)
|
||||
protected override TextureAtlas Read(ContentReader input, TextureAtlas existingInstance)
|
||||
{
|
||||
string serialized = input.ReadString();
|
||||
TextureAtlasData atlasData = JsonConvert.DeserializeObject<TextureAtlasData>(serialized);
|
||||
|
||||
SpecialTypes.TextureAtlas atlas;
|
||||
Texture2D atlasTexture = input.ContentManager.Load<Texture2D>(atlasData.textureName);
|
||||
SpecialTypes.TextureAtlas.TextureAtlasRegion[] regions = new SpecialTypes.TextureAtlas.TextureAtlasRegion[atlasData.regions.Length];
|
||||
|
||||
for (int regionID = 0; regionID < regions.Length; regionID++)
|
||||
{
|
||||
TextureAtlasData.AtlasRegionData regionData = atlasData.regions[regionID];
|
||||
SpecialTypes.NinePatch nPatch = null;
|
||||
if (regionData.ninePatchData != null)
|
||||
{
|
||||
NinePatchData nPatchData = regionData.ninePatchData;
|
||||
nPatch = new SpecialTypes.NinePatch(atlasTexture, nPatchData.left, nPatchData.right, nPatchData.bottom, nPatchData.bottom);
|
||||
}
|
||||
|
||||
regions[regionID] = new SpecialTypes.TextureAtlas.TextureAtlasRegion(regionData.name, regionData.location, nPatch, atlasTexture);
|
||||
}
|
||||
|
||||
atlas = new SpecialTypes.TextureAtlas(atlasTexture, regions);
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user