Adjust new IPC methods + added testing methods

This commit is contained in:
Limiana 2023-12-29 21:33:21 +03:00
parent 6fe68c59d1
commit 9395072bee
4 changed files with 47 additions and 35 deletions

View file

@ -12,27 +12,27 @@ namespace Glamourer.Api;
public partial class GlamourerIpc public partial class GlamourerIpc
{ {
public const string LabelApplyByGuidAll = "Glamourer.ApplyByGuidAll"; public const string LabelApplyByGuid = "Glamourer.ApplyByGuid";
public const string LabelApplyByGuidAllToCharacter = "Glamourer.ApplyByGuidAllToCharacter"; public const string LabelApplyByGuidToCharacter = "Glamourer.ApplyByGuidToCharacter";
private readonly ActionProvider<Guid, string> _applyByGuidAllProvider; private readonly ActionProvider<Guid, string> _applyByGuidProvider;
private readonly ActionProvider<Guid, Character?> _applyByGuidAllToCharacterProvider; private readonly ActionProvider<Guid, Character?> _applyByGuidToCharacterProvider;
public static ActionSubscriber<Guid, string> ApplyByGuidAllSubscriber(DalamudPluginInterface pi) public static ActionSubscriber<Guid, string> ApplyByGuidSubscriber(DalamudPluginInterface pi)
=> new(pi, LabelApplyByGuidAll); => new(pi, LabelApplyByGuid);
public static ActionSubscriber<Guid, Character?> ApplyByGuidAllToCharacterSubscriber(DalamudPluginInterface pi) public static ActionSubscriber<Guid, Character?> ApplyByGuidToCharacterSubscriber(DalamudPluginInterface pi)
=> new(pi, LabelApplyByGuidAllToCharacter); => new(pi, LabelApplyByGuidToCharacter);
public void ApplyByGuidAll(Guid GUID, string characterName) public void ApplyByGuid(Guid Identifier, string characterName)
=> ApplyDesignByGuid(GUID, FindActors(characterName), 0); => ApplyDesignByGuid(Identifier, FindActors(characterName), 0);
public void ApplyByGuidAllToCharacter(Guid GUID, Character? character) public void ApplyByGuidToCharacter(Guid Identifier, Character? character)
=> ApplyDesignByGuid(GUID, FindActors(character), 0); => ApplyDesignByGuid(Identifier, FindActors(character), 0);
private void ApplyDesignByGuid(Guid GUID, IEnumerable<ActorIdentifier> actors, uint lockCode) private void ApplyDesignByGuid(Guid Identifier, IEnumerable<ActorIdentifier> actors, uint lockCode)
{ {
var design = _designManager.Designs.FirstOrDefault(x => x.Identifier == GUID); var design = _designManager.Designs.FirstOrDefault(x => x.Identifier == Identifier);
if (design == null) if (design == null)
return; return;

View file

@ -16,23 +16,11 @@ public partial class GlamourerIpc
{ {
public const string LabelGetDesignList = "Glamourer.GetDesignList"; public const string LabelGetDesignList = "Glamourer.GetDesignList";
private readonly FuncProvider<DesignListEntry[]> _getDesignListProvider; private readonly FuncProvider<(string Name, Guid Identifier)[]> _getDesignListProvider;
public static FuncSubscriber<DesignListEntry[]> GetDesignListSubscriber(DalamudPluginInterface pi) public static FuncSubscriber<(string Name, Guid Identifier)[]> GetDesignListSubscriber(DalamudPluginInterface pi)
=> new(pi, LabelGetDesignList); => new(pi, LabelGetDesignList);
public DesignListEntry[] GetDesignList() public (string Name, Guid Identifier)[] GetDesignList()
=> _designManager.Designs.Select(x => new DesignListEntry(x)).ToArray(); => _designManager.Designs.Select(x => (x.Name.Text, x.Identifier)).ToArray();
public record class DesignListEntry
{
public string Name;
public Guid Identifier;
public DesignListEntry(Design design)
{
Name = design.Name;
Identifier = design.Identifier;
}
}
} }

View file

@ -81,10 +81,10 @@ public partial class GlamourerIpc : IDisposable
_stateChangedEvent.Subscribe(OnStateChanged, StateChanged.Priority.GlamourerIpc); _stateChangedEvent.Subscribe(OnStateChanged, StateChanged.Priority.GlamourerIpc);
_gPose.Subscribe(OnGPoseChanged, GPoseService.Priority.GlamourerIpc); _gPose.Subscribe(OnGPoseChanged, GPoseService.Priority.GlamourerIpc);
_applyByGuidAllProvider = new ActionProvider<Guid, string>(pi, LabelApplyByGuidAll, ApplyByGuidAll); _applyByGuidProvider = new ActionProvider<Guid, string>(pi, LabelApplyByGuid, ApplyByGuid);
_applyByGuidAllToCharacterProvider = new ActionProvider<Guid, Character?>(pi, LabelApplyByGuidAllToCharacter, ApplyByGuidAllToCharacter); _applyByGuidToCharacterProvider = new ActionProvider<Guid, Character?>(pi, LabelApplyByGuidToCharacter, ApplyByGuidToCharacter);
_getDesignListProvider = new FuncProvider<DesignListEntry[]>(pi, LabelGetDesignList, GetDesignList); _getDesignListProvider = new FuncProvider<(string Name, Guid Identifier)[]>(pi, LabelGetDesignList, GetDesignList);
} }
public void Dispose() public void Dispose()
@ -122,8 +122,8 @@ public partial class GlamourerIpc : IDisposable
_gPose.Unsubscribe(OnGPoseChanged); _gPose.Unsubscribe(OnGPoseChanged);
_gPoseChangedProvider.Dispose(); _gPoseChangedProvider.Dispose();
_applyByGuidAllProvider.Dispose(); _applyByGuidProvider.Dispose();
_applyByGuidAllToCharacterProvider.Dispose(); _applyByGuidToCharacterProvider.Dispose();
_getDesignListProvider.Dispose(); _getDesignListProvider.Dispose();
} }

