Character factories follow mod reloads

This commit is contained in:
cthangover committed 2026-10-21 12:31:48 +02:00
1 parent 734169db3d
commit 3afa3a6a80
2 files changed
+14 -12

No files matched your search

+5 -4
View File
@@ -56,12 +56,13 @@ namespace Cthangover.Core.Factories.Impls
/// </summary> /// </summary>
private Dictionary<string, ActionCharacterInfo> EnsureInfos() private Dictionary<string, ActionCharacterInfo> EnsureInfos()
{ {
if (_allInfos != null) // The resolver's dictionary identity is the data snapshot (see CharacterFactory.EnsureInfos).
return _allInfos;
var infos = Entities.Collect<ActionCharacterInfo>(); var infos = Entities.Collect<ActionCharacterInfo>();
if (ModManager.Instance.IsInitialized) if (!ReferenceEquals(infos, _allInfos))
{
_allInfos = infos; _allInfos = infos;
_cache.Clear();
}
return infos; return infos;
} }
+9 -8
View File
@@ -64,16 +64,17 @@ namespace Cthangover.Core.Factories.Impls
/// </summary> /// </summary>
private Dictionary<string, CharacterInfo> EnsureInfos() private Dictionary<string, CharacterInfo> EnsureInfos()
{ {
if (_allInfos != null) // Entities.Collect is cached by the entity resolver until the next
return _allInfos; // mod reload, so its dictionary identity is the data snapshot: a new
// one (reload, data edit, game switch with this mod kept) drops the
GameLogger.Log("FACTORY", $"CharacterFactory.EnsureInfos: START, ModRegistry.IsInitialized={ModRegistry.Instance.IsInitialized}, mods count={ModRegistry.Instance.Mods?.Count ?? 0}", LogLevel.Debug); // built templates instead of serving the previous mod set's data.
var infos = Entities.Collect<CharacterInfo>(); var infos = Entities.Collect<CharacterInfo>();
if (ModManager.Instance.IsInitialized) if (ReferenceEquals(infos, _allInfos))
_allInfos = infos; return infos;
GameLogger.Log("FACTORY", $"CharacterFactory.EnsureInfos: END, loaded {infos?.Count ?? 0} infos", LogLevel.Debug); _allInfos = infos;
_cache.Clear();
GameLogger.Log("FACTORY", $"CharacterFactory.EnsureInfos: {infos?.Count ?? 0} infos (new data snapshot)", LogLevel.Debug);
return infos; return infos;
} }