From 6308a22c1a4e8ba3a3c026fd0bcdcd10d3376c8e Mon Sep 17 00:00:00 2001 From: Stanley Dimant Date: Sun, 19 Jun 2022 00:23:53 +0200 Subject: [PATCH] add revert character customization --- Glamourer/Api/GlamourerIpc.cs | 39 +++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/Glamourer/Api/GlamourerIpc.cs b/Glamourer/Api/GlamourerIpc.cs index 3a642cd..c24e31b 100644 --- a/Glamourer/Api/GlamourerIpc.cs +++ b/Glamourer/Api/GlamourerIpc.cs @@ -10,10 +10,11 @@ namespace Glamourer.Api; public class GlamourerIpc : IDisposable { - public const int CurrentApiVersion = 0; - public const string LabelProviderApiVersion = "Glamourer.ApiVersion"; - public const string LabelProviderGetCharacterCustomization = "Glamourer.GetCharacterCustomization"; - public const string LabelProviderApplyCharacterCustomization = "Glamourer.ApplyCharacterCustomization"; + public const int CurrentApiVersion = 0; + public const string LabelProviderApiVersion = "Glamourer.ApiVersion"; + public const string LabelProviderGetCharacterCustomization = "Glamourer.GetCharacterCustomization"; + public const string LabelProviderApplyCharacterCustomization = "Glamourer.ApplyCharacterCustomization"; + public const string LabelProviderRevertCharacterCustomization = "Glamourer.RevertCharacterCustomization"; private readonly ClientState _clientState; private readonly ObjectTable _objectTable; @@ -21,6 +22,7 @@ public class GlamourerIpc : IDisposable internal ICallGateProvider? ProviderGetCharacterCustomization; internal ICallGateProvider? ProviderApplyCharacterCustomization; + internal ICallGateProvider? ProviderRevertCharacterCustomization; internal ICallGateProvider? ProviderGetApiVersion; public GlamourerIpc(ClientState clientState, ObjectTable objectTable, DalamudPluginInterface pluginInterface) @@ -39,6 +41,7 @@ public class GlamourerIpc : IDisposable { ProviderApplyCharacterCustomization?.UnregisterFunc(); ProviderGetCharacterCustomization?.UnregisterAction(); + ProviderRevertCharacterCustomization?.UnregisterAction(); ProviderGetApiVersion?.UnregisterFunc(); } @@ -74,6 +77,17 @@ public class GlamourerIpc : IDisposable { PluginLog.Error(ex, $"Error registering IPC provider for {LabelProviderApplyCharacterCustomization}."); } + + try + { + ProviderRevertCharacterCustomization = + _pluginInterface.GetIpcProvider(LabelProviderRevertCharacterCustomization); + ProviderRevertCharacterCustomization.RegisterAction(RevertCharacterCustomization); + } + catch (Exception ex) + { + PluginLog.Error(ex, $"Error registering IPC provider for {LabelProviderRevertCharacterCustomization}."); + } } private static int GetApiVersion() @@ -88,8 +102,25 @@ public class GlamourerIpc : IDisposable continue; var player = (Character)gameObject; + Glamourer.RevertableDesigns.Revert(player); + Glamourer.RevertableDesigns.Add(player); save.Apply(player); Glamourer.Penumbra.UpdateCharacters(player, null); + break; + } + } + + private void RevertCharacterCustomization(string characterName) + { + foreach (var gameObject in _objectTable) + { + if (gameObject.Name.ToString() != characterName) + continue; + + var player = (Character)gameObject; + Glamourer.RevertableDesigns.Revert(player); + Glamourer.Penumbra.UpdateCharacters(player, null); + break; } }