Add IPC methods IsRunning/GetCurrentQuestId
authorLiza Carvelli <liza@carvel.li>
Sat, 31 Aug 2024 12:03:53 +0000 (14:03 +0200)
committerLiza Carvelli <liza@carvel.li>
Sat, 31 Aug 2024 12:03:53 +0000 (14:03 +0200)
Questionable/External/QuestionableIpc.cs [new file with mode: 0644]
Questionable/QuestionablePlugin.cs

diff --git a/Questionable/External/QuestionableIpc.cs b/Questionable/External/QuestionableIpc.cs
new file mode 100644 (file)
index 0000000..e73053e
--- /dev/null
@@ -0,0 +1,31 @@
+using System;
+using Dalamud.Plugin;
+using Dalamud.Plugin.Ipc;
+using Questionable.Controller;
+
+namespace Questionable.External;
+
+internal sealed class QuestionableIpc : IDisposable
+{
+    private const string IpcIsRunning = "Questionable.IsRunning";
+    private const string IpcGetCurrentQuestId = "Questionable.GetCurrentQuestId";
+
+    private readonly ICallGateProvider<bool> _isRunning;
+    private readonly ICallGateProvider<string?> _getCurrentQuestId;
+
+    public QuestionableIpc(QuestController questController, IDalamudPluginInterface pluginInterface)
+    {
+        _isRunning = pluginInterface.GetIpcProvider<bool>(IpcIsRunning);
+        _isRunning.RegisterFunc(() => questController.IsRunning);
+
+        _getCurrentQuestId = pluginInterface.GetIpcProvider<string?>(IpcGetCurrentQuestId);
+        _getCurrentQuestId.RegisterFunc(() => questController.CurrentQuest?.Quest.Id.ToString());
+    }
+
+
+    public void Dispose()
+    {
+        _getCurrentQuestId.UnregisterFunc();
+        _isRunning.UnregisterFunc();
+    }
+}
index 207cf2b11aae76f5d4f2685a58ceaf05b6409659..d1a5b543f5d06631f7a4942e48e886ac8071d19b 100644 (file)
@@ -120,6 +120,7 @@ public sealed class QuestionablePlugin : IDalamudPlugin
         serviceCollection.AddSingleton<LifestreamIpc>();
         serviceCollection.AddSingleton<YesAlreadyIpc>();
         serviceCollection.AddSingleton<ArtisanIpc>();
+        serviceCollection.AddSingleton<QuestionableIpc>();
     }
 
     private static void AddTaskFactories(ServiceCollection serviceCollection)
@@ -235,6 +236,7 @@ public sealed class QuestionablePlugin : IDalamudPlugin
         serviceProvider.GetRequiredService<CreditsController>();
         serviceProvider.GetRequiredService<HelpUiController>();
         serviceProvider.GetRequiredService<LeveUiController>();
+        serviceProvider.GetRequiredService<QuestionableIpc>();
         serviceProvider.GetRequiredService<DalamudInitializer>();
     }