Rewrite ApplyToCurrentlyActiveCharacter so it behaves like DefaultProfile
This commit is contained in:
@@ -33,7 +33,6 @@ public sealed class Profile : ISavable
|
||||
public LowerString CharacterName { get; set; } = LowerString.Empty;
|
||||
|
||||
public ActorIdentifier Character { get; set; } = ActorIdentifier.Invalid;
|
||||
public bool ApplyToCurrentlyActiveCharacter { get; set; }
|
||||
|
||||
public LowerString Name { get; set; } = LowerString.Empty;
|
||||
|
||||
@@ -80,7 +79,6 @@ public sealed class Profile : ISavable
|
||||
public Profile(Profile original) : this()
|
||||
{
|
||||
Character = original.Character;
|
||||
ApplyToCurrentlyActiveCharacter = original.ApplyToCurrentlyActiveCharacter;
|
||||
|
||||
foreach (var template in original.Templates)
|
||||
{
|
||||
@@ -105,7 +103,6 @@ public sealed class Profile : ISavable
|
||||
["ModifiedDate"] = ModifiedDate,
|
||||
["CharacterName"] = CharacterName.Text,
|
||||
["Character"] = Character.ToJson(),
|
||||
["ApplyToCurrentlyActiveCharacter"] = ApplyToCurrentlyActiveCharacter,
|
||||
["Name"] = Name.Text,
|
||||
["Enabled"] = Enabled,
|
||||
["IsWriteProtected"] = IsWriteProtected,
|
||||
|
||||
@@ -22,8 +22,8 @@ public sealed class ProfileChanged() : EventWrapper<ProfileChanged.Type, Profile
|
||||
ChangedTemplate,
|
||||
ReloadedAll,
|
||||
WriteProtection,
|
||||
ApplyToCurrentlyActiveCharacterChanged,
|
||||
ChangedDefaultProfile,
|
||||
ChangedDefaultLocalPlayerProfile,
|
||||
TemporaryProfileAdded,
|
||||
TemporaryProfileDeleted,
|
||||
/*
|
||||
|
||||
@@ -103,7 +103,6 @@ public partial class ProfileManager : IDisposable
|
||||
var character = _actorManager.FromJson(obj["Character"] as JObject);
|
||||
|
||||
profile.Character = character;
|
||||
profile.ApplyToCurrentlyActiveCharacter = obj["ApplyToCurrentlyActiveCharacter"]?.ToObject<bool>() ?? false;
|
||||
profile.CharacterName = new LowerString(obj["CharacterName"]?.ToObject<string>()?.Trim() ?? throw new ArgumentNullException("CharacterName")); //temp
|
||||
|
||||
return profile;
|
||||
|
||||
@@ -52,6 +52,7 @@ public partial class ProfileManager : IDisposable
|
||||
public readonly List<Profile> Profiles = new();
|
||||
|
||||
public Profile? DefaultProfile { get; private set; }
|
||||
public Profile? DefaultLocalPlayerProfile { get; private set; }
|
||||
|
||||
public ProfileManager(
|
||||
TemplateManager templateManager,
|
||||
@@ -255,19 +256,6 @@ public partial class ProfileManager : IDisposable
|
||||
throw new ProfileNotFoundException();
|
||||
}
|
||||
|
||||
public void SetApplyToCurrentlyActiveCharacter(Profile profile, bool value)
|
||||
{
|
||||
//todo: only one profile is allowed to be active for that setting
|
||||
if (profile.ApplyToCurrentlyActiveCharacter != value)
|
||||
{
|
||||
profile.ApplyToCurrentlyActiveCharacter = value;
|
||||
|
||||
SaveProfile(profile);
|
||||
|
||||
_event.Invoke(ProfileChanged.Type.ApplyToCurrentlyActiveCharacterChanged, profile, value);
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteTemplate(Profile profile, int templateIndex)
|
||||
{
|
||||
_logger.Debug($"Deleting template #{templateIndex} from {profile}...");
|
||||
@@ -342,6 +330,26 @@ public partial class ProfileManager : IDisposable
|
||||
_event.Invoke(ProfileChanged.Type.ChangedDefaultProfile, profile, previousProfile);
|
||||
}
|
||||
|
||||
public void SetDefaultLocalPlayerProfile(Profile? profile)
|
||||
{
|
||||
if (profile == null)
|
||||
{
|
||||
if (DefaultLocalPlayerProfile == null)
|
||||
return;
|
||||
}
|
||||
else if (!Profiles.Contains(profile))
|
||||
return;
|
||||
|
||||
var previousProfile = DefaultLocalPlayerProfile;
|
||||
|
||||
DefaultLocalPlayerProfile = profile;
|
||||
_configuration.DefaultLocalPlayerProfile = profile?.UniqueId ?? Guid.Empty;
|
||||
_configuration.Save();
|
||||
|
||||
_logger.Debug($"Set profile {profile?.Incognito ?? "no profile"} as default local player profile");
|
||||
_event.Invoke(ProfileChanged.Type.ChangedDefaultLocalPlayerProfile, profile, previousProfile);
|
||||
}
|
||||
|
||||
//warn: temporary profile system does not support any world identifiers
|
||||
public void AddTemporaryProfile(Profile profile, Actor actor)
|
||||
{
|
||||
@@ -453,14 +461,8 @@ public partial class ProfileManager : IDisposable
|
||||
if (profile == DefaultProfile)
|
||||
return false;
|
||||
|
||||
if (profile.ApplyToCurrentlyActiveCharacter)
|
||||
{
|
||||
if (_objectManager.IsInLobby)
|
||||
return true;
|
||||
|
||||
var currentPlayer = _actorManager.GetCurrentPlayer();
|
||||
return currentPlayer.IsValid && currentPlayer.MatchesIgnoringOwnership(actorIdentifier);
|
||||
}
|
||||
if (profile == DefaultLocalPlayerProfile)
|
||||
return false;
|
||||
|
||||
if (actorIdentifier.Type == IdentifierType.Owned && !actorIdentifier.IsOwnedByLocalPlayer())
|
||||
return false;
|
||||
@@ -489,6 +491,13 @@ public partial class ProfileManager : IDisposable
|
||||
}
|
||||
}
|
||||
|
||||
if (DefaultLocalPlayerProfile != null && DefaultLocalPlayerProfile.Enabled)
|
||||
{
|
||||
var currentPlayer = _actorManager.GetCurrentPlayer();
|
||||
if(_objectManager.IsInLobby || (currentPlayer.IsValid && currentPlayer.Matches(actorIdentifier)))
|
||||
yield return DefaultLocalPlayerProfile;
|
||||
}
|
||||
|
||||
if (DefaultProfile != null &&
|
||||
DefaultProfile.Enabled &&
|
||||
(actorIdentifier.Type == IdentifierType.Player || actorIdentifier.Type == IdentifierType.Retainer))
|
||||
|
||||
Reference in New Issue
Block a user