Enhance gear enchant detection and handling fallback

- Refined tooltip parsing to accurately detect base enchantments.
- Added durability-based heuristic to improve enchantment line identification.
- Implemented fallback to `GetSpellInfo` for missing enchant names.
- Provided "Unresolved" as a last-resort identifier for unidentified enchants.
This commit is contained in:
2025-12-08 15:48:23 +01:00
parent 94f6f55fb6
commit 27a41bfe69
+47 -11
View File
@@ -53,28 +53,55 @@ end
local function read_enchant_from_tooltip(slot)
-- Try to extract human-readable base enchant (not mystic) if present
-- Enchantments appear as separate green lines, often between stats and durability
GameTooltip:ClearLines()
GameTooltip:SetOwner(UIParent, "ANCHOR_NONE")
GameTooltip:SetInventoryItem("player", slot)
local name = nil
local enchantLine = nil
local seenDurability = false
for i = 1, GameTooltip:NumLines() do
local line = _G["GameTooltipTextLeft" .. i]
if line then
local txt = tostring(line:GetText() or "")
if txt and txt ~= "" then
local l = txt:lower()
-- Skip mystic/mythic lines; those are handled separately
if not ((l:find("mystic") or l:find("mythic")) and (l:find("enchant") or l:find("rune"))) then
-- Heuristic: lines starting with "Enchanted" or containing "Enchantment" often denote base enchants
if l:find("^enchanted") or l:find("enchant") then
name = txt
-- Track if we've seen durability (enchants appear before this)
if l:find("durability") then
seenDurability = true
end
-- If we haven't found an enchant yet and we're not past durability
if not enchantLine and not seenDurability then
-- Skip unwanted patterns
if not l:find("disenchant") and not l:find("^equip:") and not l:find("^set:") and not l:find("^use:") then
-- Skip mystic/mythic lines
if not ((l:find("mystic") or l:find("mythic")) and (l:find("enchant") or l:find("rune"))) then
-- Get text color
local r, g, b = line:GetTextColor()
local isGreen = (g and g > 0.8 and r and r < 0.5)
-- Enchant patterns:
-- 1. Green text starting with +number
-- 2. Exclude base item stats (stamina, intellect, spirit, strength, agility)
if isGreen and l:match("^%+%d+") then
local isBaseStat = l:find("stamina") or l:find("intellect") or l:find("spirit") or
l:find("strength") or l:find("agility") or l:find("%(")
if not isBaseStat then
enchantLine = txt
break -- Found enchant, stop looking
end
end
end
end
end
end
end
end
GameTooltip:Hide()
return name
return enchantLine
end
function AE.CollectGear()
@@ -86,12 +113,21 @@ function AE.CollectGear()
local itemId = parsed.itemId or 0
local itemName, _, itemQuality, itemLevel, _, itemType, itemSubType, _, equipSlot, texture = GetItemInfo(itemLink)
local enchantName = read_enchant_from_tooltip(slot)
local enchant = nil
if parsed.enchantId and parsed.enchantId > 0 then
enchant = { id = parsed.enchantId, name = enchantName or "" }
elseif enchantName then
enchant = { id = 0, name = enchantName }
-- We have an enchantId, try multiple ways to get the name
local enchantName = read_enchant_from_tooltip(slot)
-- If tooltip parsing didn't work, try GetSpellInfo
if not enchantName then
local spellName = GetSpellInfo(parsed.enchantId)
if spellName then
enchantName = spellName
end
end
-- Fallback to "Unresolved"
enchant = { id = parsed.enchantId, name = enchantName or "Unresolved" }
end
local gems = resolve_gems(itemLink, parsed.gems or {})