Hopefully fix issue with missing caches.

This commit is contained in:
Ottermandias 2023-04-29 15:49:33 +02:00
parent c2933ba95c
commit 3d5765796e
4 changed files with 10 additions and 5 deletions

View file

@ -51,6 +51,7 @@ public class CollectionCacheManager : IDisposable
_communicator.ModSettingChanged.Subscribe(OnModSettingChange); _communicator.ModSettingChanged.Subscribe(OnModSettingChange);
_communicator.CollectionInheritanceChanged.Subscribe(OnCollectionInheritanceChange); _communicator.CollectionInheritanceChanged.Subscribe(OnCollectionInheritanceChange);
CreateNecessaryCaches(); CreateNecessaryCaches();
_active.Individuals.Loaded += CreateNecessaryCaches;
if (!MetaFileManager.CharacterUtility.Ready) if (!MetaFileManager.CharacterUtility.Ready)
MetaFileManager.CharacterUtility.LoadingFinished += IncrementCounters; MetaFileManager.CharacterUtility.LoadingFinished += IncrementCounters;

View file

@ -47,6 +47,7 @@ public class ActiveCollections : ISavable, IDisposable
_communicator.CollectionChange.Subscribe(OnCollectionChange, -100); _communicator.CollectionChange.Subscribe(OnCollectionChange, -100);
LoadCollections(); LoadCollections();
UpdateCurrentCollectionInUse(); UpdateCurrentCollectionInUse();
Individuals.Loaded += UpdateCurrentCollectionInUse;
} }
public void Dispose() public void Dispose()
@ -275,7 +276,7 @@ public class ActiveCollections : ISavable, IDisposable
jObj.WriteTo(j); jObj.WriteTo(j);
} }
public void UpdateCurrentCollectionInUse() private void UpdateCurrentCollectionInUse()
=> CurrentCollectionInUse = SpecialCollections => CurrentCollectionInUse = SpecialCollections
.OfType<ModCollection>() .OfType<ModCollection>()
.Prepend(Interface) .Prepend(Interface)

View file

@ -34,7 +34,7 @@ public partial class IndividualCollections
{ {
if (ReadJObjectInternal(obj, storage)) if (ReadJObjectInternal(obj, storage))
saver.ImmediateSave(parent); saver.ImmediateSave(parent);
parent.UpdateCurrentCollectionInUse(); Loaded?.Invoke();
_actorService.FinishedCreation -= Func; _actorService.FinishedCreation -= Func;
} }
_actorService.FinishedCreation += Func; _actorService.FinishedCreation += Func;

View file

@ -17,6 +17,8 @@ public sealed partial class IndividualCollections
private readonly List<(string DisplayName, IReadOnlyList<ActorIdentifier> Identifiers, ModCollection Collection)> _assignments = new(); private readonly List<(string DisplayName, IReadOnlyList<ActorIdentifier> Identifiers, ModCollection Collection)> _assignments = new();
private readonly Dictionary<ActorIdentifier, ModCollection> _individuals = new(); private readonly Dictionary<ActorIdentifier, ModCollection> _individuals = new();
public event Action? Loaded;
public IReadOnlyList<(string DisplayName, IReadOnlyList<ActorIdentifier> Identifiers, ModCollection Collection)> Assignments public IReadOnlyList<(string DisplayName, IReadOnlyList<ActorIdentifier> Identifiers, ModCollection Collection)> Assignments
=> _assignments; => _assignments;
@ -95,7 +97,7 @@ public sealed partial class IndividualCollections
case IdentifierType.Owned: case IdentifierType.Owned:
if (!ByteString.FromString(name, out var ownerName)) if (!ByteString.FromString(name, out var ownerName))
return AddResult.Invalid; return AddResult.Invalid;
identifiers = dataIds.Select(id => manager.CreateOwned(ownerName, homeWorld, kind, id)).ToArray(); identifiers = dataIds.Select(id => manager.CreateOwned(ownerName, homeWorld, kind, id)).ToArray();
break; break;
case IdentifierType.Npc: case IdentifierType.Npc:
@ -242,8 +244,9 @@ public sealed partial class IndividualCollections
IdentifierType.Retainer => $"{identifier.PlayerName} (Retainer)", IdentifierType.Retainer => $"{identifier.PlayerName} (Retainer)",
IdentifierType.Owned => IdentifierType.Owned =>
$"{identifier.PlayerName} ({_actorService.AwaitedService.Data.ToWorldName(identifier.HomeWorld)})'s {_actorService.AwaitedService.Data.ToName(identifier.Kind, identifier.DataId)}", $"{identifier.PlayerName} ({_actorService.AwaitedService.Data.ToWorldName(identifier.HomeWorld)})'s {_actorService.AwaitedService.Data.ToName(identifier.Kind, identifier.DataId)}",
IdentifierType.Npc => $"{_actorService.AwaitedService.Data.ToName(identifier.Kind, identifier.DataId)} ({identifier.Kind.ToName()})", IdentifierType.Npc =>
_ => string.Empty, $"{_actorService.AwaitedService.Data.ToName(identifier.Kind, identifier.DataId)} ({identifier.Kind.ToName()})",
_ => string.Empty,
}; };
} }
} }