From 9886d33e4ed39b620a55728f1ad3a89cf4153f7f Mon Sep 17 00:00:00 2001 From: Salikh Gurgenidze Date: Sun, 16 Nov 2025 18:14:48 +0400 Subject: [PATCH] fix: update item counts on bag update --- Core/Tooltip.lua | 23 +++++++++++++++++++++++ Data/BagScanner.lua | 27 ++++++++++++++++++++++++--- 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/Core/Tooltip.lua b/Core/Tooltip.lua index 8c61442..43004ef 100644 --- a/Core/Tooltip.lua +++ b/Core/Tooltip.lua @@ -142,6 +142,29 @@ function Tooltip:Initialize() end end end + + -- Clear cache function + function Tooltip:ClearCache() + addon:Debug("Tooltip cache cleared") + end + + -- Register for bag updates in Initialize + function Tooltip:Initialize() + addon:Print("Initializing tooltip module...") + + -- Your existing hook code... + + -- Clear cache on bag updates + local frame = CreateFrame("Frame") + frame:RegisterEvent("BAG_UPDATE") + frame:SetScript("OnEvent", function() + if event == "BAG_UPDATE" then + Tooltip:ClearCache() + end + end) + + addon:Print("Tooltip item-count integration enabled") + end addon:Print("Tooltip item-count integration enabled") end \ No newline at end of file diff --git a/Data/BagScanner.lua b/Data/BagScanner.lua index 86a02b8..12f8561 100644 --- a/Data/BagScanner.lua +++ b/Data/BagScanner.lua @@ -76,9 +76,30 @@ end function BagScanner:SaveToDatabase() local bagData = self:ScanBags() addon.Modules.DB:SaveBags(bagData) + addon:Debug("Bag data saved to database") + + -- Clear tooltip cache so counts update immediately + if addon.Modules.Tooltip and addon.Modules.Tooltip.ClearCache then + addon.Modules.Tooltip:ClearCache() + end end --- Initialize (no auto-save, only save when bags are opened) +-- Initialize with auto-save on bag changes function BagScanner:Initialize() - addon:Debug("Bag scanner initialized") -end + -- Create event frame for bag updates + local eventFrame = CreateFrame("Frame") + self.eventFrame = eventFrame + + -- Register bag update events + eventFrame:RegisterEvent("BAG_UPDATE") + eventFrame:RegisterEvent("BAG_UPDATE_DELAYED") + + eventFrame:SetScript("OnEvent", function() + if event == "BAG_UPDATE" or event == "BAG_UPDATE_DELAYED" then + addon:Debug("Bag update detected, saving data...") + self:SaveToDatabase() + end + end) + + addon:Debug("Bag scanner initialized with auto-save") +end \ No newline at end of file