mirror of
https://github.com/Ottermandias/Glamourer.git
synced 2025-12-12 18:27:24 +01:00
add more IPC calls, adjust revertable to clear the state after a revert.
This commit is contained in:
parent
d4529edba6
commit
3c56124705
2 changed files with 102 additions and 29 deletions
|
|
@ -10,19 +10,23 @@ namespace Glamourer.Api;
|
||||||
|
|
||||||
public class GlamourerIpc : IDisposable
|
public class GlamourerIpc : IDisposable
|
||||||
{
|
{
|
||||||
public const int CurrentApiVersion = 0;
|
public const int CurrentApiVersion = 0;
|
||||||
public const string LabelProviderApiVersion = "Glamourer.ApiVersion";
|
public const string LabelProviderApiVersion = "Glamourer.ApiVersion";
|
||||||
public const string LabelProviderGetCharacterCustomization = "Glamourer.GetCharacterCustomization";
|
public const string LabelProviderGetAllCustomization = "Glamourer.GetAllCustomization";
|
||||||
public const string LabelProviderApplyCharacterCustomization = "Glamourer.ApplyCharacterCustomization";
|
public const string LabelProviderApplyAll = "Glamourer.ApplyAll";
|
||||||
public const string LabelProviderRevertCharacterCustomization = "Glamourer.RevertCharacterCustomization";
|
public const string LabelProviderApplyOnlyEquipment = "Glamourer.ApplyOnlyEquipment";
|
||||||
|
public const string LabelProviderApplyOnlyCustomization = "Glamourer.ApplyOnlyCustomization";
|
||||||
|
public const string LabelProviderRevert = "Glamourer.Revert";
|
||||||
|
|
||||||
private readonly ClientState _clientState;
|
private readonly ClientState _clientState;
|
||||||
private readonly ObjectTable _objectTable;
|
private readonly ObjectTable _objectTable;
|
||||||
private readonly DalamudPluginInterface _pluginInterface;
|
private readonly DalamudPluginInterface _pluginInterface;
|
||||||
|
|
||||||
internal ICallGateProvider<string, string>? ProviderGetCharacterCustomization;
|
internal ICallGateProvider<string, string?>? ProviderGetAllCustomization;
|
||||||
internal ICallGateProvider<string, string, object>? ProviderApplyCharacterCustomization;
|
internal ICallGateProvider<string, string, object>? ProviderApplyAll;
|
||||||
internal ICallGateProvider<string, object>? ProviderRevertCharacterCustomization;
|
internal ICallGateProvider<string, string, object>? ProviderApplyOnlyCustomization;
|
||||||
|
internal ICallGateProvider<string, string, object>? ProviderApplyOnlyEquipment;
|
||||||
|
internal ICallGateProvider<string, object>? ProviderRevert;
|
||||||
internal ICallGateProvider<int>? ProviderGetApiVersion;
|
internal ICallGateProvider<int>? ProviderGetApiVersion;
|
||||||
|
|
||||||
public GlamourerIpc(ClientState clientState, ObjectTable objectTable, DalamudPluginInterface pluginInterface)
|
public GlamourerIpc(ClientState clientState, ObjectTable objectTable, DalamudPluginInterface pluginInterface)
|
||||||
|
|
@ -39,10 +43,13 @@ public class GlamourerIpc : IDisposable
|
||||||
|
|
||||||
private void DisposeProviders()
|
private void DisposeProviders()
|
||||||
{
|
{
|
||||||
ProviderApplyCharacterCustomization?.UnregisterFunc();
|
ProviderGetAllCustomization?.UnregisterFunc();
|
||||||
ProviderGetCharacterCustomization?.UnregisterAction();
|
ProviderApplyAll?.UnregisterAction();
|
||||||
ProviderRevertCharacterCustomization?.UnregisterAction();
|
ProviderApplyOnlyCustomization?.UnregisterAction();
|
||||||
|
ProviderApplyOnlyEquipment?.UnregisterAction();
|
||||||
|
ProviderRevert?.UnregisterAction();
|
||||||
ProviderGetApiVersion?.UnregisterFunc();
|
ProviderGetApiVersion?.UnregisterFunc();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void InitializeProviders()
|
private void InitializeProviders()
|
||||||
|
|
@ -59,41 +66,63 @@ public class GlamourerIpc : IDisposable
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ProviderGetCharacterCustomization = _pluginInterface.GetIpcProvider<string, string>(LabelProviderGetCharacterCustomization);
|
ProviderGetAllCustomization = _pluginInterface.GetIpcProvider<string, string?>(LabelProviderGetAllCustomization);
|
||||||
ProviderGetCharacterCustomization.RegisterFunc(GetCharacterCustomization);
|
ProviderGetAllCustomization.RegisterFunc(GetAllCustomization);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
PluginLog.Error(ex, $"Error registering IPC provider for {LabelProviderApplyCharacterCustomization}.");
|
PluginLog.Error(ex, $"Error registering IPC provider for {LabelProviderApplyOnlyEquipment}.");
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ProviderApplyCharacterCustomization =
|
ProviderApplyAll =
|
||||||
_pluginInterface.GetIpcProvider<string, string, object>(LabelProviderApplyCharacterCustomization);
|
_pluginInterface.GetIpcProvider<string, string, object>(LabelProviderApplyAll);
|
||||||
ProviderApplyCharacterCustomization.RegisterAction(ApplyCharacterCustomization);
|
ProviderApplyAll.RegisterAction(ApplyAll);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
PluginLog.Error(ex, $"Error registering IPC provider for {LabelProviderApplyCharacterCustomization}.");
|
PluginLog.Error(ex, $"Error registering IPC provider for {LabelProviderApplyAll}.");
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ProviderRevertCharacterCustomization =
|
ProviderApplyOnlyCustomization =
|
||||||
_pluginInterface.GetIpcProvider<string, object>(LabelProviderRevertCharacterCustomization);
|
_pluginInterface.GetIpcProvider<string, string, object>(LabelProviderApplyOnlyCustomization);
|
||||||
ProviderRevertCharacterCustomization.RegisterAction(RevertCharacterCustomization);
|
ProviderApplyOnlyCustomization.RegisterAction(ApplyOnlyCustomization);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
PluginLog.Error(ex, $"Error registering IPC provider for {LabelProviderRevertCharacterCustomization}.");
|
PluginLog.Error(ex, $"Error registering IPC provider for {LabelProviderApplyOnlyCustomization}.");
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ProviderApplyOnlyEquipment =
|
||||||
|
_pluginInterface.GetIpcProvider<string, string, object>(LabelProviderApplyOnlyEquipment);
|
||||||
|
ProviderApplyOnlyEquipment.RegisterAction(ApplyOnlyEquipment);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
PluginLog.Error(ex, $"Error registering IPC provider for {LabelProviderApplyOnlyEquipment}.");
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ProviderRevert =
|
||||||
|
_pluginInterface.GetIpcProvider<string, object>(LabelProviderRevert);
|
||||||
|
ProviderRevert.RegisterAction(Revert);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
PluginLog.Error(ex, $"Error registering IPC provider for {LabelProviderRevert}.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int GetApiVersion()
|
private static int GetApiVersion()
|
||||||
=> CurrentApiVersion;
|
=> CurrentApiVersion;
|
||||||
|
|
||||||
private void ApplyCharacterCustomization(string customization, string characterName)
|
private void ApplyAll(string customization, string characterName)
|
||||||
{
|
{
|
||||||
var save = CharacterSave.FromString(customization);
|
var save = CharacterSave.FromString(customization);
|
||||||
foreach (var gameObject in _objectTable)
|
foreach (var gameObject in _objectTable)
|
||||||
|
|
@ -103,14 +132,45 @@ public class GlamourerIpc : IDisposable
|
||||||
|
|
||||||
var player = (Character)gameObject;
|
var player = (Character)gameObject;
|
||||||
Glamourer.RevertableDesigns.Revert(player);
|
Glamourer.RevertableDesigns.Revert(player);
|
||||||
Glamourer.RevertableDesigns.Add(player);
|
|
||||||
save.Apply(player);
|
save.Apply(player);
|
||||||
Glamourer.Penumbra.UpdateCharacters(player, null);
|
Glamourer.Penumbra.UpdateCharacters(player, null);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RevertCharacterCustomization(string characterName)
|
private void ApplyOnlyCustomization(string customization, string characterName)
|
||||||
|
{
|
||||||
|
var save = CharacterSave.FromString(customization);
|
||||||
|
foreach (var gameObject in _objectTable)
|
||||||
|
{
|
||||||
|
if (gameObject.Name.ToString() != characterName)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
var player = (Character)gameObject;
|
||||||
|
Glamourer.RevertableDesigns.Revert(player);
|
||||||
|
save.ApplyOnlyCustomizations(player);
|
||||||
|
Glamourer.Penumbra.UpdateCharacters(player, null);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ApplyOnlyEquipment(string customization, string characterName)
|
||||||
|
{
|
||||||
|
var save = CharacterSave.FromString(customization);
|
||||||
|
foreach (var gameObject in _objectTable)
|
||||||
|
{
|
||||||
|
if (gameObject.Name.ToString() != characterName)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
var player = (Character)gameObject;
|
||||||
|
Glamourer.RevertableDesigns.Revert(player);
|
||||||
|
save.ApplyOnlyEquipment(player);
|
||||||
|
Glamourer.Penumbra.UpdateCharacters(player, null);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Revert(string characterName)
|
||||||
{
|
{
|
||||||
foreach (var gameObject in _objectTable)
|
foreach (var gameObject in _objectTable)
|
||||||
{
|
{
|
||||||
|
|
@ -120,23 +180,26 @@ public class GlamourerIpc : IDisposable
|
||||||
var player = (Character)gameObject;
|
var player = (Character)gameObject;
|
||||||
Glamourer.RevertableDesigns.Revert(player);
|
Glamourer.RevertableDesigns.Revert(player);
|
||||||
Glamourer.Penumbra.UpdateCharacters(player, null);
|
Glamourer.Penumbra.UpdateCharacters(player, null);
|
||||||
break;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Glamourer.RevertableDesigns.RevertByNameWithoutApplication(characterName);
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GetCharacterCustomization(string characterName)
|
private string? GetAllCustomization(string characterName)
|
||||||
{
|
{
|
||||||
var save = new CharacterSave();
|
CharacterSave save = null!;
|
||||||
foreach (var gameObject in _objectTable)
|
foreach (var gameObject in _objectTable)
|
||||||
{
|
{
|
||||||
if (gameObject.Name.ToString() != characterName)
|
if (gameObject.Name.ToString() != characterName)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
var player = (Character)gameObject;
|
var player = (Character)gameObject;
|
||||||
|
save = new CharacterSave();
|
||||||
save.LoadCharacter(player);
|
save.LoadCharacter(player);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return save.ToBase64();
|
return save?.ToBase64() ?? null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,12 +19,22 @@ namespace Glamourer.Designs
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool RevertByNameWithoutApplication(string actorName)
|
||||||
|
{
|
||||||
|
if (!Saves.ContainsKey(actorName))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
Saves.Remove(actorName);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public bool Revert(Character actor)
|
public bool Revert(Character actor)
|
||||||
{
|
{
|
||||||
if (!Saves.TryGetValue(actor.Name.ToString(), out var save))
|
if (!Saves.TryGetValue(actor.Name.ToString(), out var save))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
save.Apply(actor);
|
save.Apply(actor);
|
||||||
|
Saves.Remove(actor.Name.ToString());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue