Add Markdown export for Mystic Enchants and update enchant collection

- Implemented `GenerateMarkdownEnchants()` to export Mystic Enchants in Markdown format, sorted by quality and slot.
- Replaced tooltip-based enchant detection with `C_MysticEnchant` API for more reliable data collection.
- Added UI button to trigger Mystic Enchant Markdown export.
This commit is contained in:
2025-12-08 16:34:22 +01:00
parent d1dc8ca236
commit 03c369e10e
3 changed files with 110 additions and 49 deletions
+28 -49
View File
@@ -1,64 +1,43 @@
-- AscensionExporter - Mystic Enchants collector (from equipped item tooltips)
-- AscensionExporter - Mystic Enchants (Glyphs) collector
-- Ensure global addon table exists even if load order varies
AscensionExporter = _G.AscensionExporter or {}
_G.AscensionExporter = AscensionExporter
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",
}
function AE.CollectMysticEnchants()
local enchants = {}
local function extract_mystic_from_tooltip(slot)
GameTooltip:ClearLines()
GameTooltip:SetOwner(UIParent, "ANCHOR_NONE")
GameTooltip:SetInventoryItem("player", slot)
local found = 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()
if (l:find("mystic") or l:find("mythic")) and (l:find("enchant") or l:find("rune")) then
-- Try to pull the enchant name after a colon, else use the whole line
local name = txt
local after = txt:match("[:]%s*(.+)$")
if after and after ~= "" then name = after end
-- Trim color codes if any
name = name:gsub("|c%x%x%x%x%x%x%x%x", ""):gsub("|r", "")
found = name
break
-- Ascension uses C_MysticEnchant API
if C_MysticEnchant and C_MysticEnchant.GetAppliedEnchant then
-- NUM_MYSTIC_ENCHANT_SLOTS is typically 12 on Ascension
local numSlots = NUM_MYSTIC_ENCHANT_SLOTS or 12
for i = 1, numSlots do
local spellID = C_MysticEnchant.GetAppliedEnchant("player", i)
if spellID and spellID > 0 then
local name, _, icon = GetSpellInfo(spellID)
if name then
-- Extract icon path from full texture path
-- Format: Interface\Icons\spell_name
local iconPath = ""
if icon then
iconPath = icon:match("Interface\\Icons\\(.+)") or ""
iconPath = iconPath:lower()
end
table.insert(enchants, {
slot = i,
name = name,
spellID = spellID,
icon = iconPath
})
end
end
end
end
GameTooltip:Hide()
return found
end
function AE.CollectMysticEnchants()
local perSlot = {}
local activeSet = {}
for slot = 1, 19 do
local link = GetInventoryItemLink("player", slot)
if link then
local name = extract_mystic_from_tooltip(slot)
if name and name ~= "" then
table.insert(perSlot, { slot = slot, slotName = SLOT_NAMES[slot] or tostring(slot), name = name })
activeSet[name] = true
end
end
end
local active = {}
for n, _ in pairs(activeSet) do
table.insert(active, { name = n })
end
table.sort(active, function(a,b) return a.name < b.name end)
return { perSlot = perSlot, active = active }
table.sort(enchants, function(a,b) return a.slot < b.slot end)
return { enchants = enchants }
end
-- Mark module as loaded for debug visibility
+71
View File
@@ -266,6 +266,77 @@ function AE:GenerateMarkdownGear()
return table.concat(lines, "\n") .. "\n"
end
-- Markdown mystic enchants table generator
function AE:GenerateMarkdownEnchants()
local ench = self.CollectMysticEnchants and self.CollectMysticEnchants() or { enchants = {} }
local lines = {}
table.insert(lines, "## Mystic Enchants\n")
if #(ench.enchants or {}) == 0 then
table.insert(lines, "*No Mystic Enchants equipped.*\n")
return table.concat(lines, "\n")
end
-- Create single table with quality column
-- Ascension Mystic Enchant slots:
-- Slot 11-12: Artifact
-- Slot 1: Legendary
-- Slots 2-4: Epic
-- Slots 5-10: Rare
-- Determine quality and sort by quality then slot
local enchantRows = {}
for _, e in ipairs(ench.enchants or {}) do
local slot = e.slot or 0
local quality, qualityOrder
if slot >= 11 then
quality = '<span class="artifact">Artifact</span>'
qualityOrder = 1
elseif slot == 1 then
quality = '<span class="legendary">Legendary</span>'
qualityOrder = 2
elseif slot >= 2 and slot <= 4 then
quality = '<span class="epic">Epic</span>'
qualityOrder = 3
else
quality = '<span class="rare">Rare</span>'
qualityOrder = 4
end
local spellID = e.spellID or 0
local name = e.name or "Unknown"
local icon = e.icon or ""
local iconImg = icon ~= "" and string.format('<img src="/icons/spells/%s.png" width="20" height="20" style="vertical-align: middle;" /> ', icon) or ""
local link = spellID > 0 and string.format("[%s](https://db.ascension.gg/?spell=%d)", name, spellID) or name
table.insert(enchantRows, {
quality = quality,
qualityOrder = qualityOrder,
slot = slot,
text = string.format("| %s | %s**%s** |", quality, iconImg, link)
})
end
-- Sort by quality then slot
table.sort(enchantRows, function(a, b)
if a.qualityOrder ~= b.qualityOrder then
return a.qualityOrder < b.qualityOrder
end
return a.slot < b.slot
end)
-- Build table
table.insert(lines, "| Quality | Enchant |")
table.insert(lines, "|---------|---------|")
for _, row in ipairs(enchantRows) do
table.insert(lines, row.text)
end
return table.concat(lines, "\n")
end
-- Slash command handling
SLASH_ASCX1 = "/ascx"
SLASH_ASCX2 = "/asxc" -- alias: both map to the same handler key "ASCX"
+11
View File
@@ -54,6 +54,17 @@ local function CreateOrGetFrame()
end
end
end)
x = x + 95
makeBtn("MD Enchants", x, function()
if AscensionExporter and AscensionExporter.GenerateMarkdownEnchants then
local md = AscensionExporter:GenerateMarkdownEnchants() or ""
if AscensionExporter.ShowExport then
AscensionExporter:ShowExport(md, "Ascension Export - Markdown Enchants - Copy All (Ctrl+C)")
else
AscensionExporter_ShowExportFrame(md, "Ascension Export - Markdown Enchants - Copy All (Ctrl+C)")
end
end
end)
-- ScrollFrame + EditBox
local scrollFrame = CreateFrame("ScrollFrame", "AscensionExporterScrollFrame", frame, "UIPanelScrollFrameTemplate")