Refactors and documentation.

This commit is contained in:
Harrison Deng 2019-01-15 17:03:17 -06:00
parent f5cbd9dbab
commit a62ec1bd38
8 changed files with 108 additions and 20 deletions

View File

@ -21,6 +21,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants> <DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<DocumentationFile>bin\Debug\RecrownedAthenaeum.Pipeline.xml</DocumentationFile>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType> <DebugType>pdbonly</DebugType>

View File

@ -3,35 +3,78 @@ using RecrownedAthenaeum.Pipeline.NinePatch;
namespace RecrownedAthenaeum.Pipeline.TextureAtlas namespace RecrownedAthenaeum.Pipeline.TextureAtlas
{ {
/// <summary>
/// Data transfer object for a texture atlas.
/// </summary>
public class TextureAtlasData public class TextureAtlasData
{ {
/// <summary>
/// Contains the regions of the texture atlas.
/// </summary>
public AtlasRegionData[] regions; public AtlasRegionData[] regions;
/// <summary>
/// The name of the file.
/// </summary>
public string textureName; 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) public TextureAtlasData(string textureName, AtlasRegionData[] regions)
{ {
this.regions = regions; this.regions = regions;
this.textureName = textureName; 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 public class AtlasRegionData
{ {
/// <summary>
/// Name of the region for referencial purposes.
/// </summary>
public string name; public string name;
/// <summary>
/// The location of the patch is designated by this rectangle.
/// </summary>
public Rectangle location; public Rectangle location;
/// <summary>
/// The ninepatch information.
/// </summary>
public NinePatchData ninePatchData; 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) public void SetPosition(int x, int y)
{ {
location.X = x; location.X = x;
location.Y = y; 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) public void SetSize(int width, int height)
{ {
location.Width = width; location.Width = width;
location.Height = height; 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) public void SetBounds(int x, int y, int width, int height)
{ {
SetPosition(x, y); SetPosition(x, y);

View File

@ -23,6 +23,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants> <DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<DocumentationFile>bin\Debug\RecrownedAthenaeum.xml</DocumentationFile>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType> <DebugType>pdbonly</DebugType>

View File

@ -6,7 +6,7 @@ namespace RecrownedAthenaeum.UI.Skin.Definitions
/// <summary> /// <summary>
/// Definition for a button. /// Definition for a button.
/// </summary> /// </summary>
public class ButtonSkinDefinition : ISkinDefinition public class ButtonSkinDefinition : ISkinDefinitionData
{ {
/// <summary> /// <summary>
/// Names for the regions in the texture atlas respectively. /// Names for the regions in the texture atlas respectively.

View File

@ -3,9 +3,9 @@
namespace RecrownedAthenaeum.UI.Skin.Definitions namespace RecrownedAthenaeum.UI.Skin.Definitions
{ {
/// <summary> /// <summary>
/// A definition for the skin system. /// A definition containing the data for the skin system. Should be in data transfer object model.
/// </summary> /// </summary>
public interface ISkinDefinition public interface ISkinDefinitionData
{ {
/// <summary> /// <summary>
/// The module type this definition is definining. /// The module type this definition is definining.

View File

@ -3,7 +3,7 @@ using static System.Net.Mime.MediaTypeNames;
namespace RecrownedAthenaeum.UI.Skin.Definitions namespace RecrownedAthenaeum.UI.Skin.Definitions
{ {
class TextSkinDefinition : ISkinDefinition class TextSkinDefinition : ISkinDefinitionData
{ {
public string font; public string font;
public string color; public string color;

View File

@ -24,7 +24,7 @@ namespace RecrownedAthenaeum.UI.Skin
/// Fonts stored in this skin. /// Fonts stored in this skin.
/// </summary> /// </summary>
public readonly Dictionary<string, SpriteFont> fonts; public readonly Dictionary<string, SpriteFont> fonts;
Dictionary<Type, Dictionary<string, ISkinDefinition>> definitions; Dictionary<Type, Dictionary<string, ISkinDefinitionData>> definitions;
/// <summary> /// <summary>
/// Creates a basic unfilled skin. /// Creates a basic unfilled skin.
@ -35,7 +35,7 @@ namespace RecrownedAthenaeum.UI.Skin
this.textureAtlas = textureAtlas; this.textureAtlas = textureAtlas;
colors = new Dictionary<string, Color>(); colors = new Dictionary<string, Color>();
fonts = new Dictionary<string, SpriteFont>(); fonts = new Dictionary<string, SpriteFont>();
definitions = new Dictionary<Type, Dictionary<string, ISkinDefinition>>(); definitions = new Dictionary<Type, Dictionary<string, ISkinDefinitionData>>();
} }
/// <summary> /// <summary>
@ -53,12 +53,12 @@ namespace RecrownedAthenaeum.UI.Skin
} }
/// <summary> /// <summary>
/// Returns an <see cref="ISkinDefinition"/> of the given name and type. /// Returns an <see cref="ISkinDefinitionData"/> of the given name and type.
/// </summary> /// </summary>
/// <param name="definitionName">Name of definition of the <paramref name="type"/></param> /// <param name="definitionName">Name of definition of the <paramref name="type"/></param>
/// <param name="type">The UIModule the definition defines.</param> /// <param name="type">The UIModule the definition defines.</param>
/// <returns>The interface for the definition.</returns> /// <returns>The interface for the definition.</returns>
public ISkinDefinition ObtainDefinition(string definitionName, Type type) public ISkinDefinitionData ObtainDefinition(string definitionName, Type type)
{ {
if (definitionName == null) definitionName = "default"; if (definitionName == null) definitionName = "default";
if (!definitions.ContainsKey(type) || !definitions[type].ContainsKey(definitionName)) throw new ArgumentException("Could not find skin of type " + type.Name + " with name " + definitionName); if (!definitions.ContainsKey(type) || !definitions[type].ContainsKey(definitionName)) throw new ArgumentException("Could not find skin of type " + type.Name + " with name " + definitionName);
@ -66,11 +66,11 @@ namespace RecrownedAthenaeum.UI.Skin
} }
/// <summary> /// <summary>
/// Returns the default <see cref="ISkinDefinition"/> of the given parameters. /// Returns the default <see cref="ISkinDefinitionData"/> of the given parameters.
/// </summary> /// </summary>
/// <param name="type">The type of definition the default should be coming from.</param> /// <param name="type">The type of definition the default should be coming from.</param>
/// <returns>The default definition for the given type.</returns> /// <returns>The default definition for the given type.</returns>
public ISkinDefinition ObtainDefinition(Type type) public ISkinDefinitionData ObtainDefinition(Type type)
{ {
return ObtainDefinition(null, type); return ObtainDefinition(null, type);
} }
@ -82,7 +82,7 @@ namespace RecrownedAthenaeum.UI.Skin
/// <param name="definitionName">The name of the definition.</param> /// <param name="definitionName">The name of the definition.</param>
/// <param name="type">UIModule type the definition defines.</param> /// <param name="type">UIModule type the definition defines.</param>
/// <returns>The definition cast to T.</returns> /// <returns>The definition cast to T.</returns>
public T ObtainDefinition<T>(string definitionName, Type type) where T : ISkinDefinition public T ObtainDefinition<T>(string definitionName, Type type) where T : ISkinDefinitionData
{ {
if (definitionName == null) definitionName = "default"; if (definitionName == null) definitionName = "default";
return (T)ObtainDefinition(definitionName, type); return (T)ObtainDefinition(definitionName, type);
@ -94,7 +94,7 @@ namespace RecrownedAthenaeum.UI.Skin
/// <typeparam name="T">Convenience to cast to T.</typeparam> /// <typeparam name="T">Convenience to cast to T.</typeparam>
/// <param name="type">The type of the UIModule to retrieve the default from.</param> /// <param name="type">The type of the UIModule to retrieve the default from.</param>
/// <returns>The default definition for the given type.</returns> /// <returns>The default definition for the given type.</returns>
public T ObtainDefinition<T>(Type type) where T : ISkinDefinition public T ObtainDefinition<T>(Type type) where T : ISkinDefinitionData
{ {
return ObtainDefinition<T>(null, type); return ObtainDefinition<T>(null, type);
} }
@ -104,11 +104,11 @@ namespace RecrownedAthenaeum.UI.Skin
/// </summary> /// </summary>
/// <param name="definitionName">The name of the definition.</param> /// <param name="definitionName">The name of the definition.</param>
/// <param name="skinDefinition">The definition itself.</param> /// <param name="skinDefinition">The definition itself.</param>
public void AddDefinition(string definitionName, ISkinDefinition skinDefinition) public void AddDefinition(string definitionName, ISkinDefinitionData skinDefinition)
{ {
if (!definitions.ContainsKey(skinDefinition.UIModuleType)) if (!definitions.ContainsKey(skinDefinition.UIModuleType))
{ {
definitions.Add(skinDefinition.UIModuleType, new Dictionary<string, ISkinDefinition>()); definitions.Add(skinDefinition.UIModuleType, new Dictionary<string, ISkinDefinitionData>());
} else if (definitions[skinDefinition.UIModuleType].ContainsKey(definitionName)) throw new ArgumentException("Type of definition with that name already exists!"); } else if (definitions[skinDefinition.UIModuleType].ContainsKey(definitionName)) throw new ArgumentException("Type of definition with that name already exists!");
definitions[skinDefinition.UIModuleType].Add(definitionName, skinDefinition); definitions[skinDefinition.UIModuleType].Add(definitionName, skinDefinition);

View File

@ -7,29 +7,72 @@ using System.Threading.Tasks;
namespace RecrownedAthenaeum.UI.Skin namespace RecrownedAthenaeum.UI.Skin
{ {
/// <summary>
/// Data transfer object for game skins.
/// </summary>
public class SkinData public class SkinData
{ {
/// <summary>
/// The name of the atlas with solution of ".tatlas".
/// </summary>
public string nameOfTextureAtlas; public string nameOfTextureAtlas;
/// <summary>
/// The color data containing the name of the color, and red, green, and blue values for the color.
/// </summary>
public ColorData[] colors; public ColorData[] colors;
/// <summary>
/// The font data containing the name of the font and name of the file for the font.
/// </summary>
public FontData[] fonts; public FontData[] fonts;
/// <summary>
/// The skin definitions containing a name for the definition, and the definition itself.
/// </summary>
public DefinitionData[] definitions; public DefinitionData[] definitions;
/// <summary>
/// Color data for data transfer.
/// </summary>
public class ColorData public class ColorData
{ {
string name; /// <summary>
int r, g, b; /// Name of color to be referenced by.
/// </summary>
public string name;
/// <summary>
/// RGB data of this color.
/// </summary>
public int r, g, b;
} }
/// <summary>
/// Font data for data transfer.
/// </summary>
public class FontData public class FontData
{ {
string name; /// <summary>
string font; /// Name of font to be referenced by.
/// </summary>
public string name;
/// <summary>
/// Name of the file that contains the font. Shouldn't have extension.
/// </summary>
public string font;
} }
/// <summary>
/// Definition data for data transfer.
/// </summary>
public class DefinitionData public class DefinitionData
{ {
string name; /// <summary>
ISkinDefinition skin; /// Name of definition to be referenced by.
/// </summary>
public string name;
/// <summary>
/// The skin definition data.
/// </summary>
public ISkinDefinitionData skin;
} }
} }
} }