From 9395072bee06043b66df6ea79ede45f716829f92 Mon Sep 17 00:00:00 2001 From: Limiana <5073202+Limiana@users.noreply.github.com> Date: Fri, 29 Dec 2023 21:33:21 +0300 Subject: [PATCH] Adjust new IPC methods + added testing methods --- Glamourer/Api/GlamourerIpc.ApplyByGUID.cs | 28 +++++++++---------- Glamourer/Api/GlamourerIpc.GetDesign.cs | 20 +++---------- Glamourer/Api/GlamourerIpc.cs | 10 +++---- Glamourer/Gui/Tabs/DebugTab/IpcTesterPanel.cs | 24 ++++++++++++++++ 4 files changed, 47 insertions(+), 35 deletions(-) diff --git a/Glamourer/Api/GlamourerIpc.ApplyByGUID.cs b/Glamourer/Api/GlamourerIpc.ApplyByGUID.cs index 92088b1..2d816e7 100644 --- a/Glamourer/Api/GlamourerIpc.ApplyByGUID.cs +++ b/Glamourer/Api/GlamourerIpc.ApplyByGUID.cs @@ -12,27 +12,27 @@ namespace Glamourer.Api; public partial class GlamourerIpc { - public const string LabelApplyByGuidAll = "Glamourer.ApplyByGuidAll"; - public const string LabelApplyByGuidAllToCharacter = "Glamourer.ApplyByGuidAllToCharacter"; + public const string LabelApplyByGuid = "Glamourer.ApplyByGuid"; + public const string LabelApplyByGuidToCharacter = "Glamourer.ApplyByGuidToCharacter"; - private readonly ActionProvider _applyByGuidAllProvider; - private readonly ActionProvider _applyByGuidAllToCharacterProvider; + private readonly ActionProvider _applyByGuidProvider; + private readonly ActionProvider _applyByGuidToCharacterProvider; - public static ActionSubscriber ApplyByGuidAllSubscriber(DalamudPluginInterface pi) - => new(pi, LabelApplyByGuidAll); + public static ActionSubscriber ApplyByGuidSubscriber(DalamudPluginInterface pi) + => new(pi, LabelApplyByGuid); - public static ActionSubscriber ApplyByGuidAllToCharacterSubscriber(DalamudPluginInterface pi) - => new(pi, LabelApplyByGuidAllToCharacter); + public static ActionSubscriber ApplyByGuidToCharacterSubscriber(DalamudPluginInterface pi) + => new(pi, LabelApplyByGuidToCharacter); - public void ApplyByGuidAll(Guid GUID, string characterName) - => ApplyDesignByGuid(GUID, FindActors(characterName), 0); + public void ApplyByGuid(Guid Identifier, string characterName) + => ApplyDesignByGuid(Identifier, FindActors(characterName), 0); - public void ApplyByGuidAllToCharacter(Guid GUID, Character? character) - => ApplyDesignByGuid(GUID, FindActors(character), 0); + public void ApplyByGuidToCharacter(Guid Identifier, Character? character) + => ApplyDesignByGuid(Identifier, FindActors(character), 0); - private void ApplyDesignByGuid(Guid GUID, IEnumerable actors, uint lockCode) + private void ApplyDesignByGuid(Guid Identifier, IEnumerable actors, uint lockCode) { - var design = _designManager.Designs.FirstOrDefault(x => x.Identifier == GUID); + var design = _designManager.Designs.FirstOrDefault(x => x.Identifier == Identifier); if (design == null) return; diff --git a/Glamourer/Api/GlamourerIpc.GetDesign.cs b/Glamourer/Api/GlamourerIpc.GetDesign.cs index 7d655ee..2c53f57 100644 --- a/Glamourer/Api/GlamourerIpc.GetDesign.cs +++ b/Glamourer/Api/GlamourerIpc.GetDesign.cs @@ -16,23 +16,11 @@ public partial class GlamourerIpc { public const string LabelGetDesignList = "Glamourer.GetDesignList"; - private readonly FuncProvider _getDesignListProvider; + private readonly FuncProvider<(string Name, Guid Identifier)[]> _getDesignListProvider; - public static FuncSubscriber GetDesignListSubscriber(DalamudPluginInterface pi) + public static FuncSubscriber<(string Name, Guid Identifier)[]> GetDesignListSubscriber(DalamudPluginInterface pi) => new(pi, LabelGetDesignList); - public DesignListEntry[] GetDesignList() - => _designManager.Designs.Select(x => new DesignListEntry(x)).ToArray(); - - public record class DesignListEntry - { - public string Name; - public Guid Identifier; - - public DesignListEntry(Design design) - { - Name = design.Name; - Identifier = design.Identifier; - } - } + public (string Name, Guid Identifier)[] GetDesignList() + => _designManager.Designs.Select(x => (x.Name.Text, x.Identifier)).ToArray(); } diff --git a/Glamourer/Api/GlamourerIpc.cs b/Glamourer/Api/GlamourerIpc.cs index 54c4fa7..dd4b5bd 100644 --- a/Glamourer/Api/GlamourerIpc.cs +++ b/Glamourer/Api/GlamourerIpc.cs @@ -81,10 +81,10 @@ public partial class GlamourerIpc : IDisposable _stateChangedEvent.Subscribe(OnStateChanged, StateChanged.Priority.GlamourerIpc); _gPose.Subscribe(OnGPoseChanged, GPoseService.Priority.GlamourerIpc); - _applyByGuidAllProvider = new ActionProvider(pi, LabelApplyByGuidAll, ApplyByGuidAll); - _applyByGuidAllToCharacterProvider = new ActionProvider(pi, LabelApplyByGuidAllToCharacter, ApplyByGuidAllToCharacter); + _applyByGuidProvider = new ActionProvider(pi, LabelApplyByGuid, ApplyByGuid); + _applyByGuidToCharacterProvider = new ActionProvider(pi, LabelApplyByGuidToCharacter, ApplyByGuidToCharacter); - _getDesignListProvider = new FuncProvider(pi, LabelGetDesignList, GetDesignList); + _getDesignListProvider = new FuncProvider<(string Name, Guid Identifier)[]>(pi, LabelGetDesignList, GetDesignList); } public void Dispose() @@ -122,8 +122,8 @@ public partial class GlamourerIpc : IDisposable _gPose.Unsubscribe(OnGPoseChanged); _gPoseChangedProvider.Dispose(); - _applyByGuidAllProvider.Dispose(); - _applyByGuidAllToCharacterProvider.Dispose(); + _applyByGuidProvider.Dispose(); + _applyByGuidToCharacterProvider.Dispose(); _getDesignListProvider.Dispose(); } diff --git a/Glamourer/Gui/Tabs/DebugTab/IpcTesterPanel.cs b/Glamourer/Gui/Tabs/DebugTab/IpcTesterPanel.cs index e42d252..02a2e21 100644 --- a/Glamourer/Gui/Tabs/DebugTab/IpcTesterPanel.cs +++ b/Glamourer/Gui/Tabs/DebugTab/IpcTesterPanel.cs @@ -5,6 +5,8 @@ using Glamourer.Interop; using ImGuiNET; using OtterGui; using OtterGui.Raii; +using System; +using System.Linq; namespace Glamourer.Gui.Tabs.DebugTab; @@ -19,12 +21,14 @@ public class IpcTesterPanel(DalamudPluginInterface _pluginInterface, ObjectManag private int _gameObjectIndex; private string _gameObjectName = string.Empty; private string _base64Apply = string.Empty; + private string _designIdentifier = string.Empty; public void Draw() { ImGui.InputInt("Game Object Index", ref _gameObjectIndex, 0, 0); ImGui.InputTextWithHint("##gameObject", "Character Name...", ref _gameObjectName, 64); ImGui.InputTextWithHint("##base64", "Design Base64...", ref _base64Apply, 2047); + ImGui.InputTextWithHint("##identifier", "Design identifier...", ref _designIdentifier, 36); using var table = ImRaii.Table("##ipc", 2, ImGuiTableFlags.SizingFixedFit | ImGuiTableFlags.RowBg); if (!table) return; @@ -50,6 +54,15 @@ public class IpcTesterPanel(DalamudPluginInterface _pluginInterface, ObjectManag else ImGui.TextUnformatted("Error"); + ImGuiUtil.DrawTableColumn(GlamourerIpc.LabelGetDesignList); + ImGui.TableNextColumn(); + var designList = GlamourerIpc.GetDesignListSubscriber(_pluginInterface) + .Invoke(); + if (designList != null) + ImGuiUtil.CopyOnClickSelectable(string.Join(", ", designList)); + else + ImGui.TextUnformatted("Error"); + ImGuiUtil.DrawTableColumn(GlamourerIpc.LabelRevert); ImGui.TableNextColumn(); if (ImGui.Button("Revert##Name")) @@ -104,5 +117,16 @@ public class IpcTesterPanel(DalamudPluginInterface _pluginInterface, ObjectManag if (ImGui.Button("Revert##CustomizeCharacter")) GlamourerIpc.RevertToAutomationCharacterSubscriber(_pluginInterface) .Invoke(_objectManager.Objects[_gameObjectIndex] as Character, 1337); + + ImGuiUtil.DrawTableColumn(GlamourerIpc.LabelApplyByGuid); + ImGui.TableNextColumn(); + if (ImGui.Button("Apply##ByGuidName")) + GlamourerIpc.ApplyByGuidSubscriber(_pluginInterface).Invoke(Guid.Parse(_designIdentifier), _gameObjectName); + + ImGuiUtil.DrawTableColumn(GlamourerIpc.LabelApplyByGuidToCharacter); + ImGui.TableNextColumn(); + if (ImGui.Button("Apply##ByGuidCharacter")) + GlamourerIpc.ApplyByGuidToCharacterSubscriber(_pluginInterface) + .Invoke(Guid.Parse(_designIdentifier), _objectManager.Objects[_gameObjectIndex] as Character); } }