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
11 files changed
+365 -363

No files matched your search

+5 -4
View File
@@ -56,12 +56,13 @@ namespace Cthangover.Core.Factories.Impls
/// </summary>
private Dictionary<string, ActionCharacterInfo> EnsureInfos()
{
if (_allInfos != null)
return _allInfos;
// The resolver's dictionary identity is the data snapshot (see CharacterFactory.EnsureInfos).
var infos = Entities.Collect<ActionCharacterInfo>();
if (ModManager.Instance.IsInitialized)
if (!ReferenceEquals(infos, _allInfos))
{
_allInfos = infos;
_cache.Clear();
}
return infos;
}
+30 -30
View File
@@ -1,30 +1,30 @@
using Cthangover.Core.Factories;
using Cthangover.Core.Utils;
using Godot;
namespace Cthangover.Core.Factories.Impls
{
/// <summary>
/// Thin <c>Texture2DFactory</c> for character portrait avatars. The
/// separate factory (as opposed to reusing <c>UITextureFactory</c>)
/// isolates avatar images into their own mod group with a dedicated
/// cache budget, so frequently-swapped dialog portraits don't evict
/// other UI textures under memory pressure.
/// <para/>
/// The factory lives in the characters engine mod; its singleton is also
/// published to the kernel through <see cref="AvatarProviderRegistry"/> by
/// <c>CharactersModInitializer</c>, so core-side consumers resolve
/// avatars without referencing this assembly.
/// </summary>
public class AvatarFactory : Texture2DFactory, IAvatarProvider
{
internal AvatarFactory() : base("avatars", 64) { }
/// <summary>Process-wide singleton for this mod assembly; the public API for avatar lookups.</summary>
public static AvatarFactory Instance { get; } = new AvatarFactory();
/// <summary>Mod asset group scanned by this factory — files live under <c>mods/*/</c><b>avatars</b>.</summary>
public override string GroupName => "avatars";
}
}
using Cthangover.Core.Factories;
using Cthangover.Core.Utils;
using Godot;
namespace Cthangover.Core.Factories.Impls
{
/// <summary>
/// Thin <c>Texture2DFactory</c> for character portrait avatars. The
/// separate factory (as opposed to reusing <c>UITextureFactory</c>)
/// isolates avatar images into their own mod group with a dedicated
/// cache budget, so frequently-swapped dialog portraits don't evict
/// other UI textures under memory pressure.
/// <para/>
/// The factory lives in the characters engine mod; its singleton is also
/// published to the kernel through <see cref="AvatarProviderRegistry"/> by
/// <c>CharactersModInitializer</c>, so core-side consumers resolve
/// avatars without referencing this assembly.
/// </summary>
public class AvatarFactory : Texture2DFactory, IAvatarProvider
{
internal AvatarFactory() : base("avatars", 64) { }
/// <summary>Process-wide singleton for this mod assembly; the public API for avatar lookups.</summary>
public static AvatarFactory Instance { get; } = new AvatarFactory();
/// <summary>Mod asset group scanned by this factory — files live under <c>mods/*/</c><b>avatars</b>.</summary>
public override string GroupName => "avatars";
}
}
+9 -8
View File
@@ -64,16 +64,17 @@ namespace Cthangover.Core.Factories.Impls
/// </summary>
private Dictionary<string, CharacterInfo> EnsureInfos()
{
if (_allInfos != null)
return _allInfos;
GameLogger.Log("FACTORY", $"CharacterFactory.EnsureInfos: START, ModRegistry.IsInitialized={ModRegistry.Instance.IsInitialized}, mods count={ModRegistry.Instance.Mods?.Count ?? 0}", LogLevel.Debug);
// Entities.Collect is cached by the entity resolver until the next
// mod reload, so its dictionary identity is the data snapshot: a new
// one (reload, data edit, game switch with this mod kept) drops the
// built templates instead of serving the previous mod set's data.
var infos = Entities.Collect<CharacterInfo>();
if (ModManager.Instance.IsInitialized)
_allInfos = infos;
if (ReferenceEquals(infos, _allInfos))
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;
}