fix: tooltip error
This commit is contained in:
+38
-29
@@ -12,17 +12,18 @@ local function GetItemIDFromLink(link)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Count items for a specific character
|
-- Count items for a specific character
|
||||||
|
-- Count items for a specific character with safety checks
|
||||||
local function CountItemsForCharacter(itemID, characterData)
|
local function CountItemsForCharacter(itemID, characterData)
|
||||||
local bagCount = 0
|
local bagCount = 0
|
||||||
local bankCount = 0
|
local bankCount = 0
|
||||||
local equippedCount = 0
|
local equippedCount = 0
|
||||||
|
|
||||||
-- Count bags
|
-- Count bags with safety checks
|
||||||
if characterData.bags then
|
if characterData.bags and type(characterData.bags) == "table" then
|
||||||
for bagID, bagData in pairs(characterData.bags) do
|
for bagID, bagData in pairs(characterData.bags) do
|
||||||
if bagData and bagData.slots then
|
if bagData and type(bagData) == "table" and bagData.slots and type(bagData.slots) == "table" then
|
||||||
for slotID, itemData in pairs(bagData.slots) do
|
for slotID, itemData in pairs(bagData.slots) do
|
||||||
if itemData and itemData.link then
|
if itemData and type(itemData) == "table" and itemData.link then
|
||||||
local slotItemID = GetItemIDFromLink(itemData.link)
|
local slotItemID = GetItemIDFromLink(itemData.link)
|
||||||
if slotItemID == itemID then
|
if slotItemID == itemID then
|
||||||
bagCount = bagCount + (itemData.count or 1)
|
bagCount = bagCount + (itemData.count or 1)
|
||||||
@@ -33,12 +34,12 @@ local function CountItemsForCharacter(itemID, characterData)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Count bank
|
-- Count bank with safety checks
|
||||||
if characterData.bank then
|
if characterData.bank and type(characterData.bank) == "table" then
|
||||||
for bagID, bagData in pairs(characterData.bank) do
|
for bagID, bagData in pairs(characterData.bank) do
|
||||||
if bagData and bagData.slots then
|
if bagData and type(bagData) == "table" and bagData.slots and type(bagData.slots) == "table" then
|
||||||
for slotID, itemData in pairs(bagData.slots) do
|
for slotID, itemData in pairs(bagData.slots) do
|
||||||
if itemData and itemData.link then
|
if itemData and type(itemData) == "table" and itemData.link then
|
||||||
local slotItemID = GetItemIDFromLink(itemData.link)
|
local slotItemID = GetItemIDFromLink(itemData.link)
|
||||||
if slotItemID == itemID then
|
if slotItemID == itemID then
|
||||||
bankCount = bankCount + (itemData.count or 1)
|
bankCount = bankCount + (itemData.count or 1)
|
||||||
@@ -49,10 +50,10 @@ local function CountItemsForCharacter(itemID, characterData)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Count equipped items from EquipmentScanner data
|
-- Count equipped items from EquipmentScanner data with safety checks
|
||||||
if characterData.equipped then
|
if characterData.equipped and type(characterData.equipped) == "table" then
|
||||||
for slotName, itemData in pairs(characterData.equipped) do
|
for slotName, itemData in pairs(characterData.equipped) do
|
||||||
if itemData and itemData.link then
|
if itemData and type(itemData) == "table" and itemData.link then
|
||||||
local slotItemID = GetItemIDFromLink(itemData.link)
|
local slotItemID = GetItemIDFromLink(itemData.link)
|
||||||
if slotItemID == itemID then
|
if slotItemID == itemID then
|
||||||
equippedCount = equippedCount + 1
|
equippedCount = equippedCount + 1
|
||||||
@@ -72,11 +73,15 @@ local function GetClassColor(classToken)
|
|||||||
return 1.0, 1.0, 1.0
|
return 1.0, 1.0, 1.0
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Add inventory info to tooltip
|
|
||||||
-- Add inventory info to tooltip
|
|
||||||
-- Add inventory info to tooltip
|
|
||||||
function Tooltip:AddInventoryInfo(tooltip, link)
|
function Tooltip:AddInventoryInfo(tooltip, link)
|
||||||
if not Guda_DB or not Guda_DB.characters then
|
-- Check if database is properly initialized and has the expected structure
|
||||||
|
if not Guda_DB or type(Guda_DB) ~= "table" then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Safely check characters - it might be nil or a string during early initialization
|
||||||
|
if not Guda_DB.characters or type(Guda_DB.characters) ~= "table" then
|
||||||
|
-- If characters is a string or nil, just return silently
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -91,23 +96,27 @@ function Tooltip:AddInventoryInfo(tooltip, link)
|
|||||||
local characterCounts = {}
|
local characterCounts = {}
|
||||||
local hasAnyItems = false
|
local hasAnyItems = false
|
||||||
|
|
||||||
-- Count items across all characters
|
-- Count items across all characters with safety checks
|
||||||
for charName, charData in pairs(Guda_DB.characters) do
|
for charName, charData in pairs(Guda_DB.characters) do
|
||||||
local bagCount, bankCount, equippedCount = CountItemsForCharacter(itemID, charData)
|
-- Ensure charData is actually a table before processing
|
||||||
|
if type(charData) == "table" then
|
||||||
|
local bagCount, bankCount, equippedCount = CountItemsForCharacter(itemID, charData)
|
||||||
|
|
||||||
if bagCount > 0 or bankCount > 0 or equippedCount > 0 then
|
if bagCount > 0 or bankCount > 0 or equippedCount > 0 then
|
||||||
hasAnyItems = true
|
hasAnyItems = true
|
||||||
totalBags = totalBags + bagCount
|
totalBags = totalBags + bagCount
|
||||||
totalBank = totalBank + bankCount
|
totalBank = totalBank + bankCount
|
||||||
totalEquipped = totalEquipped + equippedCount
|
totalEquipped = totalEquipped + equippedCount
|
||||||
table.insert(characterCounts, {
|
table.insert(characterCounts, {
|
||||||
name = charData.name or charName,
|
name = charData.name or charName,
|
||||||
classToken = charData.classToken,
|
classToken = charData.classToken,
|
||||||
bagCount = bagCount,
|
bagCount = bagCount,
|
||||||
bankCount = bankCount,
|
bankCount = bankCount,
|
||||||
equippedCount = equippedCount
|
equippedCount = equippedCount
|
||||||
})
|
})
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
-- If charData is not a table (string, number, etc.), just skip it
|
||||||
end
|
end
|
||||||
|
|
||||||
local totalCount = totalBags + totalBank + totalEquipped
|
local totalCount = totalBags + totalBank + totalEquipped
|
||||||
|
|||||||
Reference in New Issue
Block a user