From c2d42317ce71ed84481dc9fc8870221d9dd99b15 Mon Sep 17 00:00:00 2001 From: Liza Carvelli Date: Sat, 13 Jan 2024 23:32:14 +0100 Subject: [PATCH] Add IPC to retrieve items that'll be auto-discarded --- ARDiscard/ARDiscard.csproj | 2 +- ARDiscard/AutoDiscardPlogon.cs | 4 ++++ ARDiscard/External/AutoDiscardIpc.cs | 32 ++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 ARDiscard/External/AutoDiscardIpc.cs diff --git a/ARDiscard/ARDiscard.csproj b/ARDiscard/ARDiscard.csproj index 2124f27..d2deb5b 100644 --- a/ARDiscard/ARDiscard.csproj +++ b/ARDiscard/ARDiscard.csproj @@ -1,7 +1,7 @@ net7.0-windows - 4.2 + 4.3 11.0 enable true diff --git a/ARDiscard/AutoDiscardPlogon.cs b/ARDiscard/AutoDiscardPlogon.cs index 4df8282..3005616 100644 --- a/ARDiscard/AutoDiscardPlogon.cs +++ b/ARDiscard/AutoDiscardPlogon.cs @@ -1,6 +1,7 @@ using System; using System.Diagnostics.CodeAnalysis; using System.Linq; +using ARDiscard.External; using ARDiscard.GameData; using ARDiscard.Windows; using AutoRetainerAPI; @@ -37,6 +38,7 @@ public class AutoDiscardPlogon : IDalamudPlugin private readonly AutoRetainerApi _autoRetainerApi; private readonly TaskManager _taskManager; private readonly ContextMenuIntegration _contextMenuIntegration; + private readonly AutoDiscardIpc _autoDiscardIpc; private DateTime _cancelDiscardAfter = DateTime.MaxValue; @@ -87,6 +89,7 @@ public class AutoDiscardPlogon : IDalamudPlugin _autoRetainerApi = new(); _taskManager = new(); _contextMenuIntegration = new(_pluginInterface, _chatGui, itemCache, _configuration, _configWindow, _gameGui); + _autoDiscardIpc = new(_pluginInterface, _configuration); _clientState.Login += _discardWindow.Login; _clientState.Logout += _discardWindow.Logout; @@ -274,6 +277,7 @@ public class AutoDiscardPlogon : IDalamudPlugin _clientState.Login -= _discardWindow.Login; _clientState.Logout -= _discardWindow.Logout; + _autoDiscardIpc.Dispose(); _contextMenuIntegration.Dispose(); _autoRetainerApi.Dispose(); ECommonsMain.Dispose(); diff --git a/ARDiscard/External/AutoDiscardIpc.cs b/ARDiscard/External/AutoDiscardIpc.cs new file mode 100644 index 0000000..67862ca --- /dev/null +++ b/ARDiscard/External/AutoDiscardIpc.cs @@ -0,0 +1,32 @@ +using System.Collections.Generic; +using System.Collections.Immutable; +using Dalamud.Plugin; +using Dalamud.Plugin.Ipc; + +namespace ARDiscard.External; + +internal sealed class AutoDiscardIpc +{ + private const string ItemsToDiscard = "ARDiscard.GetItemsToDiscard"; + + private readonly Configuration _configuration; + private readonly ICallGateProvider> _getItemsToDiscard; + + public AutoDiscardIpc(DalamudPluginInterface pluginInterface, Configuration configuration) + { + _configuration = configuration; + + _getItemsToDiscard = pluginInterface.GetIpcProvider>(ItemsToDiscard); + _getItemsToDiscard.RegisterFunc(GetItemsToDiscard); + } + + public void Dispose() + { + _getItemsToDiscard.UnregisterFunc(); + } + + private IReadOnlySet GetItemsToDiscard() + { + return _configuration.DiscardingItems.ToImmutableHashSet(); + } +}