Add RevertToAutomation IPC.

This commit is contained in:
Ottermandias 2023-09-30 23:40:52 +02:00
parent ea55d9cb03
commit c2b5064256
3 changed files with 56 additions and 7 deletions

View file

@ -14,6 +14,7 @@ public partial class GlamourerIpc
public const string LabelRevertLock = "Glamourer.RevertLock"; public const string LabelRevertLock = "Glamourer.RevertLock";
public const string LabelRevertCharacterLock = "Glamourer.RevertCharacterLock"; public const string LabelRevertCharacterLock = "Glamourer.RevertCharacterLock";
public const string LabelUnlock = "Glamourer.Unlock"; public const string LabelUnlock = "Glamourer.Unlock";
public const string LabelRevertToAutomation = "Glamourer.RevertToAutomation";
private readonly ActionProvider<string> _revertProvider; private readonly ActionProvider<string> _revertProvider;
private readonly ActionProvider<Character?> _revertCharacterProvider; private readonly ActionProvider<Character?> _revertCharacterProvider;
@ -21,6 +22,8 @@ public partial class GlamourerIpc
private readonly ActionProvider<string, uint> _revertProviderLock; private readonly ActionProvider<string, uint> _revertProviderLock;
private readonly ActionProvider<Character?, uint> _revertCharacterProviderLock; private readonly ActionProvider<Character?, uint> _revertCharacterProviderLock;
private readonly FuncProvider<Character?, uint, bool> _revertToAutomationProvider;
private readonly FuncProvider<Character?, uint, bool> _unlockProvider; private readonly FuncProvider<Character?, uint, bool> _unlockProvider;
public static ActionSubscriber<string> RevertSubscriber(DalamudPluginInterface pi) public static ActionSubscriber<string> RevertSubscriber(DalamudPluginInterface pi)
@ -29,6 +32,12 @@ public partial class GlamourerIpc
public static ActionSubscriber<Character?> RevertCharacterSubscriber(DalamudPluginInterface pi) public static ActionSubscriber<Character?> RevertCharacterSubscriber(DalamudPluginInterface pi)
=> new(pi, LabelRevertCharacter); => new(pi, LabelRevertCharacter);
public static FuncSubscriber<Character?, uint, bool> UnlockSubscriber(DalamudPluginInterface pi)
=> new(pi, LabelUnlock);
public static FuncSubscriber<Character?, uint, bool> RevertToAutomationSubscriber(DalamudPluginInterface pi)
=> new(pi, LabelRevertToAutomation);
public void Revert(string characterName) public void Revert(string characterName)
=> Revert(FindActors(characterName), 0); => Revert(FindActors(characterName), 0);
@ -44,6 +53,9 @@ public partial class GlamourerIpc
public bool Unlock(Character? character, uint lockCode) public bool Unlock(Character? character, uint lockCode)
=> Unlock(FindActors(character), lockCode); => Unlock(FindActors(character), lockCode);
public bool RevertToAutomation(Character? character, uint lockCode)
=> RevertToAutomation(FindActors(character), lockCode);
private void Revert(IEnumerable<ActorIdentifier> actors, uint lockCode) private void Revert(IEnumerable<ActorIdentifier> actors, uint lockCode)
{ {
foreach (var id in actors) foreach (var id in actors)
@ -64,4 +76,24 @@ public partial class GlamourerIpc
return ret; return ret;
} }
private bool RevertToAutomation(IEnumerable<ActorIdentifier> 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;
}
} }

View file

