feat: add InherentDependencyAttribute, mark PM inherently dependent on IM

This commit is contained in:
goat 2023-02-02 22:57:39 +01:00
parent 4a228f4e3b
commit f40ea4310c
No known key found for this signature in database
GPG key ID: 49E2AA8C6A76498B
5 changed files with 34 additions and 4 deletions

View file

@ -4,7 +4,7 @@
<TargetFramework>net7.0-windows</TargetFramework> <TargetFramework>net7.0-windows</TargetFramework>
<PlatformTarget>x64</PlatformTarget> <PlatformTarget>x64</PlatformTarget>
<Platforms>x64;AnyCPU</Platforms> <Platforms>x64;AnyCPU</Platforms>
<LangVersion>10.0</LangVersion> <LangVersion>11.0</LangVersion>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Label="Feature"> <PropertyGroup Label="Feature">

View file

@ -44,6 +44,7 @@ using Lumina.Excel.GeneratedSheets;
using Newtonsoft.Json; using Newtonsoft.Json;
using PInvoke; using PInvoke;
using Serilog; using Serilog;
using Condition = Dalamud.Game.ClientState.Conditions.Condition; using Condition = Dalamud.Game.ClientState.Conditions.Condition;
namespace Dalamud.Interface.Internal.Windows; namespace Dalamud.Interface.Internal.Windows;
@ -1728,11 +1729,11 @@ internal class DataWindow : Window
foreach (var color in colorSheet) foreach (var color in colorSheet)
{ {
this.DrawUIColor(color); this.DrawUiColor(color);
} }
} }
private void DrawUIColor(UIColor color) private void DrawUiColor(UIColor color)
{ {
ImGui.Text($"[{color.RowId:D3}] "); ImGui.Text($"[{color.RowId:D3}] ");
ImGui.SameLine(); ImGui.SameLine();
@ -1750,7 +1751,7 @@ internal class DataWindow : Window
var r = (byte)(color >> 24); var r = (byte)(color >> 24);
var g = (byte)(color >> 16); var g = (byte)(color >> 16);
var b = (byte)(color >> 8); var b = (byte)(color >> 8);
var a = (byte)(color); var a = (byte)color;
return new Vector4(r / 255.0f, g / 255.0f, b / 255.0f, a / 255.0f); return new Vector4(r / 255.0f, g / 255.0f, b / 255.0f, a / 255.0f);
} }

View file

@ -0,0 +1,20 @@
using System;
namespace Dalamud.IoC.Internal;
/// <summary>
/// Mark a class as being dependent on a service, without actually injecting it.
/// </summary>
/// <typeparam name="T">The service to be dependent upon.</typeparam>
[AttributeUsage(AttributeTargets.Class)]
internal class InherentDependencyAttribute<T> : InherentDependencyAttribute where T : IServiceType
{
}
/// <summary>
/// Helper class used for matching. Use the generic version.
/// </summary>
[AttributeUsage(AttributeTargets.Class)]
internal class InherentDependencyAttribute : Attribute
{
}

View file

@ -20,6 +20,7 @@ using Dalamud.Game.Text;
using Dalamud.Game.Text.SeStringHandling; using Dalamud.Game.Text.SeStringHandling;
using Dalamud.Game.Text.SeStringHandling.Payloads; using Dalamud.Game.Text.SeStringHandling.Payloads;
using Dalamud.Interface.Internal; using Dalamud.Interface.Internal;
using Dalamud.IoC.Internal;
using Dalamud.Logging.Internal; using Dalamud.Logging.Internal;
using Dalamud.Plugin.Internal.Exceptions; using Dalamud.Plugin.Internal.Exceptions;
using Dalamud.Plugin.Internal.Types; using Dalamud.Plugin.Internal.Types;
@ -33,6 +34,9 @@ namespace Dalamud.Plugin.Internal;
/// Class responsible for loading and unloading plugins. /// Class responsible for loading and unloading plugins.
/// </summary> /// </summary>
[ServiceManager.EarlyLoadedService] [ServiceManager.EarlyLoadedService]
#pragma warning disable SA1015
[InherentDependency<InterfaceManager.InterfaceManagerWithScene>]
#pragma warning restore SA1015
internal partial class PluginManager : IDisposable, IServiceType internal partial class PluginManager : IDisposable, IServiceType
{ {
/// <summary> /// <summary>

View file

@ -128,6 +128,11 @@ internal static class Service<T> where T : IServiceType
.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) .GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
.Select(x => x.FieldType) .Select(x => x.FieldType)
.Where(x => x.GetCustomAttribute<ServiceManager.ServiceDependency>(true) != null)); .Where(x => x.GetCustomAttribute<ServiceManager.ServiceDependency>(true) != null));
res.AddRange(typeof(T)
.GetCustomAttributes()
.OfType<InherentDependencyAttribute>()
.Select(x => x.GetType().GetGenericArguments().First()));
return res return res
.Distinct() .Distinct()
.Select(x => typeof(Service<>).MakeGenericType(x)) .Select(x => typeof(Service<>).MakeGenericType(x))