Skip to content

Commit b38063d

Browse files
committed
feat(PoolEnergyIconPatches): implement unmapped content warnings for cards, relics, and potions
- Added functionality to log warnings for unmapped cards, relics, and potions that are registered in ModelDb but not included in any respective pool. - Introduced a locking mechanism to prevent duplicate warnings for the same content, enhancing the clarity of the logging process. - Refactored pool retrieval logic to improve maintainability and readability.
1 parent 2035239 commit b38063d

1 file changed

Lines changed: 58 additions & 3 deletions

File tree

Scaffolding/Content/Patches/PoolEnergyIconPatches.cs

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ public static bool Prefix(string prefix, ref string __result)
6262

6363
internal static class ModBigEnergyIconHelper
6464
{
65+
private static readonly Lock UnmappedContentWarningGate = new();
66+
private static readonly HashSet<string> UnmappedContentWarningLoggedKeys = new(StringComparer.Ordinal);
6567
private static Dictionary<string, string>? _cache;
6668

6769
public static bool TryOverridePath(string prefix, ref string result)
@@ -82,18 +84,71 @@ private static Dictionary<string, string> BuildCache()
8284
foreach (var character in ModContentRegistry.GetModCharacters())
8385
AddPoolIfMapped(dict, character.CardPool);
8486

85-
foreach (var pool in ModelDb.AllCards.Select(c => c.Pool).Distinct())
87+
var cardPools = ModelDb.AllCardPools.ToArray();
88+
foreach (var pool in cardPools)
8689
AddPoolIfMapped(dict, pool);
90+
WarnUnmappedCards(cardPools);
8791

88-
foreach (var pool in ModelDb.AllRelics.Select(r => r.Pool).Distinct())
92+
var relicPools = ModelDb.AllRelicPools.ToArray();
93+
foreach (var pool in relicPools)
8994
AddPoolIfMapped(dict, pool);
95+
WarnUnmappedRelics(relicPools);
9096

91-
foreach (var pool in ModelDb.AllPotions.Select(p => p.Pool).Distinct())
97+
var potionPools = ModelDb.AllPotionPools.ToArray();
98+
foreach (var pool in potionPools)
9299
AddPoolIfMapped(dict, pool);
100+
WarnUnmappedPotions(potionPools);
93101

94102
return dict;
95103
}
96104

105+
private static void WarnUnmappedCards(CardPoolModel[] pools)
106+
{
107+
foreach (var card in ModelDb.AllCards)
108+
{
109+
if (pools.Any(pool => pool.AllCardIds.Contains(card.Id)))
110+
continue;
111+
112+
WarnUnmappedContentOnce("card", card.Id);
113+
}
114+
}
115+
116+
private static void WarnUnmappedRelics(RelicPoolModel[] pools)
117+
{
118+
foreach (var relic in ModelDb.AllRelics)
119+
{
120+
if (pools.Any(pool => pool.AllRelicIds.Contains(relic.Id)))
121+
continue;
122+
123+
WarnUnmappedContentOnce("relic", relic.Id);
124+
}
125+
}
126+
127+
private static void WarnUnmappedPotions(PotionPoolModel[] pools)
128+
{
129+
foreach (var potion in ModelDb.AllPotions)
130+
{
131+
if (pools.Any(pool => pool.AllPotionIds.Contains(potion.Id)))
132+
continue;
133+
134+
WarnUnmappedContentOnce("potion", potion.Id);
135+
}
136+
}
137+
138+
private static void WarnUnmappedContentOnce(string contentType, ModelId id)
139+
{
140+
var key = contentType + "\0" + id;
141+
lock (UnmappedContentWarningGate)
142+
{
143+
if (!UnmappedContentWarningLoggedKeys.Add(key))
144+
return;
145+
}
146+
147+
RitsuLibFramework.Logger.Warn(
148+
$"[Content] {contentType} '{id}' is registered in ModelDb but is not contained in any {contentType} pool. " +
149+
"Skipping it while building energy icon overrides.");
150+
}
151+
97152
private static void AddPoolIfMapped(Dictionary<string, string> dict, IPoolModel pool)
98153
{
99154
if (pool is not IModBigEnergyIconPool mapped)

0 commit comments

Comments
 (0)