Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion ShowCraftable/ShowCraftable/ShowCraftableModSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public class ShowCraftableSystem : ModSystem
private static List<string> s_EmptyPages;
private static List<string> StoneTypeTabCache = new();
private static List<string> WoodTypeTabCache = new();
private static readonly Dictionary<string, bool> TabCachePrimed = new(StringComparer.Ordinal);
private static List<WildGroup> wildcardGroups = new();
private static readonly Dictionary<int, ScanRequestInfo> InflightById = new();
private static readonly Dictionary<string, bool> TabReadyToUpdateUi = new(StringComparer.Ordinal);
Expand Down Expand Up @@ -564,6 +565,8 @@ private static void SetTabCache(string tabKey, IEnumerable<string> pages)
else if (string.Equals(tabKey, WoodTabKeyName, StringComparison.Ordinal)) WoodTypeTabCache = list;
else if (string.Equals(tabKey, StoneTabKeyName, StringComparison.Ordinal)) StoneTypeTabCache = list;
else CraftableTabCache = list;

TabCachePrimed[tabKey] = true;
}

private static List<string> GetTabCacheSnapshot(string tabKey)
Expand Down Expand Up @@ -2572,6 +2575,7 @@ private static void ClearAllCaches()
StoneTypeTabCache = new List<string>();
WoodTypeTabCache = new List<string>();
s_EmptyPages = null;
TabCachePrimed.Clear();
}

recipeGroupNeeds = new Dictionary<GridRecipeShim, Dictionary<string, int>>();
Expand Down Expand Up @@ -4145,14 +4149,16 @@ private void OnServerScanReply(CraftScanReply data)
}

int cachedPages;
bool cachePrimed;
lock (CacheLock)
{
var cache = GetTabCache(tabKey);
cachedPages = cache?.Count ?? 0;
cachePrimed = TabCachePrimed.TryGetValue(tabKey, out var primed) && primed;
}
bool cacheEmpty = cachedPages == 0;

if (dnaMatch && !cacheEmpty)
if (dnaMatch && (cachePrimed || !cacheEmpty))
{
SetTabReadyToUpdateUI(tabKey, true);
_capi.Event.EnqueueMainThreadTask(() =>
Expand Down