From 8ddb79c1354f6a70989a270f07b1b7d51c5f8e83 Mon Sep 17 00:00:00 2001 From: Harrison Deng Date: Tue, 11 Dec 2018 20:03:35 -0600 Subject: [PATCH] added documentation and cleaned up some parameters. Added obtain and draw functions to the skin class. --- RecrownedAthenaeum/DataTypes/TextureAtlas.cs | 47 ++++++++++++++----- RecrownedAthenaeum/Properties/AssemblyInfo.cs | 4 +- RecrownedAthenaeum/UI/Skin/Skin.cs | 14 +++++- 3 files changed, 50 insertions(+), 15 deletions(-) diff --git a/RecrownedAthenaeum/DataTypes/TextureAtlas.cs b/RecrownedAthenaeum/DataTypes/TextureAtlas.cs index c421b32..12697e5 100644 --- a/RecrownedAthenaeum/DataTypes/TextureAtlas.cs +++ b/RecrownedAthenaeum/DataTypes/TextureAtlas.cs @@ -13,7 +13,6 @@ namespace RecrownedAthenaeum.DataTypes { public class TextureAtlas { - [JsonIgnore] private Texture2D texture; private Dictionary dictionaryOfRegions = new Dictionary(); @@ -33,15 +32,29 @@ namespace RecrownedAthenaeum.DataTypes this.dictionaryOfRegions = dictionaryOfRegions; } - public void Draw(string name, SpriteBatch batch, Rectangle destination, Color color, float rotation = 0, Vector2 origin = new Vector2()) + /// + /// Draw the region given by a string in the atlas onto a destination rectangle. + /// + /// Name of region to draw. + /// SpriteBatch to be used. + /// The location to draw this region. + /// Color to use. + /// Rotation of texture drawn. + /// Origin used by rotation. + public void Draw(string name, SpriteBatch batch, Rectangle destination, Color color = default(Color), float rotation = 0, Vector2 origin = new Vector2()) { dictionaryOfRegions[name].Draw(batch, destination, color, rotation, origin); } - - public Texture2D TextureOfRegion(string name, GraphicsDevice graphicsDevice) + /// + /// Creates or obtains a previously created texture of a region. + /// + /// Name of region. + /// graphics device to be used. + /// The texture from the region. + public Texture2D ObtainRegionAsTexture(string name, GraphicsDevice graphicsDevice) { - return dictionaryOfRegions[name].AsTexture2D(graphicsDevice, texture); + return dictionaryOfRegions[name].AsTexture2D(graphicsDevice); } public class TextureAtlasRegion : IComparable, IDisposable @@ -52,11 +65,18 @@ namespace RecrownedAthenaeum.DataTypes Texture2D atlasTexture; Texture2D regionTexture; - public TextureAtlasRegion(string name, Rectangle source, NinePatch ninePatch, Texture2D atlasTexture) + /// + /// A specified region in a texture atlas. + /// + /// Name of region. + /// The location of the region on the atlas. + /// A definition for the region. + /// The texture that holds the image data for the atlas. + public TextureAtlasRegion(string name, Rectangle sourceRegion, NinePatch ninePatch, Texture2D atlasTexture) { - this.atlasTexture = atlasTexture; - this.name = name; - this.sourceRectangle = source; + this.atlasTexture = atlasTexture ?? throw new ArgumentNullException("Name parameters can be null."); + this.name = name ?? throw new ArgumentNullException("Name parameters can be null."); + this.sourceRectangle = sourceRegion; this.ninepatch = ninePatch; } @@ -65,13 +85,18 @@ namespace RecrownedAthenaeum.DataTypes batch.Draw(atlasTexture, destination, sourceRectangle, color, rotation, origin, SpriteEffects.None, 0f); } - public Texture2D AsTexture2D(GraphicsDevice graphicsDevice, Texture2D textureAtlas) + /// + /// Create or obtains a previously created texture of this region. + /// + /// The graphics device to use to create the texture. + /// The texture of the region. + public Texture2D AsTexture2D(GraphicsDevice graphicsDevice) { if (regionTexture == null) { Color[] data = new Color[sourceRectangle.Width * sourceRectangle.Height]; regionTexture = new Texture2D(graphicsDevice, sourceRectangle.Width, sourceRectangle.Height); - textureAtlas.GetData(0, sourceRectangle, data, 0, sourceRectangle.Width * sourceRectangle.Height); + atlasTexture.GetData(0, sourceRectangle, data, 0, sourceRectangle.Width * sourceRectangle.Height); regionTexture.SetData(data); } return regionTexture; diff --git a/RecrownedAthenaeum/Properties/AssemblyInfo.cs b/RecrownedAthenaeum/Properties/AssemblyInfo.cs index 2c8bef0..1ba04c9 100644 --- a/RecrownedAthenaeum/Properties/AssemblyInfo.cs +++ b/RecrownedAthenaeum/Properties/AssemblyInfo.cs @@ -5,11 +5,11 @@ using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. -[assembly: AssemblyTitle("Recrowned-Athenaeum")] +[assembly: AssemblyTitle("RecrownedAthenaeum")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("Recrowned-Athenaeum")] +[assembly: AssemblyProduct("RecrownedAthenaeum")] [assembly: AssemblyCopyright("Copyright © 2018")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] diff --git a/RecrownedAthenaeum/UI/Skin/Skin.cs b/RecrownedAthenaeum/UI/Skin/Skin.cs index 9867bdd..c8e136b 100644 --- a/RecrownedAthenaeum/UI/Skin/Skin.cs +++ b/RecrownedAthenaeum/UI/Skin/Skin.cs @@ -25,9 +25,19 @@ namespace RecrownedAthenaeum.UI.Skin definitions = new Dictionary>(); } - public void Draw(string texture, string color, Rectangle region) + public void Draw(string regionName, string color, SpriteBatch batch, Rectangle destination, Type type, float rotation = 0, Vector2 origin = default(Vector2)) { - + textureAtlas.Draw(regionName, batch, destination, colors[color], rotation, origin); + } + + public ISkinDefinition ObtainDefinition(string definitionName, Type type) + { + return definitions[type][definitionName]; + } + + public T ObtainDefinition(string definitionName) where T : ISkinDefinition + { + return (T)definitions[typeof(T)][definitionName]; } public void AddDefinition(string definitionName, ISkinDefinition skinDefinition)