Skip to content

Commit

Permalink
fix: only update category tabs if needed
Browse files Browse the repository at this point in the history
  • Loading branch information
MSchmoecker committed Nov 2, 2024
1 parent dce3f59 commit 98e8a0a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## Version 2.21.3
* Fixed category tabs refreshed every frame, causing saplings to spin in the cultivator

## Version 2.21.2
* Fixed for Valheim 0.219.14 (Bog Witch), older Valheim versions are not compatible

Expand Down
20 changes: 11 additions & 9 deletions JotunnLib/Managers/PieceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,10 @@ private static class Patches
private static void Hud_Awake() => Instance.RefreshCategories();

[HarmonyPatch(typeof(Hud), nameof(Hud.UpdateBuild)), HarmonyPrefix]
private static void Hud_UpdateBuild() => Instance.RefreshCategories();
private static void Hud_UpdateBuild() => Instance.RefreshCategoriesIfNeeded();

[HarmonyPatch(typeof(Hud), nameof(Hud.LateUpdate)), HarmonyPostfix]
private static void Hud_LateUpdate()
{
if (categoryRefreshNeeded)
{
categoryRefreshNeeded = false;
Instance.RefreshCategories();
}
}
private static void Hud_LateUpdate() => Instance.RefreshCategoriesIfNeeded();

[HarmonyPatch(typeof(ObjectDB), nameof(ObjectDB.Awake)), HarmonyPostfix, HarmonyPriority(Priority.Low)]
private static void RegisterCustomData(ObjectDB __instance) => Instance.RegisterCustomData(__instance);
Expand Down Expand Up @@ -846,6 +839,15 @@ private GameObject CreateCategoryTab()
return newTab;
}

private void RefreshCategoriesIfNeeded()
{
if (categoryRefreshNeeded)
{
categoryRefreshNeeded = false;
RefreshCategories();
}
}

/// <summary>
/// Updates the piece categories, should be called after setting the m_category field of a piece.
/// </summary>
Expand Down

0 comments on commit 98e8a0a

Please sign in to comment.