From c2b506425621005ad2667d704f7f136eb79c2f1c Mon Sep 17 00:00:00 2001 From: Ottermandias Date: Sat, 30 Sep 2023 23:40:52 +0200 Subject: [PATCH] Add RevertToAutomation IPC. --- Glamourer/Api/GlamourerIpc.Revert.cs | 32 ++++++++++++++++++++++++++++ Glamourer/Api/GlamourerIpc.cs | 17 +++++++++------ Glamourer/Gui/Tabs/DebugTab.cs | 14 +++++++++++- 3 files changed, 56 insertions(+), 7 deletions(-) diff --git a/Glamourer/Api/GlamourerIpc.Revert.cs b/Glamourer/Api/GlamourerIpc.Revert.cs index e9908b8..b3760af 100644 --- a/Glamourer/Api/GlamourerIpc.Revert.cs +++ b/Glamourer/Api/GlamourerIpc.Revert.cs @@ -14,6 +14,7 @@ public partial class GlamourerIpc public const string LabelRevertLock = "Glamourer.RevertLock"; public const string LabelRevertCharacterLock = "Glamourer.RevertCharacterLock"; public const string LabelUnlock = "Glamourer.Unlock"; + public const string LabelRevertToAutomation = "Glamourer.RevertToAutomation"; private readonly ActionProvider _revertProvider; private readonly ActionProvider _revertCharacterProvider; @@ -21,6 +22,8 @@ public partial class GlamourerIpc private readonly ActionProvider _revertProviderLock; private readonly ActionProvider _revertCharacterProviderLock; + private readonly FuncProvider _revertToAutomationProvider; + private readonly FuncProvider _unlockProvider; public static ActionSubscriber RevertSubscriber(DalamudPluginInterface pi) @@ -29,6 +32,12 @@ public partial class GlamourerIpc public static ActionSubscriber RevertCharacterSubscriber(DalamudPluginInterface pi) => new(pi, LabelRevertCharacter); + public static FuncSubscriber UnlockSubscriber(DalamudPluginInterface pi) + => new(pi, LabelUnlock); + + public static FuncSubscriber RevertToAutomationSubscriber(DalamudPluginInterface pi) + => new(pi, LabelRevertToAutomation); + public void Revert(string characterName) => Revert(FindActors(characterName), 0); @@ -44,6 +53,9 @@ public partial class GlamourerIpc public bool Unlock(Character? character, uint lockCode) => Unlock(FindActors(character), lockCode); + public bool RevertToAutomation(Character? character, uint lockCode) + => RevertToAutomation(FindActors(character), lockCode); + private void Revert(IEnumerable actors, uint lockCode) { foreach (var id in actors) @@ -64,4 +76,24 @@ public partial class GlamourerIpc return ret; } + + private bool RevertToAutomation(IEnumerable actors, uint lockCode) + { + var ret = false; + foreach (var id in actors) + { + if (_stateManager.TryGetValue(id, out var state)) + { + ret |= state.Unlock(lockCode); + if (_objects.TryGetValue(id, out var data)) + foreach (var obj in data.Objects) + { + _autoDesignApplier.ReapplyAutomation(obj, state.Identifier, state); + _stateManager.ReapplyState(obj); + } + } + } + + return ret; + } } diff --git a/Glamourer/Api/GlamourerIpc.cs b/Glamourer/Api/GlamourerIpc.cs index 036ff42..a60e16e 100644 --- a/Glamourer/Api/GlamourerIpc.cs +++ b/Glamourer/Api/GlamourerIpc.cs @@ -3,6 +3,7 @@ using Dalamud.Plugin; using System; using System.Collections.Generic; using System.Linq; +using Glamourer.Automation; using Glamourer.Designs; using Glamourer.Events; using Glamourer.Interop; @@ -17,20 +18,22 @@ namespace Glamourer.Api; public partial class GlamourerIpc : IDisposable { public const int CurrentApiVersionMajor = 0; - public const int CurrentApiVersionMinor = 3; + public const int CurrentApiVersionMinor = 4; - private readonly StateManager _stateManager; - private readonly ObjectManager _objects; - private readonly ActorService _actors; - private readonly DesignConverter _designConverter; + private readonly StateManager _stateManager; + private readonly ObjectManager _objects; + private readonly ActorService _actors; + private readonly DesignConverter _designConverter; + private readonly AutoDesignApplier _autoDesignApplier; public GlamourerIpc(DalamudPluginInterface pi, StateManager stateManager, ObjectManager objects, ActorService actors, - DesignConverter designConverter, StateChanged stateChangedEvent, GPoseService gPose) + DesignConverter designConverter, StateChanged stateChangedEvent, GPoseService gPose, AutoDesignApplier autoDesignApplier) { _stateManager = stateManager; _objects = objects; _actors = actors; _designConverter = designConverter; + _autoDesignApplier = autoDesignApplier; _gPose = gPose; _stateChangedEvent = stateChangedEvent; _apiVersionProvider = new FuncProvider(pi, LabelApiVersion, ApiVersion); @@ -65,6 +68,7 @@ public partial class GlamourerIpc : IDisposable _revertProviderLock = new ActionProvider(pi, LabelRevertLock, RevertLock); _revertCharacterProviderLock = new ActionProvider(pi, LabelRevertCharacterLock, RevertCharacterLock); _unlockProvider = new FuncProvider(pi, LabelUnlock, Unlock); + _revertToAutomationProvider = new FuncProvider(pi, LabelRevertToAutomation, RevertToAutomation); _stateChangedProvider = new EventProvider>(pi, LabelStateChanged); _gPoseChangedProvider = new EventProvider(pi, LabelGPoseChanged); @@ -99,6 +103,7 @@ public partial class GlamourerIpc : IDisposable _revertProviderLock.Dispose(); _revertCharacterProviderLock.Dispose(); _unlockProvider.Dispose(); + _revertToAutomationProvider.Dispose(); _stateChangedEvent.Unsubscribe(OnStateChanged); _stateChangedProvider.Dispose(); diff --git a/Glamourer/Gui/Tabs/DebugTab.cs b/Glamourer/Gui/Tabs/DebugTab.cs index 4314de7..eb26f82 100644 --- a/Glamourer/Gui/Tabs/DebugTab.cs +++ b/Glamourer/Gui/Tabs/DebugTab.cs @@ -526,7 +526,7 @@ public unsafe class DebugTab : ITab using (var disabled = ImRaii.Disabled(!_penumbra.Available)) { if (ImGui.SmallButton("Redraw")) - _penumbra.RedrawObject((ObjectIndex) _gameObjectIndex, RedrawType.Redraw); + _penumbra.RedrawObject((ObjectIndex)_gameObjectIndex, RedrawType.Redraw); } ImGuiUtil.DrawTableColumn("Last Tooltip Date"); @@ -1682,6 +1682,18 @@ public unsafe class DebugTab : ITab if (ImGui.Button("Apply##CustomizeCharacter")) GlamourerIpc.ApplyOnlyCustomizationToCharacterSubscriber(_pluginInterface) .Invoke(_base64Apply, _objectManager.Objects[_gameObjectIndex] as Character); + + ImGuiUtil.DrawTableColumn(GlamourerIpc.LabelUnlock); + ImGui.TableNextColumn(); + if (ImGui.Button("Unlock##CustomizeCharacter")) + GlamourerIpc.UnlockSubscriber(_pluginInterface) + .Invoke(_objectManager.Objects[_gameObjectIndex] as Character, 1337); + + ImGuiUtil.DrawTableColumn(GlamourerIpc.LabelRevertToAutomation); + ImGui.TableNextColumn(); + if (ImGui.Button("Revert##CustomizeCharacter")) + GlamourerIpc.RevertToAutomationSubscriber(_pluginInterface) + .Invoke(_objectManager.Objects[_gameObjectIndex] as Character, 1337); } #endregion