Fix DefaultLocalPlayerProfile and DefaultProfile conflicting, fix commands, bump IPC version, send Profile.OnUpdate for DefaultProfile and DefaultLocalPlayerProfile

This commit is contained in:
RisaDev
2024-10-19 23:06:48 +03:00
parent 93802e6115
commit 74cf737102
6 changed files with 39 additions and 40 deletions

View File

@@ -4,7 +4,7 @@ namespace CustomizePlus.Api;
public partial class CustomizePlusIpc
{
private readonly (int Breaking, int Feature) _apiVersion = (5, 1);
private readonly (int Breaking, int Feature) _apiVersion = (5, 2);
/// <summary>
/// When there are breaking changes the first number is bumped up and second one is reset.

View File

@@ -283,24 +283,12 @@ public partial class CustomizePlusIpc
else
(activeProfile, oldProfile) = ((Profile?, Profile?))arg3;
if (activeProfile != null)
{
if (activeProfile == _profileManager.DefaultProfile || activeProfile.ProfileType == ProfileType.Editor)
{
//ignore any changes while player is in editor or if player changes between default profiles
//also do not send event if there were no active profile before
if (activeProfile == oldProfile || oldProfile == null)
//do not send event if we are entering editor
if (activeProfile != null && activeProfile.ProfileType == ProfileType.Editor)
return;
OnProfileUpdateInternal(localPlayerCharacter, null); //send empty profile when player enters editor or turns on default profile
return;
}
}
//do not send event if we are exiting editor or disabling default profile and don't have any active profile
if (oldProfile != null &&
(oldProfile == _profileManager.DefaultProfile || oldProfile.ProfileType == ProfileType.Editor) &&
activeProfile == null)
//do not send event if we are exiting editor
if (oldProfile != null && oldProfile.ProfileType == ProfileType.Editor)
return;
OnProfileUpdateInternal(localPlayerCharacter, activeProfile);
@@ -309,8 +297,9 @@ public partial class CustomizePlusIpc
if (type == ArmatureChanged.Type.Deleted)
{
//Do not send event if default or editor profile was used
if (armature.Profile == _profileManager.DefaultProfile || armature.Profile.ProfileType == ProfileType.Editor) //todo: never send if ProfileType != normal?
//Do not send event if editor profile was used
//todo: never send if ProfileType != normal?
if (armature.Profile.ProfileType == ProfileType.Editor)
return;
OnProfileUpdateInternal(localPlayerCharacter, null);

View File

@@ -464,15 +464,17 @@ public unsafe sealed class ArmatureManager : IDisposable
if (!profile.Enabled && profile.Armatures.Count == 0)
return;
if (profile == _profileManager.DefaultProfile)
if (profile == _profileManager.DefaultProfile ||
profile == _profileManager.DefaultLocalPlayerProfile)
{
foreach (var kvPair in Armatures)
{
var armature = kvPair.Value;
if (armature.Profile == profile)
if (armature.Profile == _profileManager.DefaultProfile || //not the best solution but w/e
armature.Profile == _profileManager.DefaultLocalPlayerProfile)
armature.IsPendingProfileRebind = true;
_logger.Debug($"ArmatureManager.OnProfileChange default profile toggled, planning rebind for armature {armature}");
_logger.Debug($"ArmatureManager.OnProfileChange default/default local player profile toggled, planning rebind for armature {armature}");
}
return;

View File

@@ -14,6 +14,8 @@ using CustomizePlus.Profiles.Data;
using CustomizePlus.Configuration.Data;
using Dalamud.Interface.ImGuiNotification;
using CustomizePlus.GameData.Extensions;
using System.Collections.Generic;
using ECommons;
namespace CustomizePlus.Core.Services;
@@ -168,8 +170,8 @@ public class CommandService : IDisposable
break;
}
//todo: support for multiple profiles
Profile? targetProfile = null;
List<Profile> profilesToDisable = new List<Profile>(_profileManager.Profiles.Count);
characterName = subArgumentList[0].Trim();
characterName = characterName switch
@@ -184,12 +186,24 @@ public class CommandService : IDisposable
if (!isTurningOffAllProfiles)
{
profileName = subArgumentList[1].Trim();
targetProfile = _profileManager.Profiles.FirstOrDefault(x => x.Name == profileName && x.Characters.Any(x => x.ToNameWithoutOwnerName() == characterName));
foreach(var profile in _profileManager.Profiles)
{
if (!profile.Characters.Any(x => x.ToNameWithoutOwnerName() == characterName))
continue;
if (profile.Name != profileName)
{
profilesToDisable.Add(profile);
continue;
}
targetProfile = profile;
}
}
else
targetProfile = _profileManager.Profiles.FirstOrDefault(x => x.Characters.Any(x => x.ToNameWithoutOwnerName() == characterName) && x.Enabled);
profilesToDisable = _profileManager.Profiles.Where(x => x.Characters.Any(x => x.ToNameWithoutOwnerName() == characterName) && x.Enabled).ToList();
if (targetProfile == null)
if (targetProfile == null || (isTurningOffAllProfiles && profilesToDisable.Count == 0))
{
_chatService.PrintInChat(new SeStringBuilder()
.AddText("Cannot execute command because profile ")
@@ -219,6 +233,12 @@ public class CommandService : IDisposable
else
_profileManager.SetEnabled(targetProfile, !targetProfile.Enabled);
if(targetProfile.Enabled)
{
foreach (var profile in profilesToDisable)
_profileManager.SetEnabled(profile, false);
}
if (_pluginConfiguration.CommandSettings.PrintSuccessMessages)
_chatService.PrintInChat(new SeStringBuilder()
.AddText("Profile ")

View File

@@ -61,6 +61,7 @@ public class SupportLogBuilderService
}
sb.AppendLine("**Profiles**");
sb.Append($"> **`Default profile: `** {_profileManager.DefaultProfile?.ToString() ?? "None"}\n");
sb.Append($"> **`Default local player profile: `** {_profileManager.DefaultLocalPlayerProfile?.ToString() ?? "None"}\n");
sb.Append($"> **`Count: `** {_profileManager.Profiles.Count}\n");
foreach (var profile in _profileManager.Profiles)
{

View File

@@ -186,10 +186,6 @@ public partial class ProfileManager : IDisposable
profile.Characters.Add(actorIdentifier);
//Called so all other active profiles for new character name get disabled
//saving is performed there
//SetEnabled(profile, profile.Enabled, true); //todo
SaveProfile(profile);
_logger.Debug($"Add character for profile {profile.UniqueId}.");
@@ -206,10 +202,6 @@ public partial class ProfileManager : IDisposable
profile.Characters.Remove(actorIdentifier);
//Called so all other active profiles for new character name get disabled
//saving is performed there
//SetEnabled(profile, profile.Enabled, true); //todo
SaveProfile(profile);
_logger.Debug($"Removed character from profile {profile.UniqueId}.");
@@ -479,11 +471,6 @@ public partial class ProfileManager : IDisposable
if (!actorIdentifier.IsValid)
yield break;
var name = actorIdentifier.ToNameWithoutOwnerName();
if (name.IsNullOrWhitespace())
yield break;
bool IsProfileAppliesToCurrentActor(Profile profile)
{
//default profile check is done later