This commit is contained in:
Salikh Gurgenidze
2026-01-24 00:38:03 +04:00
parent 21efe4c1cc
commit 75e4d83fc0
2 changed files with 45 additions and 30 deletions
+25 -15
View File
@@ -52,24 +52,29 @@ function BagScanner:GetBagData()
if cacheValid and bagCache then if cacheValid and bagCache then
-- Process any dirty slots incrementally -- Process any dirty slots incrementally
for bagID, slots in pairs(dirtySlots) do for bagID, slots in pairs(dirtySlots) do
if bagCache[bagID] then if bagID ~= nil and type(slots) == "table" then
for slotID in pairs(slots) do if bagCache[bagID] then
local oldData = bagCache[bagID].slots[slotID] for slotID in pairs(slots) do
local newData = self:ScanSlot(bagID, slotID) -- Validate slotID is a valid number
bagCache[bagID].slots[slotID] = newData if type(slotID) == "number" and slotID >= 1 then
local oldData = bagCache[bagID].slots[slotID]
local newData = self:ScanSlot(bagID, slotID)
bagCache[bagID].slots[slotID] = newData
-- Update free slot count -- Update free slot count
local wasEmpty = (oldData == nil) local wasEmpty = (oldData == nil)
local isEmpty = (newData == nil) local isEmpty = (newData == nil)
if wasEmpty and not isEmpty then if wasEmpty and not isEmpty then
bagCache[bagID].freeSlots = bagCache[bagID].freeSlots - 1 bagCache[bagID].freeSlots = bagCache[bagID].freeSlots - 1
elseif not wasEmpty and isEmpty then elseif not wasEmpty and isEmpty then
bagCache[bagID].freeSlots = bagCache[bagID].freeSlots + 1 bagCache[bagID].freeSlots = bagCache[bagID].freeSlots + 1
end
end
end end
else
-- Bag not in cache, scan it
bagCache[bagID] = self:ScanBag(bagID)
end end
else
-- Bag not in cache, scan it
bagCache[bagID] = self:ScanBag(bagID)
end end
end end
dirtySlots = {} dirtySlots = {}
@@ -139,6 +144,11 @@ end
-- Scan a single slot -- Scan a single slot
function BagScanner:ScanSlot(bagID, slot) function BagScanner:ScanSlot(bagID, slot)
-- Validate parameters to prevent API errors
if bagID == nil or slot == nil or slot < 1 then
return nil
end
local texture, itemCount, locked, quality, readable, lootable = GetContainerItemInfo(bagID, slot) local texture, itemCount, locked, quality, readable, lootable = GetContainerItemInfo(bagID, slot)
if not texture then if not texture then
+20 -15
View File
@@ -52,24 +52,29 @@ function BankScanner:GetBankData()
if cacheValid and bankCache then if cacheValid and bankCache then
-- Process any dirty slots incrementally -- Process any dirty slots incrementally
for bagID, slots in pairs(dirtySlots) do for bagID, slots in pairs(dirtySlots) do
if bankCache[bagID] then if bagID ~= nil and type(slots) == "table" then
for slotID in pairs(slots) do if bankCache[bagID] then
local oldData = bankCache[bagID].slots[slotID] for slotID in pairs(slots) do
local newData = addon.Modules.BagScanner:ScanSlot(bagID, slotID) -- Validate slotID is a valid number
bankCache[bagID].slots[slotID] = newData if type(slotID) == "number" and slotID >= 1 then
local oldData = bankCache[bagID].slots[slotID]
local newData = addon.Modules.BagScanner:ScanSlot(bagID, slotID)
bankCache[bagID].slots[slotID] = newData
-- Update free slot count -- Update free slot count
local wasEmpty = (oldData == nil) local wasEmpty = (oldData == nil)
local isEmpty = (newData == nil) local isEmpty = (newData == nil)
if wasEmpty and not isEmpty then if wasEmpty and not isEmpty then
bankCache[bagID].freeSlots = bankCache[bagID].freeSlots - 1 bankCache[bagID].freeSlots = bankCache[bagID].freeSlots - 1
elseif not wasEmpty and isEmpty then elseif not wasEmpty and isEmpty then
bankCache[bagID].freeSlots = bankCache[bagID].freeSlots + 1 bankCache[bagID].freeSlots = bankCache[bagID].freeSlots + 1
end
end
end end
else
-- Bag not in cache, scan it
bankCache[bagID] = self:ScanBankBag(bagID)
end end
else
-- Bag not in cache, scan it
bankCache[bagID] = self:ScanBankBag(bagID)
end end
end end
dirtySlots = {} dirtySlots = {}