mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 18:27:23 +01:00
Utility class and namespace
This commit is contained in:
parent
ff5502baa8
commit
16266f9636
14 changed files with 114 additions and 19 deletions
|
|
@ -5,9 +5,8 @@ using System.Diagnostics;
|
|||
using System.IO;
|
||||
using System.Threading;
|
||||
|
||||
using Dalamud.Data.LuminaExtensions;
|
||||
using Dalamud.Interface;
|
||||
using Dalamud.Interface.Internal;
|
||||
using Dalamud.Utility;
|
||||
using ImGuiScene;
|
||||
using JetBrains.Annotations;
|
||||
using Lumina;
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ namespace Dalamud.Hooking.Internal
|
|||
internal Delegate Delegate { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the hooked assembly.
|
||||
/// Gets the assembly implementing the hook.
|
||||
/// </summary>
|
||||
internal Assembly Assembly { get; }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ using Dalamud.Interface.Windowing;
|
|||
using Dalamud.Logging;
|
||||
using Dalamud.Logging.Internal;
|
||||
using Dalamud.Plugin.Internal;
|
||||
using Dalamud.Utility;
|
||||
using ImGuiNET;
|
||||
using Serilog.Events;
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ using Dalamud.Game.ClientState;
|
|||
using Dalamud.Game.Internal.DXGI;
|
||||
using Dalamud.Hooking;
|
||||
using Dalamud.Hooking.Internal;
|
||||
using Dalamud.Utility;
|
||||
using ImGuiNET;
|
||||
using ImGuiScene;
|
||||
using Serilog;
|
||||
|
|
@ -322,9 +323,7 @@ namespace Dalamud.Interface.Internal
|
|||
|
||||
private static void ShowFontError(string path)
|
||||
{
|
||||
Util.Fatal(
|
||||
$"One or more files required by XIVLauncher were not found.\nPlease restart and report this error if it occurs again.\n\n{path}",
|
||||
"Error");
|
||||
Util.Fatal($"One or more files required by XIVLauncher were not found.\nPlease restart and report this error if it occurs again.\n\n{path}", "Error");
|
||||
}
|
||||
|
||||
private IntPtr PresentDetour(IntPtr swapChain, uint syncInterval, uint presentFlags)
|
||||
|
|
|
|||
|
|
@ -131,7 +131,7 @@ public class ScratchPlugin : IDalamudPlugin {
|
|||
case ParseContext.Dispose:
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
throw new ArgumentOutOfRangeException(paramName: nameof(input));
|
||||
}
|
||||
|
||||
ctx = ParseContext.None;
|
||||
|
|
@ -156,7 +156,7 @@ public class ScratchPlugin : IDalamudPlugin {
|
|||
disposeBody += line + "\n";
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
throw new ArgumentOutOfRangeException(paramName: nameof(input));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
using System.Diagnostics;
|
||||
|
||||
using Dalamud.Interface.Windowing;
|
||||
using Dalamud.Utility;
|
||||
using ImGuiNET;
|
||||
|
||||
namespace Dalamud.Interface.Internal.Windows
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ using Dalamud.Game.Internal.Gui.Toast;
|
|||
using Dalamud.Game.Text;
|
||||
using Dalamud.Interface.Windowing;
|
||||
using Dalamud.Plugin;
|
||||
using Dalamud.Utility;
|
||||
using ImGuiNET;
|
||||
using ImGuiScene;
|
||||
using Newtonsoft.Json;
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ namespace Dalamud.Plugin
|
|||
public Framework Framework { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="UiBuilder">UiBuilder</see> instance which allows you to draw UI into the game via ImGui draw calls.
|
||||
/// Gets the <see cref="UiBuilder"/> instance which allows you to draw UI into the game via ImGui draw calls.
|
||||
/// </summary>
|
||||
public UiBuilder UiBuilder { get; private set; }
|
||||
|
||||
|
|
@ -165,6 +165,8 @@ namespace Dalamud.Plugin
|
|||
/// </summary>
|
||||
internal Action<string, ExpandoObject> AnyPluginIpcAction { get; private set; }
|
||||
|
||||
#region Configuration
|
||||
|
||||
/// <summary>
|
||||
/// Save a plugin configuration(inheriting IPluginConfiguration).
|
||||
/// </summary>
|
||||
|
|
@ -216,6 +218,8 @@ namespace Dalamud.Plugin
|
|||
/// <returns>directory with path of AppData/XIVLauncher/pluginConfig/PluginInternalName/loc.</returns>
|
||||
public string GetPluginLocDirectory() => this.configs.GetDirectory(Path.Combine(this.pluginName, "loc"));
|
||||
|
||||
#endregion
|
||||
|
||||
#region Chat Links
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ using System.Text;
|
|||
using Dalamud.Configuration;
|
||||
using Dalamud.Plugin;
|
||||
using Dalamud.Plugin.Internal.Types;
|
||||
using Dalamud.Utility;
|
||||
using Newtonsoft.Json;
|
||||
using Serilog;
|
||||
|
||||
|
|
|
|||
28
Dalamud/Utility/EnumExtensions.cs
Normal file
28
Dalamud/Utility/EnumExtensions.cs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace Dalamud.Utility
|
||||
{
|
||||
/// <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();
|
||||
}
|
||||
}
|
||||
}
|
||||
16
Dalamud/Utility/StringExtensions.cs
Normal file
16
Dalamud/Utility/StringExtensions.cs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
namespace Dalamud.Utility
|
||||
{
|
||||
/// <summary>
|
||||
/// Extension methods for strings.
|
||||
/// </summary>
|
||||
public static class StringExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// An extension method to chain usage of string.Format.
|
||||
/// </summary>
|
||||
/// <param name="format">Format string.</param>
|
||||
/// <param name="args">Format arguments.</param>
|
||||
/// <returns>Formatted string.</returns>
|
||||
public static string Format(this string format, params object[] args) => string.Format(format, args);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
using ImGuiScene;
|
||||
using Lumina.Data.Files;
|
||||
|
||||
namespace Dalamud.Data.LuminaExtensions
|
||||
namespace Dalamud.Utility
|
||||
{
|
||||
/// <summary>
|
||||
/// Extensions to <see cref="TexFile"/>.
|
||||
|
|
@ -7,10 +7,11 @@ using System.Text;
|
|||
using Dalamud.Game;
|
||||
using Dalamud.Interface;
|
||||
using Dalamud.Interface.Colors;
|
||||
using Dalamud.Logging.Internal;
|
||||
using ImGuiNET;
|
||||
using Serilog;
|
||||
|
||||
namespace Dalamud
|
||||
namespace Dalamud.Utility
|
||||
{
|
||||
/// <summary>
|
||||
/// Class providing various helper methods for use in Dalamud and plugins.
|
||||
|
|
@ -196,13 +197,5 @@ namespace Dalamud
|
|||
|
||||
// TODO: Someone implement GetUTF8String with some IntPtr overloads.
|
||||
// while(Marshal.ReadByte(0, sz) != 0) { sz++; }
|
||||
|
||||
/// <summary>
|
||||
/// An extension method to chain usage of string.Format.
|
||||
/// </summary>
|
||||
/// <param name="format">Format string.</param>
|
||||
/// <param name="args">Format arguments.</param>
|
||||
/// <returns>Formatted string.</returns>
|
||||
public static string Format(this string format, params object[] args) => string.Format(format, args);
|
||||
}
|
||||
}
|
||||
52
Dalamud/Utility/VectorExtensions.cs
Normal file
52
Dalamud/Utility/VectorExtensions.cs
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
using System.Numerics;
|
||||
|
||||
namespace Dalamud.Utility
|
||||
{
|
||||
/// <summary>
|
||||
/// Extension methods for System.Numerics.VectorN and SharpDX.VectorN.
|
||||
/// </summary>
|
||||
public static class VectorExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts a SharpDX vector to System.Numerics.
|
||||
/// </summary>
|
||||
/// <param name="vec">Vector to convert.</param>
|
||||
/// <returns>A converted vector.</returns>
|
||||
public static Vector2 ToSystem(this SharpDX.Vector2 vec) => new(x: vec.X, y: vec.Y);
|
||||
|
||||
/// <summary>
|
||||
/// Converts a SharpDX vector to System.Numerics.
|
||||
/// </summary>
|
||||
/// <param name="vec">Vector to convert.</param>
|
||||
/// <returns>A converted vector.</returns>
|
||||
public static Vector3 ToSystem(this SharpDX.Vector3 vec) => new(x: vec.X, y: vec.Y, z: vec.Z);
|
||||
|
||||
/// <summary>
|
||||
/// Converts a SharpDX vector to System.Numerics.
|
||||
/// </summary>
|
||||
/// <param name="vec">Vector to convert.</param>
|
||||
/// <returns>A converted vector.</returns>
|
||||
public static Vector4 ToSystem(this SharpDX.Vector4 vec) => new(x: vec.X, y: vec.Y, z: vec.Z, w: vec.W);
|
||||
|
||||
/// <summary>
|
||||
/// Converts a System.Numerics vector to SharpDX.
|
||||
/// </summary>
|
||||
/// <param name="vec">Vector to convert.</param>
|
||||
/// <returns>A converted vector.</returns>
|
||||
public static SharpDX.Vector2 ToSharpDX(this Vector2 vec) => new(x: vec.X, y: vec.Y);
|
||||
|
||||
/// <summary>
|
||||
/// Converts a System.Numerics vector to SharpDX.
|
||||
/// </summary>
|
||||
/// <param name="vec">Vector to convert.</param>
|
||||
/// <returns>A converted vector.</returns>
|
||||
public static SharpDX.Vector3 ToSharpDX(this Vector3 vec) => new(x: vec.X, y: vec.Y, z: vec.Z);
|
||||
|
||||
/// <summary>
|
||||
/// Converts a System.Numerics vector to SharpDX.
|
||||
/// </summary>
|
||||
/// <param name="vec">Vector to convert.</param>
|
||||
/// <returns>A converted vector.</returns>
|
||||
public static SharpDX.Vector4 ToSharpDX(this Vector4 vec) => new(x: vec.X, y: vec.Y, z: vec.Z, w: vec.W);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue