add revert character customization

This commit is contained in:
Stanley Dimant 2022-06-19 00:23:53 +02:00
parent b78a6266b1
commit 6308a22c1a

View file

@ -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<string>? ProviderGetCharacterCustomization;
internal ICallGateProvider<string, string, object>? ProviderApplyCharacterCustomization;
internal ICallGateProvider<string, object>? ProviderRevertCharacterCustomization;
internal ICallGateProvider<int>? 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<string, object>(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;
}
}