View file

@ -5,6 +5,8 @@ using Glamourer.Interop;
using ImGuiNET; using ImGuiNET;
using OtterGui; using OtterGui;
using OtterGui.Raii; using OtterGui.Raii;
using System;
using System.Linq;
namespace Glamourer.Gui.Tabs.DebugTab; namespace Glamourer.Gui.Tabs.DebugTab;
@ -19,12 +21,14 @@ public class IpcTesterPanel(DalamudPluginInterface _pluginInterface, ObjectManag
private int _gameObjectIndex; private int _gameObjectIndex;
private string _gameObjectName = string.Empty; private string _gameObjectName = string.Empty;
private string _base64Apply = string.Empty; private string _base64Apply = string.Empty;
private string _designIdentifier = string.Empty;
public void Draw() public void Draw()
{ {
ImGui.InputInt("Game Object Index", ref _gameObjectIndex, 0, 0); ImGui.InputInt("Game Object Index", ref _gameObjectIndex, 0, 0);
ImGui.InputTextWithHint("##gameObject", "Character Name...", ref _gameObjectName, 64); ImGui.InputTextWithHint("##gameObject", "Character Name...", ref _gameObjectName, 64);
ImGui.InputTextWithHint("##base64", "Design Base64...", ref _base64Apply, 2047); 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); using var table = ImRaii.Table("##ipc", 2, ImGuiTableFlags.SizingFixedFit | ImGuiTableFlags.RowBg);
if (!table) if (!table)
return; return;
@ -50,6 +54,15 @@ public class IpcTesterPanel(DalamudPluginInterface _pluginInterface, ObjectManag
else else
ImGui.TextUnformatted("Error"); 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); ImGuiUtil.DrawTableColumn(GlamourerIpc.LabelRevert);
ImGui.TableNextColumn(); ImGui.TableNextColumn();
if (ImGui.Button("Revert##Name")) if (ImGui.Button("Revert##Name"))
@ -104,5 +117,16 @@ public class IpcTesterPanel(DalamudPluginInterface _pluginInterface, ObjectManag
if (ImGui.Button("Revert##CustomizeCharacter")) if (ImGui.Button("Revert##CustomizeCharacter"))
GlamourerIpc.RevertToAutomationCharacterSubscriber(_pluginInterface) GlamourerIpc.RevertToAutomationCharacterSubscriber(_pluginInterface)
.Invoke(_objectManager.Objects[_gameObjectIndex] as Character, 1337); .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);
} }
} }