Skip to content

Commit

Permalink
Special actor fixes
Browse files Browse the repository at this point in the history
Remove special actor armatures without waiting (fixes incorrect profile when changing examined character without closing the window)
Fix for special actor armatures not reflecting changes in active profiles
Slight refactoring
  • Loading branch information
RisaDev committed Apr 10, 2024
1 parent 076460f commit 933eb27
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 31 deletions.
29 changes: 10 additions & 19 deletions CustomizePlus/Armatures/Services/ArmatureManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,10 @@ private void RefreshArmatures()
foreach (var kvPair in Armatures.ToList())
{
var armature = kvPair.Value;
//Only remove armatures which haven't been seen for a while
//But remove armatures of special actors (like examine screen) right away
if (!_objectManager.ContainsKey(kvPair.Value.ActorIdentifier) &&
armature.LastSeen <= armatureExpirationDateTime) //Only remove armatures which haven't been seen for a while
(armature.LastSeen <= armatureExpirationDateTime || armature.ActorIdentifier.Type == IdentifierType.Special))
{
_logger.Debug($"Removing armature {armature} because {kvPair.Key.IncognitoDebug()} is gone");
RemoveArmature(armature, ArmatureChanged.DeletionReason.Gone);
Expand All @@ -124,27 +126,12 @@ private void RefreshArmatures()
armature.IsVisible = armature.LastSeen.AddSeconds(1) >= currentTime;
}

Profile? GetProfileForActor(ActorIdentifier identifier)
{
foreach (var profile in _profileManager.GetEnabledProfilesByActor(identifier))
{
if (profile.LimitLookupToOwnedObjects &&
(identifier.Type != IdentifierType.Owned ||
identifier.PlayerName != _objectManager.PlayerData.Identifier.PlayerName))
continue;

return profile;
}

return null;
}

foreach (var obj in _objectManager.Identifiers)
{
var actorIdentifier = obj.Key.CreatePermanent();
if (!Armatures.ContainsKey(actorIdentifier))
{
var activeProfile = GetProfileForActor(actorIdentifier);
var activeProfile = _profileManager.GetEnabledProfilesByActor(actorIdentifier).FirstOrDefault();
if (activeProfile == null)
continue;

Expand All @@ -166,7 +153,7 @@ private void RefreshArmatures()
_logger.Debug($"Armature {armature} is pending profile/bone rebind, rebinding...");
armature.IsPendingProfileRebind = false;

var activeProfile = GetProfileForActor(actorIdentifier);
var activeProfile = _profileManager.GetEnabledProfilesByActor(actorIdentifier).FirstOrDefault();
Profile? oldProfile = armature.Profile;
if (activeProfile != armature.Profile)
{
Expand Down Expand Up @@ -555,7 +542,11 @@ private IEnumerable<Armature> GetArmaturesForCharacterName(string characterName)
{
foreach(var kvPair in Armatures)
{
if(kvPair.Key.ToNameWithoutOwnerName() == characterName)
var actorIdentifier = kvPair.Key;
if (actorIdentifier.Type == IdentifierType.Special)
actorIdentifier = actorIdentifier.GetTrueActorForSpecialType();

if(actorIdentifier.ToNameWithoutOwnerName() == characterName)
yield return kvPair.Value;
}
}
Expand Down
22 changes: 11 additions & 11 deletions CustomizePlus/Profiles/ProfileManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
using CustomizePlus.Profiles.Exceptions;
using Penumbra.GameData.Enums;
using Penumbra.GameData.Interop;
using System.Runtime.Serialization;

namespace CustomizePlus.Profiles;

Expand Down Expand Up @@ -487,17 +488,21 @@ public IEnumerable<Profile> GetEnabledProfilesByActor(ActorIdentifier actorIdent
if (name.IsNullOrWhitespace())
yield break;

if (_templateEditorManager.IsEditorActive && _templateEditorManager.EditorProfile.Enabled)
bool IsProfileAppliesToCurrentActor(Profile profile)
{
if (ProfileAppliesTo(_templateEditorManager.EditorProfile, name))
{
yield return _templateEditorManager.EditorProfile;
}
return profile.CharacterName.Text == name &&
(!profile.LimitLookupToOwnedObjects ||
(actorIdentifier.Type == IdentifierType.Owned &&
actorIdentifier.PlayerName != _actorManager.GetCurrentPlayer().PlayerName));
}


if (_templateEditorManager.IsEditorActive && _templateEditorManager.EditorProfile.Enabled && IsProfileAppliesToCurrentActor(_templateEditorManager.EditorProfile))
yield return _templateEditorManager.EditorProfile;

foreach (var profile in Profiles)
{
if (ProfileAppliesTo(profile, name) && profile.Enabled)
if (IsProfileAppliesToCurrentActor(profile) && profile.Enabled)
yield return profile;
}

Expand All @@ -520,11 +525,6 @@ public IEnumerable<Profile> GetProfilesUsingTemplate(Template template)
yield return _templateEditorManager.EditorProfile;
}

/// <summary>
/// Returns whether or not profile applies to the object with the indicated name.
/// </summary>
public bool ProfileAppliesTo(Profile profile, string objectName) => !string.IsNullOrWhiteSpace(objectName) && objectName == profile.CharacterName.Text;

private void SaveProfile(Profile profile)
{
//disallow saving special profiles
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private void DrawObjectManager()
continue;

ImGui.Text($"ActorIdentifier");
ImGui.Text($"PlayerName: {kvPair.Key.PlayerName}");
ImGui.Text($"PlayerName: {kvPair.Key.PlayerName.ToString()}");
ImGui.Text($"HomeWorld: {kvPair.Key.HomeWorld}");
ImGui.Text($"Retainer: {kvPair.Key.Retainer}");
ImGui.Text($"Kind: {kvPair.Key.Kind}");
Expand All @@ -106,6 +106,8 @@ private void DrawObjectManager()
ImGui.Text($"Special: {kvPair.Key.Special.ToString()}");
ImGui.Text($"ToName: {kvPair.Key.ToName()}");
ImGui.Text($"ToNameWithoutOwnerName: {kvPair.Key.ToNameWithoutOwnerName()}");
if(kvPair.Key.Type == Penumbra.GameData.Enums.IdentifierType.Special)
ImGui.Text($"True actor: {kvPair.Key.GetTrueActorForSpecialType().ToName()}");

ImGui.Spacing();
ImGui.Spacing();
Expand Down

0 comments on commit 933eb27

Please sign in to comment.