Files
ascension-char-exporter/AscensionExporter/Collectors/Gear.lua
T
florian.berthold 06704f628f Add fallback export UI and improve gem data handling
- Implemented a fallback lightweight export window for cases where the UI module is not loaded.
- Abstracted export display logic into a unified `ShowExport` function.
- Added gem `enchantId` to gem data for better clarity.
2025-12-08 14:03:52 +01:00

117 lines
4.2 KiB
Lua

-- AscensionExporter - Gear collector (equipped items only)
local AE = AscensionExporter
local SLOT_NAMES = {
[1] = "HEAD", [2] = "NECK", [3] = "SHOULDER", [4] = "SHIRT", [5] = "CHEST",
[6] = "WAIST", [7] = "LEGS", [8] = "FEET", [9] = "WRIST", [10] = "HANDS",
[11] = "FINGER1", [12] = "FINGER2", [13] = "TRINKET1", [14] = "TRINKET2",
[15] = "BACK", [16] = "MAINHAND", [17] = "OFFHAND", [18] = "RANGED", [19] = "TABARD",
}
local function parse_item_link(itemLink)
if not itemLink then return nil end
local itemString = itemLink:match("Hitem:([%d:]+)")
if not itemString then return nil end
local parts = {}
for v in string.gmatch(itemString, "([^:]+)") do
parts[#parts+1] = tonumber(v) or 0
end
local itemId = parts[1] or 0
local enchantId = parts[2] or 0
local gems = { parts[3] or 0, parts[4] or 0, parts[5] or 0, parts[6] or 0 }
local suffixId = parts[7] or 0
return {
itemId = itemId,
enchantId = enchantId,
gems = gems,
suffixId = suffixId,
}
end
local function resolve_gems(itemLink, gemIds)
local arr = {}
for i = 1, 4 do
local gid = gemIds[i] or 0
if gid and gid > 0 then
-- GetItemGem gives name & link by index
local name, gemLink = GetItemGem(itemLink, i)
local gemItemId = 0
if gemLink then
local id = tonumber(string.match(gemLink, "item:(%d+)"))
if id then gemItemId = id end
end
-- gid from item link is the socket gem enchantId; expose it explicitly
table.insert(arr, { itemId = gemItemId, enchantId = gid, name = name or "", link = gemLink or "" })
end
end
return arr
end
local function read_enchant_from_tooltip(slot)
-- Try to extract human-readable base enchant (not mystic) if present
GameTooltip:ClearLines()
GameTooltip:SetOwner(UIParent, "ANCHOR_NONE")
GameTooltip:SetInventoryItem("player", slot)
local name = nil
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
end
end
end
end
end
GameTooltip:Hide()
return name
end
function AE.CollectGear()
local out = { slots = {} }
for slot = 1, 19 do
local itemLink = GetInventoryItemLink("player", slot)
if itemLink then
local parsed = parse_item_link(itemLink) or {}
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 }
end
local gems = resolve_gems(itemLink, parsed.gems or {})
table.insert(out.slots, {
slot = slot,
slotName = SLOT_NAMES[slot] or tostring(slot),
itemId = itemId,
name = itemName or "",
quality = itemQuality or 0,
itemLevel = itemLevel or 0,
type = itemType or "",
subType = itemSubType or "",
equipSlot = equipSlot or "",
texture = texture or "",
link = itemLink,
enchant = enchant,
gems = gems,
})
else
-- Empty slot omitted intentionally
end
end
return out
end