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 public partial class CustomizePlusIpc
{ {
private readonly (int Breaking, int Feature) _apiVersion = (5, 1); private readonly (int Breaking, int Feature) _apiVersion = (5, 2);
/// <summary> /// <summary>
/// When there are breaking changes the first number is bumped up and second one is reset. /// 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 else
(activeProfile, oldProfile) = ((Profile?, Profile?))arg3; (activeProfile, oldProfile) = ((Profile?, Profile?))arg3;
if (activeProfile != null) //do not send event if we are entering editor
{ if (activeProfile != null && activeProfile.ProfileType == ProfileType.Editor)
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)
return; return;
OnProfileUpdateInternal(localPlayerCharacter, null); //send empty profile when player enters editor or turns on default profile //do not send event if we are exiting editor
return; if (oldProfile != null && oldProfile.ProfileType == ProfileType.Editor)
}
}
//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)
return; return;
OnProfileUpdateInternal(localPlayerCharacter, activeProfile); OnProfileUpdateInternal(localPlayerCharacter, activeProfile);
@@ -309,8 +297,9 @@ public partial class CustomizePlusIpc
if (type == ArmatureChanged.Type.Deleted) if (type == ArmatureChanged.Type.Deleted)
{ {
//Do not send event if default or editor profile was used //Do not send event if editor profile was used
if (armature.Profile == _profileManager.DefaultProfile || armature.Profile.ProfileType == ProfileType.Editor) //todo: never send if ProfileType != normal? //todo: never send if ProfileType != normal?
if (armature.Profile.ProfileType == ProfileType.Editor)
return; return;
OnProfileUpdateInternal(localPlayerCharacter, null); OnProfileUpdateInternal(localPlayerCharacter, null);

View File

@@ -464,15 +464,17 @@ public unsafe sealed class ArmatureManager : IDisposable
if (!profile.Enabled && profile.Armatures.Count == 0) if (!profile.Enabled && profile.Armatures.Count == 0)
return; return;
if (profile == _profileManager.DefaultProfile) if (profile == _profileManager.DefaultProfile ||
profile == _profileManager.DefaultLocalPlayerProfile)
{ {
foreach (var kvPair in Armatures) foreach (var kvPair in Armatures)
{ {
var armature = kvPair.Value; 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; 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; return;

View File

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

View File

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

View File

@@ -186,10 +186,6 @@ public partial class ProfileManager : IDisposable
profile.Characters.Add(actorIdentifier); 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); SaveProfile(profile);
_logger.Debug($"Add character for profile {profile.UniqueId}."); _logger.Debug($"Add character for profile {profile.UniqueId}.");
@@ -206,10 +202,6 @@ public partial class ProfileManager : IDisposable
profile.Characters.Remove(actorIdentifier); 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); SaveProfile(profile);
_logger.Debug($"Removed character from profile {profile.UniqueId}."); _logger.Debug($"Removed character from profile {profile.UniqueId}.");
@@ -479,11 +471,6 @@ public partial class ProfileManager : IDisposable
if (!actorIdentifier.IsValid) if (!actorIdentifier.IsValid)
yield break; yield break;
var name = actorIdentifier.ToNameWithoutOwnerName();
if (name.IsNullOrWhitespace())
yield break;
bool IsProfileAppliesToCurrentActor(Profile profile) bool IsProfileAppliesToCurrentActor(Profile profile)
{ {
//default profile check is done later //default profile check is done later