Refactoring
This commit is contained in:
37
RecrownedAthenaeum/Pipeline/NinePatchData.cs
Normal file
37
RecrownedAthenaeum/Pipeline/NinePatchData.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using RecrownedAthenaeum.Pipeline.TextureAtlas;
|
||||
|
||||
namespace RecrownedAthenaeum.Pipeline
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a data structure for 9patches.
|
||||
/// </summary>
|
||||
public class NinePatchData
|
||||
{
|
||||
/// <summary>
|
||||
/// Name of texture associated with patch. May be null in the case of being apart of a <see cref="TextureAtlasData"/>
|
||||
/// </summary>
|
||||
public string textureName;
|
||||
|
||||
/// <summary>
|
||||
/// the boundaries of the patch.
|
||||
/// </summary>
|
||||
public int left, right, bottom, top;
|
||||
|
||||
/// <summary>
|
||||
/// Constructs patch.
|
||||
/// </summary>
|
||||
/// <param name="textureName">Name of the texture. May be null.</param>
|
||||
/// <param name="left">Left bound.</param>
|
||||
/// <param name="right">Right bound.</param>
|
||||
/// <param name="bottom">Bottom bound.</param>
|
||||
/// <param name="Top">Top bound.</param>
|
||||
public NinePatchData(string textureName, int left, int right, int bottom, int Top)
|
||||
{
|
||||
this.textureName = textureName;
|
||||
this.left = left;
|
||||
this.right = right;
|
||||
this.bottom = bottom;
|
||||
this.top = Top;
|
||||
}
|
||||
}
|
||||
}
|
@@ -4,14 +4,14 @@ using System.Text;
|
||||
|
||||
namespace RecrownedAthenaeum.Pipeline
|
||||
{
|
||||
class NinePatchDataReader : ContentTypeReader<DataTypes.NinePatch>
|
||||
class NinePatchDataReader : ContentTypeReader<SpecialTypes.NinePatch>
|
||||
{
|
||||
protected override DataTypes.NinePatch Read(ContentReader input, DataTypes.NinePatch existingInstance)
|
||||
protected override SpecialTypes.NinePatch Read(ContentReader input, SpecialTypes.NinePatch existingInstance)
|
||||
{
|
||||
int length = input.ReadInt32();
|
||||
byte[] bytes = input.ReadBytes(length);
|
||||
|
||||
return JsonConvert.DeserializeObject<DataTypes.NinePatch>(Encoding.UTF8.GetString(bytes));
|
||||
return JsonConvert.DeserializeObject<SpecialTypes.NinePatch>(Encoding.UTF8.GetString(bytes));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
84
RecrownedAthenaeum/Pipeline/TextureAtlasData.cs
Normal file
84
RecrownedAthenaeum/Pipeline/TextureAtlasData.cs
Normal file
@@ -0,0 +1,84 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
|
||||
namespace RecrownedAthenaeum.Pipeline
|
||||
{
|
||||
/// <summary>
|
||||
/// Data transfer object for a texture atlas.
|
||||
/// </summary>
|
||||
public class TextureAtlasData
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains the regions of the texture atlas.
|
||||
/// </summary>
|
||||
public AtlasRegionData[] regions;
|
||||
/// <summary>
|
||||
/// The name of the file.
|
||||
/// </summary>
|
||||
public string textureName;
|
||||
|
||||
/// <summary>
|
||||
/// Creates the atlas given the regions and the file name of the texture file to be used.
|
||||
/// </summary>
|
||||
/// <param name="textureName"></param>
|
||||
/// <param name="regions"></param>
|
||||
public TextureAtlasData(string textureName, AtlasRegionData[] regions)
|
||||
{
|
||||
this.regions = regions;
|
||||
this.textureName = textureName;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Data object that contains information about the region ninepatch situation of a given region in an atlas.
|
||||
/// </summary>
|
||||
public class AtlasRegionData
|
||||
{
|
||||
/// <summary>
|
||||
/// Name of the region for referencial purposes.
|
||||
/// </summary>
|
||||
public string name;
|
||||
/// <summary>
|
||||
/// The location of the patch is designated by this rectangle.
|
||||
/// </summary>
|
||||
public Rectangle location;
|
||||
/// <summary>
|
||||
/// The ninepatch information.
|
||||
/// </summary>
|
||||
public NinePatchData ninePatchData;
|
||||
|
||||
/// <summary>
|
||||
/// Sets position in atlas for convenience.
|
||||
/// </summary>
|
||||
/// <param name="x">X coordinate of the position in the patch.</param>
|
||||
/// <param name="y">Y coordinate of the position in the patch.</param>
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
location.X = x;
|
||||
location.Y = y;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the dimensions of the region on the atlas for convenience.
|
||||
/// </summary>
|
||||
/// <param name="width">Width of the region.</param>
|
||||
/// <param name="height">Height of the region.</param>
|
||||
public void SetSize(int width, int height)
|
||||
{
|
||||
location.Width = width;
|
||||
location.Height = height;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets both the coordinates and dimensions of the region on the atlas for convenience.
|
||||
/// </summary>
|
||||
/// <param name="x">X coordinate of the position in the patch.</param>
|
||||
/// <param name="y">Y coordinate of the position in the patch.</param>
|
||||
/// <param name="width">Width of the region.</param>
|
||||
/// <param name="height">Height of the region.</param>
|
||||
public void SetBounds(int x, int y, int width, int height)
|
||||
{
|
||||
SetPosition(x, y);
|
||||
SetSize(width, height);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -7,31 +7,31 @@ using System.Text;
|
||||
|
||||
namespace RecrownedAthenaeum.Pipeline
|
||||
{
|
||||
class TextureAtlasDataReader : ContentTypeReader<DataTypes.TextureAtlas>
|
||||
class TextureAtlasDataReader : ContentTypeReader<SpecialTypes.TextureAtlas>
|
||||
{
|
||||
protected override DataTypes.TextureAtlas Read(ContentReader input, DataTypes.TextureAtlas existingInstance)
|
||||
protected override SpecialTypes.TextureAtlas Read(ContentReader input, SpecialTypes.TextureAtlas existingInstance)
|
||||
{
|
||||
string serialized = input.ReadString();
|
||||
TextureAtlasData atlasData = JsonConvert.DeserializeObject<TextureAtlasData>(serialized);
|
||||
|
||||
DataTypes.TextureAtlas atlas;
|
||||
SpecialTypes.TextureAtlas atlas;
|
||||
Texture2D atlasTexture = input.ContentManager.Load<Texture2D>(atlasData.textureName);
|
||||
DataTypes.TextureAtlas.TextureAtlasRegion[] regions = new DataTypes.TextureAtlas.TextureAtlasRegion[atlasData.regions.Length];
|
||||
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];
|
||||
DataTypes.NinePatch nPatch = null;
|
||||
SpecialTypes.NinePatch nPatch = null;
|
||||
if (regionData.ninePatchData != null)
|
||||
{
|
||||
NinePatchData nPatchData = regionData.ninePatchData;
|
||||
nPatch = new DataTypes.NinePatch(atlasTexture, nPatchData.left, nPatchData.right, nPatchData.bottom, nPatchData.bottom);
|
||||
nPatch = new SpecialTypes.NinePatch(atlasTexture, nPatchData.left, nPatchData.right, nPatchData.bottom, nPatchData.bottom);
|
||||
}
|
||||
|
||||
regions[regionID] = new DataTypes.TextureAtlas.TextureAtlasRegion(regionData.name, regionData.location, nPatch, atlasTexture);
|
||||
regions[regionID] = new SpecialTypes.TextureAtlas.TextureAtlasRegion(regionData.name, regionData.location, nPatch, atlasTexture);
|
||||
}
|
||||
|
||||
atlas = new DataTypes.TextureAtlas(atlasTexture, regions);
|
||||
atlas = new SpecialTypes.TextureAtlas(atlasTexture, regions);
|
||||
|
||||
return atlas;
|
||||
}
|
||||
|
Reference in New Issue
Block a user