Rename CompareIgnoringOwnership and FindActorsByIdentifier

This commit is contained in:
RisaDev
2024-10-18 21:34:35 +03:00
parent 80e87a821d
commit 3e290cbabc
8 changed files with 22 additions and 16 deletions

View File

@@ -29,9 +29,9 @@ public static class ActorIdentifierExtensions
} }
/// <summary> /// <summary>
/// Compares two actor identifiers while ignoring ownership for owned objects. For all other identifier types will use Matches() method. /// Matches() method but ignoring ownership for owned objects.
/// </summary> /// </summary>
public static bool CompareIgnoringOwnership(this ActorIdentifier identifier, ActorIdentifier other) public static bool MatchesIgnoringOwnership(this ActorIdentifier identifier, ActorIdentifier other)
{ {
if (identifier.Type != other.Type) if (identifier.Type != other.Type)
return false; return false;

View File

@@ -261,7 +261,7 @@ public partial class CustomizePlusIpc
//warn: intended limitation - ignores default profiles because why you would use default profile on your own character //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) private void OnArmatureChanged(ArmatureChanged.Type type, Armature armature, object? arg3)
{ {
if (!armature.ActorIdentifier.CompareIgnoringOwnership(_gameObjectService.GetCurrentPlayerActorIdentifier())) if (armature.ActorIdentifier != _gameObjectService.GetCurrentPlayerActorIdentifier())
return; return;
if (armature.ActorIdentifier.HomeWorld == WorldId.AnyWorld) //Only Cutscene/GPose actors have world set to AnyWorld if (armature.ActorIdentifier.HomeWorld == WorldId.AnyWorld) //Only Cutscene/GPose actors have world set to AnyWorld

View File

@@ -539,7 +539,7 @@ public unsafe sealed class ArmatureManager : IDisposable
{ {
(var armatureActorIdentifier, _) = _gameObjectService.GetTrueActorForSpecialTypeActor(kvPair.Key); (var armatureActorIdentifier, _) = _gameObjectService.GetTrueActorForSpecialTypeActor(kvPair.Key);
if (actorIdentifier.IsValid && armatureActorIdentifier.CompareIgnoringOwnership(actorIdentifier) && if (actorIdentifier.IsValid && armatureActorIdentifier.MatchesIgnoringOwnership(actorIdentifier) &&
(armatureActorIdentifier.Type != IdentifierType.Owned || armatureActorIdentifier.IsOwnedByLocalPlayer())) (armatureActorIdentifier.Type != IdentifierType.Owned || armatureActorIdentifier.IsOwnedByLocalPlayer()))
yield return kvPair.Value; yield return kvPair.Value;
} }

View File

@@ -32,6 +32,11 @@ public class PluginConfiguration : IPluginConfiguration, ISavable
/// </summary> /// </summary>
public Guid DefaultProfile { get; set; } = Guid.Empty; public Guid DefaultProfile { get; set; } = Guid.Empty;
/// <summary>
/// Id of the profile applied to any character user logins with. Can be set to Empty to disable this feature.
/// </summary>
public Guid DefaultLocalPlayerProfile { get; set; } = Guid.Empty;
[Serializable] [Serializable]
public class ChangelogSettingsEntries public class ChangelogSettingsEntries
{ {

View File

@@ -85,9 +85,9 @@ public class GameObjectService
} }
/// <summary> /// <summary>
/// Searches using CompareIgnoringOwnership /// Searches using MatchesIgnoringOwnership
/// </summary> /// </summary>
public IEnumerable<(ActorIdentifier, Actor)> FindActorsByIdentifier(ActorIdentifier identifier) public IEnumerable<(ActorIdentifier, Actor)> FindActorsByIdentifierIgnoringOwnership(ActorIdentifier identifier)
{ {
if (!identifier.IsValid) if (!identifier.IsValid)
yield break; yield break;
@@ -103,7 +103,7 @@ public class GameObjectService
if (!objectIdentifier.IsValid) if (!objectIdentifier.IsValid)
continue; continue;
if (identifier.CompareIgnoringOwnership(objectIdentifier)) if (identifier.MatchesIgnoringOwnership(objectIdentifier))
{ {
if (kvPair.Value.Objects.Count > 1) //in gpose we can have more than a single object for one actor if (kvPair.Value.Objects.Count > 1) //in gpose we can have more than a single object for one actor
foreach (var obj in kvPair.Value.Objects) foreach (var obj in kvPair.Value.Objects)

View File

@@ -172,7 +172,7 @@ public partial class ProfileManager : IDisposable
/// </summary> /// </summary>
public void ChangeCharacter(Profile profile, ActorIdentifier actorIdentifier) public void ChangeCharacter(Profile profile, ActorIdentifier actorIdentifier)
{ {
if (!actorIdentifier.IsValid || actorIdentifier.CompareIgnoringOwnership(profile.Character)) if (!actorIdentifier.IsValid || actorIdentifier.MatchesIgnoringOwnership(profile.Character))
return; return;
var oldCharacter = profile.Character; var oldCharacter = profile.Character;
@@ -227,7 +227,7 @@ public partial class ProfileManager : IDisposable
_logger.Debug($"Setting {profile} as enabled..."); _logger.Debug($"Setting {profile} as enabled...");
foreach (var otherProfile in Profiles foreach (var otherProfile in Profiles
.Where(x => x.Character.CompareIgnoringOwnership(profile.Character) && x != profile && x.Enabled && !x.IsTemporary)) .Where(x => x.Character.MatchesIgnoringOwnership(profile.Character) && x != profile && x.Enabled && !x.IsTemporary))
{ {
_logger.Debug($"\t-> {otherProfile} disabled"); _logger.Debug($"\t-> {otherProfile} disabled");
SetEnabled(otherProfile, false); SetEnabled(otherProfile, false);
@@ -257,6 +257,7 @@ public partial class ProfileManager : IDisposable
public void SetApplyToCurrentlyActiveCharacter(Profile profile, bool value) public void SetApplyToCurrentlyActiveCharacter(Profile profile, bool value)
{ {
//todo: only one profile is allowed to be active for that setting
if (profile.ApplyToCurrentlyActiveCharacter != value) if (profile.ApplyToCurrentlyActiveCharacter != value)
{ {
profile.ApplyToCurrentlyActiveCharacter = value; profile.ApplyToCurrentlyActiveCharacter = value;
@@ -351,7 +352,7 @@ public partial class ProfileManager : IDisposable
profile.ProfileType = ProfileType.Temporary; profile.ProfileType = ProfileType.Temporary;
profile.Character = identifier.CreatePermanent(); //warn: identifier must not be AnyWorld or stuff will break! profile.Character = identifier.CreatePermanent(); //warn: identifier must not be AnyWorld or stuff will break!
var existingProfile = Profiles.FirstOrDefault(x => x.Character.CompareIgnoringOwnership(profile.Character) && x.IsTemporary); var existingProfile = Profiles.FirstOrDefault(x => x.Character.MatchesIgnoringOwnership(profile.Character) && x.IsTemporary);
if (existingProfile != null) if (existingProfile != null)
{ {
_logger.Debug($"Temporary profile for {existingProfile.Character.Incognito(null)} already exists, removing..."); _logger.Debug($"Temporary profile for {existingProfile.Character.Incognito(null)} already exists, removing...");
@@ -409,7 +410,7 @@ public partial class ProfileManager : IDisposable
if (!actorIdentifier.IsValid) if (!actorIdentifier.IsValid)
return null; return null;
var query = Profiles.Where(x => x.Character.CompareIgnoringOwnership(actorIdentifier) && !x.IsTemporary); var query = Profiles.Where(x => x.Character.MatchesIgnoringOwnership(actorIdentifier) && !x.IsTemporary);
if (enabledOnly) if (enabledOnly)
query = query.Where(x => x.Enabled); query = query.Where(x => x.Enabled);
@@ -458,13 +459,13 @@ public partial class ProfileManager : IDisposable
return true; return true;
var currentPlayer = _actorManager.GetCurrentPlayer(); var currentPlayer = _actorManager.GetCurrentPlayer();
return currentPlayer.IsValid && currentPlayer.CompareIgnoringOwnership(actorIdentifier); return currentPlayer.IsValid && currentPlayer.MatchesIgnoringOwnership(actorIdentifier);
} }
if (actorIdentifier.Type == IdentifierType.Owned && !actorIdentifier.IsOwnedByLocalPlayer()) if (actorIdentifier.Type == IdentifierType.Owned && !actorIdentifier.IsOwnedByLocalPlayer())
return false; return false;
return profile.CharacterName.Text == name || profile.Character.CompareIgnoringOwnership(actorIdentifier); return profile.CharacterName.Text == name || profile.Character.MatchesIgnoringOwnership(actorIdentifier);
} }
if (_templateEditorManager.IsEditorActive && _templateEditorManager.EditorProfile.Enabled && IsProfileAppliesToCurrentActor(_templateEditorManager.EditorProfile)) if (_templateEditorManager.IsEditorActive && _templateEditorManager.EditorProfile.Enabled && IsProfileAppliesToCurrentActor(_templateEditorManager.EditorProfile))

View File

@@ -76,7 +76,7 @@ public class TemplateEditorManager : IDisposable
{ {
//todo: check with mounts/companions //todo: check with mounts/companions
var playerName = _gameObjectService.GetCurrentPlayerName(); var playerName = _gameObjectService.GetCurrentPlayerName();
return _gameObjectService.FindActorsByIdentifier(Character) return _gameObjectService.FindActorsByIdentifierIgnoringOwnership(Character)
.Where(x => x.Item1.Type != Penumbra.GameData.Enums.IdentifierType.Owned || x.Item1.IsOwnedByLocalPlayer()) .Where(x => x.Item1.Type != Penumbra.GameData.Enums.IdentifierType.Owned || x.Item1.IsOwnedByLocalPlayer())
.Any(); .Any();
} }

View File

@@ -240,9 +240,9 @@ public class ProfileFileSystemSelector : FileSystemSelector<Profile, ProfileStat
} }
if (leaf.Value.Enabled) if (leaf.Value.Enabled)
state.Color = leaf.Value.Character.CompareIgnoringOwnership(_gameObjectService.GetCurrentPlayerActorIdentifier()) ? ColorId.LocalCharacterEnabledProfile : ColorId.EnabledProfile; state.Color = leaf.Value.Character.MatchesIgnoringOwnership(_gameObjectService.GetCurrentPlayerActorIdentifier()) ? ColorId.LocalCharacterEnabledProfile : ColorId.EnabledProfile;
else else
state.Color = leaf.Value.Character.CompareIgnoringOwnership(_gameObjectService.GetCurrentPlayerActorIdentifier()) ? ColorId.LocalCharacterDisabledProfile : ColorId.DisabledProfile; state.Color = leaf.Value.Character.MatchesIgnoringOwnership(_gameObjectService.GetCurrentPlayerActorIdentifier()) ? ColorId.LocalCharacterDisabledProfile : ColorId.DisabledProfile;
return ApplyStringFilters(leaf, leaf.Value); return ApplyStringFilters(leaf, leaf.Value);
} }