@ -3,6 +3,7 @@ using Dalamud.Plugin;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Glamourer.Automation;
using Glamourer.Designs; using Glamourer.Designs;
using Glamourer.Events; using Glamourer.Events;
using Glamourer.Interop; using Glamourer.Interop;
@ -17,20 +18,22 @@ namespace Glamourer.Api;
public partial class GlamourerIpc : IDisposable public partial class GlamourerIpc : IDisposable
{ {
public const int CurrentApiVersionMajor = 0; public const int CurrentApiVersionMajor = 0;
public const int CurrentApiVersionMinor = 3; public const int CurrentApiVersionMinor = 4;
private readonly StateManager _stateManager; private readonly StateManager _stateManager;
private readonly ObjectManager _objects; private readonly ObjectManager _objects;
private readonly ActorService _actors; private readonly ActorService _actors;
private readonly DesignConverter _designConverter; private readonly DesignConverter _designConverter;
private readonly AutoDesignApplier _autoDesignApplier;
public GlamourerIpc(DalamudPluginInterface pi, StateManager stateManager, ObjectManager objects, ActorService actors, 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; _stateManager = stateManager;
_objects = objects; _objects = objects;
_actors = actors; _actors = actors;
_designConverter = designConverter; _designConverter = designConverter;
_autoDesignApplier = autoDesignApplier;
_gPose = gPose; _gPose = gPose;
_stateChangedEvent = stateChangedEvent; _stateChangedEvent = stateChangedEvent;
_apiVersionProvider = new FuncProvider<int>(pi, LabelApiVersion, ApiVersion); _apiVersionProvider = new FuncProvider<int>(pi, LabelApiVersion, ApiVersion);
@ -65,6 +68,7 @@ public partial class GlamourerIpc : IDisposable
_revertProviderLock = new ActionProvider<string, uint>(pi, LabelRevertLock, RevertLock); _revertProviderLock = new ActionProvider<string, uint>(pi, LabelRevertLock, RevertLock);
_revertCharacterProviderLock = new ActionProvider<Character?, uint>(pi, LabelRevertCharacterLock, RevertCharacterLock); _revertCharacterProviderLock = new ActionProvider<Character?, uint>(pi, LabelRevertCharacterLock, RevertCharacterLock);
_unlockProvider = new FuncProvider<Character?, uint, bool>(pi, LabelUnlock, Unlock); _unlockProvider = new FuncProvider<Character?, uint, bool>(pi, LabelUnlock, Unlock);
_revertToAutomationProvider = new FuncProvider<Character?, uint, bool>(pi, LabelRevertToAutomation, RevertToAutomation);
_stateChangedProvider = new EventProvider<StateChanged.Type, nint, Lazy<string>>(pi, LabelStateChanged); _stateChangedProvider = new EventProvider<StateChanged.Type, nint, Lazy<string>>(pi, LabelStateChanged);
_gPoseChangedProvider = new EventProvider<bool>(pi, LabelGPoseChanged); _gPoseChangedProvider = new EventProvider<bool>(pi, LabelGPoseChanged);
@ -99,6 +103,7 @@ public partial class GlamourerIpc : IDisposable
_revertProviderLock.Dispose(); _revertProviderLock.Dispose();
_revertCharacterProviderLock.Dispose(); _revertCharacterProviderLock.Dispose();
_unlockProvider.Dispose(); _unlockProvider.Dispose();
_revertToAutomationProvider.Dispose();
_stateChangedEvent.Unsubscribe(OnStateChanged); _stateChangedEvent.Unsubscribe(OnStateChanged);
_stateChangedProvider.Dispose(); _stateChangedProvider.Dispose();

View file

@ -526,7 +526,7 @@ public unsafe class DebugTab : ITab
using (var disabled = ImRaii.Disabled(!_penumbra.Available)) using (var disabled = ImRaii.Disabled(!_penumbra.Available))
{ {
if (ImGui.SmallButton("Redraw")) if (ImGui.SmallButton("Redraw"))
_penumbra.RedrawObject((ObjectIndex) _gameObjectIndex, RedrawType.Redraw); _penumbra.RedrawObject((ObjectIndex)_gameObjectIndex, RedrawType.Redraw);
} }
ImGuiUtil.DrawTableColumn("Last Tooltip Date"); ImGuiUtil.DrawTableColumn("Last Tooltip Date");
@ -1682,6 +1682,18 @@ public unsafe class DebugTab : ITab
if (ImGui.Button("Apply##CustomizeCharacter")) if (ImGui.Button("Apply##CustomizeCharacter"))
GlamourerIpc.ApplyOnlyCustomizationToCharacterSubscriber(_pluginInterface) GlamourerIpc.ApplyOnlyCustomizationToCharacterSubscriber(_pluginInterface)
.Invoke(_base64Apply, _objectManager.Objects[_gameObjectIndex] as Character); .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 #endregion