From cc0203f1110f8d403f95fb0ac57eef3393968b83 Mon Sep 17 00:00:00 2001 From: Harrison Deng Date: Tue, 15 Jan 2019 19:33:22 -0600 Subject: [PATCH] Exposes function to generate regions from data and texture. --- .../Pipeline/TextureAtlasDataReader.cs | 45 ++++++++++--------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/RecrownedAthenaeum/Pipeline/TextureAtlasDataReader.cs b/RecrownedAthenaeum/Pipeline/TextureAtlasDataReader.cs index b8081b9..8ed0c45 100644 --- a/RecrownedAthenaeum/Pipeline/TextureAtlasDataReader.cs +++ b/RecrownedAthenaeum/Pipeline/TextureAtlasDataReader.cs @@ -2,36 +2,39 @@ using Microsoft.Xna.Framework.Graphics; using Newtonsoft.Json; using RecrownedAthenaeum.Serializable; +using RecrownedAthenaeum.SpecialTypes; namespace RecrownedAthenaeum.Pipeline { - class TextureAtlasDataReader : ContentTypeReader + class TextureAtlasDataReader : ContentTypeReader { - 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(serialized); - - SpecialTypes.TextureAtlas atlas; - Texture2D atlasTexture = input.ContentManager.Load(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(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; + } } }