mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-15 05:04:15 +01:00
Break out XivChatType Extensions and InfoAttribute
This commit is contained in:
parent
16266f9636
commit
f26b1ead9e
3 changed files with 59 additions and 76 deletions
|
|
@ -1,6 +1,3 @@
|
||||||
using System;
|
|
||||||
using System.Linq;
|
|
||||||
|
|
||||||
namespace Dalamud.Game.Text
|
namespace Dalamud.Game.Text
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -237,77 +234,4 @@ namespace Dalamud.Game.Text
|
||||||
[XivChatTypeInfo("Crossworld Linkshell 8", "cw8", 0xFF1E90FF)]
|
[XivChatTypeInfo("Crossworld Linkshell 8", "cw8", 0xFF1E90FF)]
|
||||||
CrossLinkShell8 = 107,
|
CrossLinkShell8 = 107,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Extension methods for the <see cref="XivChatType"/> type.
|
|
||||||
/// </summary>
|
|
||||||
public static class XivChatTypeExtensions
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Get the InfoAttribute associated with this chat type.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="chatType">The chat type.</param>
|
|
||||||
/// <returns>The info attribute.</returns>
|
|
||||||
public static XivChatTypeInfoAttribute GetDetails(this XivChatType chatType)
|
|
||||||
{
|
|
||||||
return chatType.GetAttribute<XivChatTypeInfoAttribute>();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Storage for relevant information associated with the chat type.
|
|
||||||
/// </summary>
|
|
||||||
public class XivChatTypeInfoAttribute : Attribute
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="XivChatTypeInfoAttribute"/> class.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="fancyName">The fancy name.</param>
|
|
||||||
/// <param name="slug">The name slug.</param>
|
|
||||||
/// <param name="defaultColor">The default color.</param>
|
|
||||||
internal XivChatTypeInfoAttribute(string fancyName, string slug, uint defaultColor)
|
|
||||||
{
|
|
||||||
this.FancyName = fancyName;
|
|
||||||
this.Slug = slug;
|
|
||||||
this.DefaultColor = defaultColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the "fancy" name of the type.
|
|
||||||
/// </summary>
|
|
||||||
public string FancyName { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the type name slug or short-form.
|
|
||||||
/// </summary>
|
|
||||||
public string Slug { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the type default color.
|
|
||||||
/// </summary>
|
|
||||||
public uint DefaultColor { get; }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Extension methods for enums.
|
|
||||||
/// </summary>
|
|
||||||
public static class EnumExtensions
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Gets an attribute on an enum.
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="TAttribute">The type of attribute to get.</typeparam>
|
|
||||||
/// <param name="value">The enum value that has an attached attribute.</param>
|
|
||||||
/// <returns>The attached attribute, if any.</returns>
|
|
||||||
public static TAttribute GetAttribute<TAttribute>(this Enum value)
|
|
||||||
where TAttribute : Attribute
|
|
||||||
{
|
|
||||||
var type = value.GetType();
|
|
||||||
var name = Enum.GetName(type, value);
|
|
||||||
return type.GetField(name) // I prefer to get attributes this way
|
|
||||||
.GetCustomAttributes(false)
|
|
||||||
.OfType<TAttribute>()
|
|
||||||
.SingleOrDefault();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
20
Dalamud/Game/Text/XivChatTypeExtensions.cs
Normal file
20
Dalamud/Game/Text/XivChatTypeExtensions.cs
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
using Dalamud.Utility;
|
||||||
|
|
||||||
|
namespace Dalamud.Game.Text
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Extension methods for the <see cref="XivChatType"/> type.
|
||||||
|
/// </summary>
|
||||||
|
public static class XivChatTypeExtensions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Get the InfoAttribute associated with this chat type.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="chatType">The chat type.</param>
|
||||||
|
/// <returns>The info attribute.</returns>
|
||||||
|
public static XivChatTypeInfoAttribute GetDetails(this XivChatType chatType)
|
||||||
|
{
|
||||||
|
return chatType.GetAttribute<XivChatTypeInfoAttribute>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
39
Dalamud/Game/Text/XivChatTypeInfoAttribute.cs
Normal file
39
Dalamud/Game/Text/XivChatTypeInfoAttribute.cs
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Dalamud.Game.Text
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Storage for relevant information associated with the chat type.
|
||||||
|
/// </summary>
|
||||||
|
[AttributeUsage(AttributeTargets.Field)]
|
||||||
|
public class XivChatTypeInfoAttribute : Attribute
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="XivChatTypeInfoAttribute"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="fancyName">The fancy name.</param>
|
||||||
|
/// <param name="slug">The name slug.</param>
|
||||||
|
/// <param name="defaultColor">The default color.</param>
|
||||||
|
internal XivChatTypeInfoAttribute(string fancyName, string slug, uint defaultColor)
|
||||||
|
{
|
||||||
|
this.FancyName = fancyName;
|
||||||
|
this.Slug = slug;
|
||||||
|
this.DefaultColor = defaultColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the "fancy" name of the type.
|
||||||
|
/// </summary>
|
||||||
|
public string FancyName { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the type name slug or short-form.
|
||||||
|
/// </summary>
|
||||||
|
public string Slug { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the type default color.
|
||||||
|
/// </summary>
|
||||||
|
public uint DefaultColor { get; }
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue