Send IPC OnProfileUpdate when currently used template was changed in editor, fix Profile.GetActiveProfileIdOnCharacter IPC ignoring DefaultLocalPlayerProfile
This commit is contained in:
@@ -15,6 +15,9 @@ using CustomizePlus.GameData.Extensions;
|
||||
using Dalamud.Game.ClientState.Objects.Types;
|
||||
using Penumbra.GameData.Structs;
|
||||
using Penumbra.GameData.Enums;
|
||||
using CustomizePlus.Templates.Data;
|
||||
using CustomizePlus.Templates.Events;
|
||||
using Penumbra.GameData.Actors;
|
||||
|
||||
namespace CustomizePlus.Api;
|
||||
|
||||
@@ -144,7 +147,7 @@ public partial class CustomizePlusIpc
|
||||
if (actor == null || !actor.Value.Valid || !actor.Value.IsCharacter)
|
||||
return ((int)ErrorCode.InvalidCharacter, null);
|
||||
|
||||
var profile = _profileManager.GetProfileByActor(actor.Value, true);
|
||||
var profile = _profileManager.GetActiveProfileByActor(actor.Value);
|
||||
|
||||
if (profile == null)
|
||||
return ((int)ErrorCode.ProfileNotFound, null);
|
||||
@@ -268,6 +271,35 @@ public partial class CustomizePlusIpc
|
||||
}
|
||||
}
|
||||
|
||||
//Send profile update if any of the templates were changed in currently active profile
|
||||
private void OnTemplateChanged(TemplateChanged.Type type, Template? template, object? arg3)
|
||||
{
|
||||
if (type != TemplateChanged.Type.EditorDisabled)
|
||||
return;
|
||||
|
||||
(ActorIdentifier actorIdentifier, bool hasChanges) = ((ActorIdentifier, bool))arg3;
|
||||
|
||||
if (!hasChanges || actorIdentifier.Type != IdentifierType.Player)
|
||||
return;
|
||||
|
||||
var actor = _gameObjectService.GetLocalPlayerActor();
|
||||
if (!actor.Valid || !actorIdentifier.PlayerName.EqualsCi(actor.Utf8Name))
|
||||
return;
|
||||
|
||||
var profile = _profileManager.GetActiveProfileByActor(actor);
|
||||
if (profile == null) //safety check
|
||||
return;
|
||||
|
||||
if (!profile.Templates.Contains(template!))
|
||||
return;
|
||||
|
||||
ICharacter? localPlayerCharacter = (ICharacter?)_gameObjectService.GetDalamudGameObjectFromActor(actor);
|
||||
if (localPlayerCharacter == null)
|
||||
return;
|
||||
|
||||
OnProfileUpdateInternal(localPlayerCharacter, profile);
|
||||
}
|
||||
|
||||
//warn: intended limitation - ignores default profiles because why you would use default profile on your own character
|
||||
private void OnArmatureChanged(ArmatureChanged.Type type, Armature armature, object? arg3)
|
||||
{
|
||||
|
||||
@@ -4,6 +4,8 @@ using CustomizePlus.Game.Services;
|
||||
using CustomizePlus.GameData.Services;
|
||||
using CustomizePlus.Profiles;
|
||||
using CustomizePlus.Profiles.Events;
|
||||
using CustomizePlus.Templates.Data;
|
||||
using CustomizePlus.Templates.Events;
|
||||
using Dalamud.Plugin;
|
||||
using ECommonsLite.EzIpcManager;
|
||||
using OtterGui.Log;
|
||||
@@ -29,6 +31,7 @@ public partial class CustomizePlusIpc : IDisposable
|
||||
private readonly CutsceneService _cutsceneService;
|
||||
|
||||
private readonly ArmatureChanged _armatureChangedEvent;
|
||||
private readonly TemplateChanged _templateChangedEvent;
|
||||
|
||||
/// <summary>
|
||||
/// Shows if IPC failed to initialize or any other unrecoverable fatal error occured.
|
||||
@@ -43,7 +46,8 @@ public partial class CustomizePlusIpc : IDisposable
|
||||
GameObjectService gameObjectService,
|
||||
ProfileFileSystem profileFileSystem,
|
||||
CutsceneService cutsceneService,
|
||||
ArmatureChanged armatureChangedEvent)
|
||||
ArmatureChanged armatureChangedEvent,
|
||||
TemplateChanged templateChangedEvent)
|
||||
{
|
||||
_pluginInterface = pluginInterface;
|
||||
_logger = logger;
|
||||
@@ -54,14 +58,17 @@ public partial class CustomizePlusIpc : IDisposable
|
||||
_cutsceneService = cutsceneService;
|
||||
|
||||
_armatureChangedEvent = armatureChangedEvent;
|
||||
_templateChangedEvent = templateChangedEvent;
|
||||
|
||||
EzIPC.Init(this, "CustomizePlus");
|
||||
|
||||
_armatureChangedEvent.Subscribe(OnArmatureChanged, ArmatureChanged.Priority.CustomizePlusIpc);
|
||||
_templateChangedEvent.Subscribe(OnTemplateChanged, TemplateChanged.Priority.CustomizePlusIpc);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_armatureChangedEvent.Unsubscribe(OnArmatureChanged);
|
||||
_templateChangedEvent.Unsubscribe(OnTemplateChanged);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user