feat: begin adding ipc
This commit is contained in:
parent
ed7065355d
commit
6ffeecf1ba
47
ChatTwo/IpcManager.cs
Executable file
47
ChatTwo/IpcManager.cs
Executable file
|
@ -0,0 +1,47 @@
|
||||||
|
using Dalamud.Game.Text.SeStringHandling;
|
||||||
|
using Dalamud.Game.Text.SeStringHandling.Payloads;
|
||||||
|
using Dalamud.Plugin;
|
||||||
|
using Dalamud.Plugin.Ipc;
|
||||||
|
|
||||||
|
namespace ChatTwo;
|
||||||
|
|
||||||
|
internal sealed class IpcManager : IDisposable {
|
||||||
|
private DalamudPluginInterface Interface { get; }
|
||||||
|
private ICallGateProvider<string> RegisterGate { get; }
|
||||||
|
private ICallGateProvider<string, object?> UnregisterGate { get; }
|
||||||
|
private ICallGateProvider<string, PlayerPayload?, ulong, Payload?, object?> InvokeGate { get; }
|
||||||
|
|
||||||
|
internal List<string> Registered { get; } = new();
|
||||||
|
|
||||||
|
public IpcManager(DalamudPluginInterface pluginInterface) {
|
||||||
|
this.Interface = pluginInterface;
|
||||||
|
|
||||||
|
this.RegisterGate = this.Interface.GetIpcProvider<string>("ChatTwo.Register");
|
||||||
|
this.RegisterGate.RegisterFunc(this.Register);
|
||||||
|
|
||||||
|
this.UnregisterGate = this.Interface.GetIpcProvider<string, object?>("ChatTwo.Unregister");
|
||||||
|
this.UnregisterGate.RegisterAction(this.Unregister);
|
||||||
|
|
||||||
|
this.InvokeGate = this.Interface.GetIpcProvider<string, PlayerPayload?, ulong, Payload?, object?>("ChatTwo.Invoke");
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void Invoke(string id, PlayerPayload? sender, ulong contentId, Payload? payload) {
|
||||||
|
this.InvokeGate.SendMessage(id, sender, contentId, payload);
|
||||||
|
}
|
||||||
|
|
||||||
|
private string Register() {
|
||||||
|
var id = Guid.NewGuid().ToString();
|
||||||
|
this.Registered.Add(id);
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Unregister(string id) {
|
||||||
|
this.Registered.Remove(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose() {
|
||||||
|
this.UnregisterGate.UnregisterFunc();
|
||||||
|
this.RegisterGate.UnregisterFunc();
|
||||||
|
this.Registered.Clear();
|
||||||
|
}
|
||||||
|
}
|
|
@ -74,11 +74,36 @@ internal sealed class PayloadHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.ContextFooter(drawn, chunk);
|
this.ContextFooter(drawn, chunk);
|
||||||
|
this.Integrations(chunk, payload);
|
||||||
|
|
||||||
ImGui.PopID();
|
ImGui.PopID();
|
||||||
ImGui.EndPopup();
|
ImGui.EndPopup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void Integrations(Chunk chunk, Payload? payload) {
|
||||||
|
var registered = this.Ui.Plugin.Ipc.Registered;
|
||||||
|
if (registered.Count == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var contentId = chunk.Message?.ContentId ?? 0;
|
||||||
|
var sender = chunk.Message?.Sender
|
||||||
|
.Select(chunk => chunk.Link)
|
||||||
|
.FirstOrDefault(chunk => chunk is PlayerPayload) as PlayerPayload;
|
||||||
|
|
||||||
|
if (ImGui.BeginMenu("Integrations")) {
|
||||||
|
foreach (var id in registered) {
|
||||||
|
try {
|
||||||
|
this.Ui.Plugin.Ipc.Invoke(id, sender, contentId, payload);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
PluginLog.Error(ex, "Error executing integration");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui.EndMenu();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void ContextFooter(bool separator, Chunk chunk) {
|
private void ContextFooter(bool separator, Chunk chunk) {
|
||||||
if (separator) {
|
if (separator) {
|
||||||
ImGui.Separator();
|
ImGui.Separator();
|
||||||
|
|
|
@ -64,6 +64,7 @@ public sealed class Plugin : IDalamudPlugin {
|
||||||
internal TextureCache TextureCache { get; }
|
internal TextureCache TextureCache { get; }
|
||||||
internal GameFunctions.GameFunctions Functions { get; }
|
internal GameFunctions.GameFunctions Functions { get; }
|
||||||
internal Store Store { get; }
|
internal Store Store { get; }
|
||||||
|
internal IpcManager Ipc { get; }
|
||||||
internal PluginUi Ui { get; }
|
internal PluginUi Ui { get; }
|
||||||
|
|
||||||
internal int DeferredSaveFrames = -1;
|
internal int DeferredSaveFrames = -1;
|
||||||
|
@ -84,6 +85,7 @@ public sealed class Plugin : IDalamudPlugin {
|
||||||
this.TextureCache = new TextureCache(this.DataManager!);
|
this.TextureCache = new TextureCache(this.DataManager!);
|
||||||
this.Functions = new GameFunctions.GameFunctions(this);
|
this.Functions = new GameFunctions.GameFunctions(this);
|
||||||
this.Store = new Store(this);
|
this.Store = new Store(this);
|
||||||
|
this.Ipc = new IpcManager(this.Interface);
|
||||||
this.Ui = new PluginUi(this);
|
this.Ui = new PluginUi(this);
|
||||||
|
|
||||||
// let all the other components register, then initialise commands
|
// let all the other components register, then initialise commands
|
||||||
|
@ -104,6 +106,7 @@ public sealed class Plugin : IDalamudPlugin {
|
||||||
GameFunctions.GameFunctions.SetChatInteractable(true);
|
GameFunctions.GameFunctions.SetChatInteractable(true);
|
||||||
|
|
||||||
this.Ui.Dispose();
|
this.Ui.Dispose();
|
||||||
|
this.Ipc.Dispose();
|
||||||
this.Store.Dispose();
|
this.Store.Dispose();
|
||||||
this.Functions.Dispose();
|
this.Functions.Dispose();
|
||||||
this.TextureCache.Dispose();
|
this.TextureCache.Dispose();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user