mirror of
https://github.com/Ottermandias/Glamourer.git
synced 2026-02-07 16:34:40 +01:00
Add ModUsage subscription.
This commit is contained in:
parent
4d466fb7eb
commit
74517d8ec5
3 changed files with 77 additions and 11 deletions
58
Glamourer/Interop/Penumbra/ModUsageInformer.cs
Normal file
58
Glamourer/Interop/Penumbra/ModUsageInformer.cs
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
using Glamourer.Automation;
|
||||
using Glamourer.Designs;
|
||||
using OtterGui.Services;
|
||||
|
||||
namespace Glamourer.Interop.Penumbra;
|
||||
|
||||
public sealed class ModUsageInformer : IDisposable, IRequiredService
|
||||
{
|
||||
private readonly PenumbraService _penumbra;
|
||||
private readonly DesignManager _designs;
|
||||
private readonly AutoDesignManager _automation;
|
||||
|
||||
public ModUsageInformer(PenumbraService penumbra, DesignManager designs, AutoDesignManager automation)
|
||||
{
|
||||
_penumbra = penumbra;
|
||||
_designs = designs;
|
||||
_automation = automation;
|
||||
|
||||
_penumbra.ModUsageQueried += OnModUsageQueried;
|
||||
}
|
||||
|
||||
private void OnModUsageQueried(string modPath, string modName, Dictionary<Assembly, (bool, string)> notes)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
var inUse = false;
|
||||
foreach (var design in _designs.Designs)
|
||||
{
|
||||
if (!design.AssociatedMods.Any(p => ModMatches(modPath, modName, p.Key)))
|
||||
continue;
|
||||
|
||||
sb.AppendLine($"Contained in Design {design.Name}.");
|
||||
if (_automation.EnabledSets.Values.Any(s => s.Designs.Any(d => d.Type is not 0 && d.Design == design)))
|
||||
{
|
||||
inUse = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (inUse)
|
||||
notes.TryAdd(Assembly.GetAssembly(typeof(ModUsageInformer))!, (true, string.Empty));
|
||||
else if (sb.Length > 0)
|
||||
notes.TryAdd(Assembly.GetAssembly(typeof(ModUsageInformer))!, (false, sb.ToString()));
|
||||
}
|
||||
|
||||
private static bool ModMatches(string modPath, string modName, in Mod mod)
|
||||
{
|
||||
if (mod.DirectoryName.Equals(modPath, StringComparison.OrdinalIgnoreCase))
|
||||
return true;
|
||||
|
||||
if (mod.Name.Equals(modName, StringComparison.OrdinalIgnoreCase))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
=> _penumbra.ModUsageQueried -= OnModUsageQueried;
|
||||
}
|
||||
|
|
@ -44,15 +44,16 @@ public class PenumbraService : IDisposable
|
|||
private const int KeyManual = -6160;
|
||||
private const string NameManual = "Glamourer (Manually)";
|
||||
|
||||
private readonly IDalamudPluginInterface _pluginInterface;
|
||||
private readonly Configuration _config;
|
||||
private readonly EventSubscriber<ChangedItemType, uint> _tooltipSubscriber;
|
||||
private readonly EventSubscriber<MouseButton, ChangedItemType, uint> _clickSubscriber;
|
||||
private readonly EventSubscriber<nint, Guid, nint, nint, nint> _creatingCharacterBase;
|
||||
private readonly EventSubscriber<nint, Guid, nint> _createdCharacterBase;
|
||||
private readonly EventSubscriber<ModSettingChange, Guid, string, bool> _modSettingChanged;
|
||||
private readonly EventSubscriber<JObject, string, Guid> _pcpParsed;
|
||||
private readonly EventSubscriber<JObject, ushort, string> _pcpCreated;
|
||||
private readonly IDalamudPluginInterface _pluginInterface;
|
||||
private readonly Configuration _config;
|
||||
private readonly EventSubscriber<ChangedItemType, uint> _tooltipSubscriber;
|
||||
private readonly EventSubscriber<MouseButton, ChangedItemType, uint> _clickSubscriber;
|
||||
private readonly EventSubscriber<nint, Guid, nint, nint, nint> _creatingCharacterBase;
|
||||
private readonly EventSubscriber<nint, Guid, nint> _createdCharacterBase;
|
||||
private readonly EventSubscriber<ModSettingChange, Guid, string, bool> _modSettingChanged;
|
||||
private readonly EventSubscriber<JObject, string, Guid> _pcpParsed;
|
||||
private readonly EventSubscriber<JObject, ushort, string> _pcpCreated;
|
||||
private readonly EventSubscriber<string, string, Dictionary<Assembly, (bool, string)>> _modUsageQueried;
|
||||
|
||||
private global::Penumbra.Api.IpcSubscribers.GetCollectionsByIdentifier? _collectionByIdentifier;
|
||||
private global::Penumbra.Api.IpcSubscribers.GetCollections? _collections;
|
||||
|
|
@ -109,6 +110,7 @@ public class PenumbraService : IDisposable
|
|||
_modSettingChanged = global::Penumbra.Api.IpcSubscribers.ModSettingChanged.Subscriber(pi);
|
||||
_pcpCreated = global::Penumbra.Api.IpcSubscribers.CreatingPcp.Subscriber(pi);
|
||||
_pcpParsed = global::Penumbra.Api.IpcSubscribers.ParsingPcp.Subscriber(pi);
|
||||
_modUsageQueried = global::Penumbra.Api.IpcSubscribers.ModUsageQueried.Subscriber(pi);
|
||||
Reattach();
|
||||
}
|
||||
|
||||
|
|
@ -155,6 +157,12 @@ public class PenumbraService : IDisposable
|
|||
remove => _pcpParsed.Event -= value;
|
||||
}
|
||||
|
||||
public event Action<string, string, Dictionary<Assembly, (bool, string)>> ModUsageQueried
|
||||
{
|
||||
add => _modUsageQueried.Event += value;
|
||||
remove => _modUsageQueried.Event -= value;
|
||||
}
|
||||
|
||||
public event Action? DrawSettingsSection;
|
||||
|
||||
private void InvokeDrawSettingsSection()
|
||||
|
|
@ -573,7 +581,7 @@ public class PenumbraService : IDisposable
|
|||
_changedItems = new global::Penumbra.Api.IpcSubscribers.GetChangedItemAdapterList(_pluginInterface).Invoke();
|
||||
_checkCurrentChangedItems =
|
||||
new global::Penumbra.Api.IpcSubscribers.CheckCurrentChangedItemFunc(_pluginInterface).Invoke();
|
||||
_registerSettingsSection = new global::Penumbra.Api.IpcSubscribers.RegisterSettingsSection(_pluginInterface);
|
||||
_registerSettingsSection = new global::Penumbra.Api.IpcSubscribers.RegisterSettingsSection(_pluginInterface);
|
||||
_unregisterSettingsSection = new global::Penumbra.Api.IpcSubscribers.UnregisterSettingsSection(_pluginInterface);
|
||||
|
||||
_registerSettingsSection.Invoke(InvokeDrawSettingsSection);
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Subproject commit 52a3216a525592205198303df2844435e382cf87
|
||||
Subproject commit a79ff8d87c5b1ac12192f18563fb4247173ff4f0
|
||||
Loading…
Add table
Add a link
Reference in a new issue