-- AscensionExporter - Talent URL Encoder -- Encodes talents into URL format for https://exil.es/en/wow/talent-calc?build=... AscensionExporter = _G.AscensionExporter or {} _G.AscensionExporter = AscensionExporter local AE = AscensionExporter local BASE36_CHARS = "0123456789abcdefghijklmnopqrstuvwxyz" local function encodeRank(rank) if rank < 10 then return tostring(rank) end -- For ranks >= 10, use base36 (a=10, b=11, etc) if rank <= 35 then return BASE36_CHARS:sub(rank + 1, rank + 1) end return "0" end local function toBase36(num) if num == 0 then return "0" end local result = "" while num > 0 do local remainder = num % 36 result = BASE36_CHARS:sub(remainder + 1, remainder + 1) .. result num = math.floor(num / 36) end return result end -- Encode talents to URL format -- Format: `${class}.${tree0}.${tree1}.${tree2}` -- Each tree is encoded as "index_rank" pairs separated by underscores -- Example: "0_3_b_5" means slot 0 has rank 3, slot 11 (b in base36) has rank 5 function AE.EncodeTalentsToURL(talentsData, className) if not talentsData or not className then return nil end -- Normalize class name to lowercase className = className:lower() -- Build a structure: 3 talent trees with slots -- Each WoW class has 3 talent trees local trees = {{}, {}, {}} -- Group talents by their tabIndex (1-based in Lua, but we want 0-based for array) for _, t in ipairs(talentsData.selected or {}) do local tabIndex = t.tabIndex or 1 local talentIndex = (t.talentIndex or 1) - 1 -- Convert to 0-based index local rank = t.rank or 0 if rank > 0 and tabIndex >= 1 and tabIndex <= 3 then table.insert(trees[tabIndex], { index = talentIndex, rank = rank }) end end -- Sort each tree by index for consistent encoding for _, tree in ipairs(trees) do table.sort(tree, function(a, b) return a.index < b.index end) end -- Encode each tree local treeParts = {} for _, tree in ipairs(trees) do local pairs = {} for _, talent in ipairs(tree) do local idxStr = toBase36(talent.index) local rankStr = encodeRank(talent.rank) table.insert(pairs, idxStr .. rankStr) end table.insert(treeParts, table.concat(pairs, "_")) end -- Build final URL format: class.tree0.tree1.tree2 return className .. "." .. table.concat(treeParts, ".") end -- Generate full talent calc URL function AE.GenerateTalentCalcURL(talentsData, className) local build = AE.EncodeTalentsToURL(talentsData, className) if not build then return nil end return "https://exil.es/en/wow/talent-calc?build=" .. build end -- Mark module as loaded AE._loadedTalentEncoder = true