Mudanças entre as edições de "Módulo:C.Generate"

De Wiki Gla
Ir para navegação Ir para pesquisar
(Criou página com '-- Módulo:C.Generate — função generate() local p = {} local utils = require("Módulo:C.Utils") local i18n = require("Módulo:C.i18n") local trim = utils.trim local file...')
 
m (fix styles)
Linha 7: Linha 7:
local trim = utils.trim
local trim = utils.trim
local fileURL = utils.fileURL
local fileURL = utils.fileURL
local normalizeDim = utils.normalizeDim
local makeAttrString = utils.makeAttrString
local makeAttrString = utils.makeAttrString
local requireCharModule = utils.requireCharModule
local requireCharModule = utils.requireCharModule
local collectJsonObjects = utils.collectJsonObjects
local collectJsonObjects = utils.collectJsonObjects
local function ensureFileExists(fileName, fallback)
local function ensureFileExists(fileName, fallback)
     fileName = trim(fileName or "")
     fileName = trim(fileName or "")
Linha 39: Linha 39:
     local parent = frame:getParent() or frame
     local parent = frame:getParent() or frame
     local args = parent.args or {}
     local args = parent.args or {}
    local html = mw.html.create('div')
    local box = html:tag('div'):addClass('character-box')


     -- Requer |module= explícito
     -- Requer |module= explícito
Linha 47: Linha 50:


     -- Carrega módulo do personagem
     -- Carrega módulo do personagem
     local data = requireCharModule(moduleName) or {}
     local charData = requireCharModule(moduleName) or {}


     -- Nome: |name= ou do módulo
     -- Nome: |name= ou |nome= ou do módulo
     local charName = trim(args.name or data.name or "")
     local charName = trim(args.name or args.nome or charData.name or "")
 
    local html = mw.html.create('div')
    local box = html:tag('div'):addClass('character-box')


     ----------------------------------------------------------------------------
     ----------------------------------------------------------------------------
     -- Background (do módulo)
     -- Background (suporta |background= ou |banner= como fallback, ou do módulo)
     ----------------------------------------------------------------------------
     ----------------------------------------------------------------------------
     do
     do
         local bgParam = data.background or ""
         local bgParam = trim(frame:preprocess(args.background or ""))
        if bgParam == "" then
            bgParam = trim(frame:preprocess(args.banner or "")) -- opcional compat
        end
        if bgParam == "" then
            bgParam = charData.background or ""
        end
         if bgParam ~= "" then
         if bgParam ~= "" then
             box:attr('data-bg-file', bgParam)
             box:attr('data-bg-file', bgParam)
Linha 65: Linha 71:
             if url and url ~= "" then
             if url and url ~= "" then
                 box:attr('data-bg-url', url)
                 box:attr('data-bg-url', url)
                -- fallback inline para certos temas
                 local style = string.format("--character-bg: url('%s'); background-image: url('%s');", url, url)
                 local style = string.format("--character-bg: url('%s'); background-image: url('%s');", url, url)
                 box:attr('style', style)
                local old = box:getAttr('style')
                 box:attr('style', old and (old .. " " .. style) or style)
             end
             end
         end
         end
Linha 72: Linha 80:


     ----------------------------------------------------------------------------
     ----------------------------------------------------------------------------
     -- Weapon Icon (do módulo)
     -- Weapon Icon (ícone global do weapon toggle)
     ----------------------------------------------------------------------------
     ----------------------------------------------------------------------------
     do
     do
         local weaponIconParam = data.weaponicon or ""
         local weaponIconParam = trim(frame:preprocess(args.weaponicon or ""))
        if weaponIconParam == "" then
            weaponIconParam = charData.weaponicon or ""
        end
         if weaponIconParam ~= "" and weaponIconParam ~= "Nada.png" then
         if weaponIconParam ~= "" and weaponIconParam ~= "Nada.png" then
             box:attr('data-weaponicon', weaponIconParam)
             box:attr('data-weaponicon', weaponIconParam)
Linha 90: Linha 101:
     local nameBox = topbar:tag('div'):addClass('character-name-box')
     local nameBox = topbar:tag('div'):addClass('character-name-box')


     local avatarImg = ensureFileExists(data.avatar, "Franky_ts_medal.png")
     local avatarImg = ensureFileExists(args.avatar or charData.avatar, "Franky_ts_medal.png")
     nameBox:wikitext(string.format('[[Arquivo:%s|class=topbar-icon|link=|alt=Avatar]]', avatarImg))
     nameBox:wikitext(string.format('[[Arquivo:%s|class=topbar-icon|link=|alt=Avatar]]', avatarImg))


Linha 99: Linha 110:
     local classTags = nameGroup:tag('div'):addClass('class-tags')
     local classTags = nameGroup:tag('div'):addClass('class-tags')


     -- Resolve Tier/Tags do módulo
     -- Resolve Tier/Tags em PT (render inicial)
     local rawTier = ""
     local rawTier = trim(frame:preprocess(args.tier or ""))
     if data.tier_i18n and type(data.tier_i18n) == "table" then
    local rawClasse = trim(frame:preprocess(args.classe or ""))
         rawTier = data.tier_i18n.pt or data.tier_i18n.en or data.tier or ""
 
     else
    -- Se vier tokens tipo "tier*", resolve via módulo
         rawTier = data.tier or ""
     if rawTier ~= "" and mw.ustring.lower(rawTier):sub(1, 4) == "tier" then
        rawTier = (charData.tier_i18n and charData.tier_i18n.pt) or charData.tier or rawTier
    end
    if rawClasse ~= "" and mw.ustring.lower(rawClasse):sub(1, 5) == "class" then
        local arr = (charData.tags_i18n and charData.tags_i18n.pt) or charData.tags
        if type(arr) == "table" then
            rawClasse = table.concat(arr, " / ")
        end
    end
    -- Se continuar vazio, puxa do módulo do personagem
    if rawTier == "" then
         rawTier = (charData.tier_i18n and charData.tier_i18n.pt) or charData.tier or ""
     end
    if rawClasse == "" then
        local arr = (charData.tags_i18n and charData.tags_i18n.pt) or charData.tags
         if type(arr) == "table" then
            rawClasse = table.concat(arr, " / ")
        else
            rawClasse = arr or ""
        end
     end
     end


Linha 115: Linha 145:
     -- Injeta i18n do TIER como data-*
     -- Injeta i18n do TIER como data-*
     do
     do
         local tI = data.tier_i18n
         local tI = charData.tier_i18n
         if type(tI) ~= "table" then
         if type(tI) ~= "table" then
             tI = tierPackFrom(rawTier ~= "" and rawTier or (data.tier or ""))
            -- deduz do texto já resolvido (rawTier) ou do charData.tier
             tI = tierPackFrom(rawTier ~= "" and rawTier or (charData.tier or ""))
         else
         else
             local seed = tI.pt or tI.en or tI.es or tI.pl or rawTier or data.tier or ""
            -- completa faltantes usando um seed
             local seed = tI.pt or tI.en or tI.es or tI.pl or rawTier or charData.tier or ""
             local base = tierPackFrom(seed)
             local base = tierPackFrom(seed)
             tI = {
             tI = {
Linha 129: Linha 161:
         end
         end
         if tierDiv then
         if tierDiv then
             tierDiv:attr('data-tier-pt', tI.pt or rawTier)
             tierDiv:attr('data-tier-pt', tI.pt or rawTier):attr('data-tier-en', tI.en or tI.pt or rawTier):attr(
                :attr('data-tier-en', tI.en or tI.pt or rawTier)
                'data-tier-es', tI.es or tI.pt or rawTier):attr('data-tier-pl', tI.pl or tI.pt or rawTier)
                :attr('data-tier-es', tI.es or tI.pt or rawTier)
                :attr('data-tier-pl', tI.pl or tI.pt or rawTier)
         end
         end
     end
     end
Linha 139: Linha 169:
     do
     do
         local tagsI = nil
         local tagsI = nil
         if type(data.tags_i18n) == "table" then
         if type(charData.tags_i18n) == "table" then
             local basis = tagsPackFrom(data.tags_i18n.pt or data.tags_i18n.en or data.tags_i18n.es or data.tags_i18n.pl or
            -- já tem i18n no módulo → só completa faltantes
            {})
             local basis = tagsPackFrom(charData.tags_i18n.pt or charData.tags_i18n.en or charData.tags_i18n.es or
                charData.tags_i18n.pl or {})
             tagsI = {
             tagsI = {
                 pt = data.tags_i18n.pt or basis.pt,
                 pt = charData.tags_i18n.pt or basis.pt,
                 en = data.tags_i18n.en or basis.en,
                 en = charData.tags_i18n.en or basis.en,
                 es = data.tags_i18n.es or basis.es,
                 es = charData.tags_i18n.es or basis.es,
                 pl = data.tags_i18n.pl or basis.pl
                 pl = charData.tags_i18n.pl or basis.pl
             }
             }
         else
         else
            -- constrói i18n a partir da lista simples (pt ou en que o editor já colocou)
             local baseList = {}
             local baseList = {}
             if type(data.tags) == "table" then
             if type(charData.tags) == "table" then
                 baseList = data.tags
                 baseList = charData.tags
             elseif type(data.tags) == "string" then
             elseif type(charData.tags) == "string" then
                 for entry in mw.text.gsplit(data.tags, '/', true) do
                 for entry in mw.text.gsplit(charData.tags, '/', true) do
                     local t = mw.text.trim(entry or '')
                     local t = mw.text.trim(entry or '')
                     if t ~= '' then
                     if t ~= '' then
Linha 162: Linha 194:
             tagsI = tagsPackFrom(baseList)
             tagsI = tagsPackFrom(baseList)
         end
         end
         if tagsI then
         classTags:attr('data-tags-i18n', mw.text.jsonEncode(tagsI))
            classTags:attr('data-tags-i18n', mw.text.jsonEncode(tagsI))
    end
            -- Render inicial das TAGS (PT)
 
            if tagsI.pt and type(tagsI.pt) == "table" then
    -- Render inicial das TAGS (PT)
                for _, tag in ipairs(tagsI.pt) do
    do
                    if trim(tag) ~= "" then
        for entry in mw.text.gsplit(rawClasse, '/', true) do
                        classTags:tag('div'):addClass('class-tag'):wikitext(tag)
            local clean = mw.text.trim(entry or '')
                    end
            if clean ~= '' then
                end
                classTags:tag('div'):addClass('class-tag'):wikitext(clean)
             end
             end
         end
         end
     end
     end


     -- Descrição geral (do módulo)
     -- Descrição geral (se houver)
     if data.desc then
     local descText = args.desc or ""
        local descText = ""
    if descText == "" then
         if type(data.desc) == "table" then
         if type(charData.desc) == "table" then
             descText = data.desc.pt or data.desc.en or data.desc.es or data.desc.pl or ""
             descText = charData.desc.pt or charData.desc.en or charData.desc.es or charData.desc.pl or ""
         else
         else
             descText = tostring(data.desc)
             descText = tostring(charData.desc or "")
        end
        if descText ~= "" then
            header:tag('div'):addClass('topbar-description'):wikitext(descText)
         end
         end
     end
     end
    header:tag('div'):addClass('topbar-description'):wikitext(descText)


     ----------------------------------------------------------------------------
     ----------------------------------------------------------------------------
Linha 195: Linha 225:
     local baseLang = rawLang:match("^([a-z][a-z])") or rawLang
     local baseLang = rawLang:match("^([a-z][a-z])") or rawLang


     local TAB = TAB_I18N[rawLang] or TAB_I18N[baseLang] or TAB_I18N.pt
    -- fallback caso TAB_I18N não exista
    local TAB_MAP = TAB_I18N or {
        pt = {
            skills = "Habilidades",
            skins = "Skins",
            skins_title = "SKINS & SPOTLIGHTS"
        },
        en = {
            skills = "Skills",
            skins = "Skins",
            skins_title = "SKINS & SPOTLIGHTS"
        },
        es = {
            skills = "Habilidades",
            skins = "Aspectos",
            skins_title = "ASPECTOS Y DESTACADOS"
        },
        pl = {
            skills = "Umiejętności",
            skins = "Skórki",
            skins_title = "SKÓRKI I PREZENTACJE"
        }
    }
     local TAB = TAB_MAP[rawLang] or TAB_MAP[baseLang] or TAB_MAP.pt


     ----------------------------------------------------------------------------
     ----------------------------------------------------------------------------
Linha 216: Linha 269:
     skillsTab:attr('data-i18n-attrs', mw.text.jsonEncode(ATTR_I18N))
     skillsTab:attr('data-i18n-attrs', mw.text.jsonEncode(ATTR_I18N))
     skillsTab:attr('data-i18n-flags', mw.text.jsonEncode(FLAGS_I18N))
     skillsTab:attr('data-i18n-flags', mw.text.jsonEncode(FLAGS_I18N))
     if baseLang then
     if args.lang and trim(args.lang) ~= "" then
         skillsTab:attr('data-i18n-default', baseLang)
         skillsTab:attr('data-i18n-default', baseLang)
     end
     end


     -- Gera skills do módulo: chama I.Skills
     -- Monta ícones de skill: tenta do módulo primeiro, depois de |skills=
     local skillsJSON = iSkills.skill(frame)
    local skillsPacked = args.skills or ""
     if skillsPacked == "" then
        -- Tenta gerar do módulo
        local skillsJSON = iSkills.skill(frame)
        if skillsJSON and skillsJSON ~= "" and skillsJSON ~= "[]" then
            skillsPacked = skillsJSON
        end
    end
 
     local idx = 0
     local idx = 0
     if skillsJSON and skillsJSON ~= "" then
     for _, chunk in ipairs(collectJsonObjects(skillsPacked)) do
        for _, chunk in ipairs(collectJsonObjects(skillsJSON)) do
        local ok, sk = pcall(mw.text.jsonDecode, chunk)
            local ok, sk = pcall(mw.text.jsonDecode, chunk)
        if ok and type(sk) == "table" then
            if ok and type(sk) == "table" then
            local name = trim(sk.name or sk.nome or sk.n or "")
                local name = trim(sk.name or sk.n or "")
            local icon = trim(sk.icon or "")
                local icon = trim(sk.icon or "")
            local desc = trim(sk.desc or "")
                if icon ~= "" then
            local level = trim(tostring(sk.level or ""))
                    idx = idx + 1
            local pve = trim(sk.powerpve or "")
                    local attrs = makeAttrString(
            local pvp = trim(sk.powerpvp or "")
                        trim(tostring(sk.powerpve or "")),
            local energy = trim(sk.energy or "")
                        trim(tostring(sk.powerpvp or "")),
            local cd = trim(sk.cooldown or "")
                        trim(tostring(sk.energy or "")),
            local video = trim(sk.video or "")
                        trim(tostring(sk.cooldown or ""))
            if icon ~= "" then
                    )
                idx = idx + 1
                local attrs = makeAttrString(pve, pvp, energy, cd)


                    local iconWrap = iconBar:tag('div'):addClass('skill-icon')
                local iconWrap = iconBar:tag('div'):addClass('skill-icon'):attr('data-index', idx):attr('data-nome',
                        :attr('data-index', idx)
                    name):attr('data-desc', desc):attr('data-atr', attrs):attr('data-video',
                        :attr('data-nome', name)
                    (video ~= "" and fileURL(video) or "")):attr('data-video-preload', 'auto'):attr('data-icon-file',
                        :attr('data-desc', trim(sk.desc or ""))
                    icon):attr('data-video-file', video or "")
                        :attr('data-atr', attrs)
                        :attr('data-video', (sk.video and sk.video ~= "" and fileURL(sk.video)) or "")
                        :attr('data-video-preload', 'auto')
                        :attr('data-icon-file', icon)
                        :attr('data-video-file', sk.video or "")


                    local level = trim(tostring(sk.level or ""))
                -- Level (para "Nível X" no JS)
                    if level ~= "" and mw.ustring.upper(level) ~= "NIVEL" then
                if level ~= "" and mw.ustring.upper(level) ~= "NIVEL" then
                        iconWrap:attr('data-level', level)
                    iconWrap:attr('data-level', level)
                    end
                end


                    -- Descrições i18n
                -- Descrições i18n (quando vierem do Info)
                    if type(sk.desc_i18n) == "table" then
                if type(sk.desc_i18n) == "table" then
                        iconWrap:attr('data-desc-pt', sk.desc_i18n.pt or "")
                    iconWrap:attr('data-desc-pt', sk.desc_i18n.pt or ""):attr('data-desc-en', sk.desc_i18n.en or "")
                            :attr('data-desc-en', sk.desc_i18n.en or "")
                        :attr('data-desc-es', sk.desc_i18n.es or ""):attr('data-desc-pl', sk.desc_i18n.pl or "")
                            :attr('data-desc-es', sk.desc_i18n.es or "")
                elseif desc and desc ~= "" then
                            :attr('data-desc-pl', sk.desc_i18n.pl or "")
                     -- Pelo menos PT
                     end
                    iconWrap:attr('data-desc-pt', desc)
                end


                    -- Subskills (suporte recursivo nativo)
                -- Subskills: injeta dados no HTML pro Widget ler
                    if type(sk.subs) == "table" and #sk.subs > 0 then
                if type(sk.subs) == "table" and #sk.subs > 0 then
                        iconWrap:attr('data-subs', mw.text.jsonEncode(sk.subs))
                    iconWrap:attr('data-subs', mw.text.jsonEncode(sk.subs))
                    end
                end
                    if type(sk.suborder) == "table" and #sk.suborder > 0 then
                if type(sk.suborder) == "table" and #sk.suborder > 0 then
                        iconWrap:attr('data-suborder', mw.text.jsonEncode(sk.suborder))
                    iconWrap:attr('data-suborder', mw.text.jsonEncode(sk.suborder))
                    end
                end


                    -- Flags
                -- flags (características: aggro, bridge, wall, quickcast)
                    if type(sk.flags) == "table" and #sk.flags > 0 then
                if type(sk.flags) == "table" and #sk.flags > 0 then
                        iconWrap:attr('data-flags', mw.text.jsonEncode(sk.flags))
                    iconWrap:attr('data-flags', mw.text.jsonEncode(sk.flags))
                    end
                end


                    -- Weapon
                -- weapon (arma equipável que modifica atributos/descrição)
                    if type(sk.weapon) == "table" then
                if type(sk.weapon) == "table" then
                        iconWrap:attr('data-weapon', mw.text.jsonEncode(sk.weapon))
                    iconWrap:attr('data-weapon', mw.text.jsonEncode(sk.weapon))
                    end
                end
                    if sk.weaponicon and sk.weaponicon ~= "" and sk.weaponicon ~= "Nada.png" then
                -- weaponicon (ícone do botão de toggle)
                        iconWrap:attr('data-weaponicon', sk.weaponicon)
                local weaponIcon = sk.weaponicon or charData.weaponicon or ""
                    end
                if weaponIcon ~= "" and weaponIcon ~= "Nada.png" then
                    iconWrap:attr('data-weaponicon', weaponIcon)
                end


                    -- Imagem do ícone
                -- Imagem do ícone
                    iconWrap:wikitext(string.format('[[Arquivo:%s|class=skill-icon-img|link=]]', icon))
                iconWrap:wikitext(string.format('[[Arquivo:%s|class=skill-icon-img|link=]]', icon))


                    -- Slot de descrição
                -- Slot de descrição indexado (o JS usa para sincronizar)
                    descBox:tag('div'):addClass('skill-desc'):attr('data-index', idx)
                descBox:tag('div'):addClass('skill-desc'):attr('data-index', idx)
                end
             end
             end
         end
         end
Linha 297: Linha 356:
     local skinsTab = box:tag('div'):addClass('tab-content'):attr('id', 'skins')
     local skinsTab = box:tag('div'):addClass('tab-content'):attr('id', 'skins')
     local cardSkins = skinsTab:tag('div'):addClass('card-skins')
     local cardSkins = skinsTab:tag('div'):addClass('card-skins')
    -- Título removido conforme requisito
     local podium = cardSkins:tag('div'):addClass('skins-podium')
     local podium = cardSkins:tag('div'):addClass('skins-podium')


     -- Gera skins do módulo: chama I.Skills
     local skinsPacked = args.skins or ""
    local skinsJSON = iSkills.skin(frame)
    if skinsPacked == "" then
        -- Tenta gerar do módulo
        local skinsJSON = iSkills.skin(frame)
        if skinsJSON and skinsJSON ~= "" and skinsJSON ~= "[]" then
            skinsPacked = skinsJSON
        end
    end
 
     local skinIndex = 0
     local skinIndex = 0
     if skinsJSON and skinsJSON ~= "" then
     for _, chunk in ipairs(collectJsonObjects(skinsPacked)) do
        for _, chunk in ipairs(collectJsonObjects(skinsJSON)) do
        local ok, sk = pcall(mw.text.jsonDecode, chunk)
            local ok, sk = pcall(mw.text.jsonDecode, chunk)
        if ok and type(sk) == "table" then
            if ok and type(sk) == "table" then
            skinIndex = skinIndex + 1
                skinIndex = skinIndex + 1
            local imageFile = trim(sk.sprite or "")
                local imageFile = trim(sk.sprite or "")
            local tooltipRaw = trim(sk.tooltip or "")
                local tooltipRaw = trim(sk.tooltip or "")
                local skinTitle = trim(sk.name or "")


                -- Processa tooltip (pode ser string ou objeto i18n)
            -- Título: vem 100% do editor (|name=)
                local tipPack, chosen = nil, ""
            local skinTitle = mw.text.trim(sk.name or "")
                if tooltipRaw:match("^%s*{") then
 
                    local ok2, obj2 = pcall(mw.text.jsonDecode, tooltipRaw)
            -- PT (ou fallback) para render inicial; preserva i18n p/ trocar no JS
                    if ok2 and type(obj2) == "table" then
            local tipPack, chosen = nil, ""
                        tipPack = obj2
            if tooltipRaw:match("^%s*{") then
                        chosen = trim(obj2.pt or obj2.en or obj2.es or obj2.pl or "")
                local ok2, obj2 = pcall(mw.text.jsonDecode, tooltipRaw)
                    end
                if ok2 and type(obj2) == "table" then
                end
                    tipPack = obj2
                if chosen == "" then
                    chosen = mw.text.trim(obj2.pt or obj2.en or obj2.es or obj2.pl or "")
                    chosen = tooltipRaw
                 end
                 end
            end
            if chosen == "" then
                chosen = tooltipRaw
            end
            -- HTML final do tooltip:
            -- 1) Título sem <br>, sem margem (pra não abrir um "buraco")
            local titleHtml = skinTitle ~= "" and
                ('<div class="skin-tooltip-title" style="margin:0">' .. skinTitle .. '</div>') or ""
            -- 2) Descrição com '''bold''' respeitado e TODA a linha em <b> (onde obtém)
            local bodyHtml = chosen:gsub("'''([^']+)'''", "<b>%1</b>"):gsub("\n", "<br>")
            bodyHtml = bodyHtml ~= "" and ('<b>' .. bodyHtml .. '</b>') or ""


                -- HTML do tooltip
            local tooltipHtml = titleHtml .. bodyHtml
                local titleHtml = skinTitle ~= "" and
                    ('<div class="skin-tooltip-title" style="margin:0">' .. skinTitle .. '</div>') or ""
                local bodyHtml = chosen:gsub("'''([^']+)'''", "<b>%1</b>"):gsub("\n", "<br>")
                bodyHtml = bodyHtml ~= "" and ('<b>' .. bodyHtml .. '</b>') or ""
                local tooltipHtml = titleHtml .. bodyHtml


                -- Podium slot
            -- Podium slot
                local slot = podium:tag('div'):addClass('podium-slot')
            local slot = podium:tag('div'):addClass('podium-slot')
                    :attr('data-skin-tooltip', tooltipHtml)
                :attr('data-skin-tooltip', tooltipHtml)
                    :attr('data-skin-index', skinIndex)
                :attr('data-skin-index', skinIndex)


                -- Offset X
            -- Aplica deslocamento horizontal via data-attribute
                local offsetXStr = trim(sk.offset_x or "")
            -- O JavaScript no widget aplicará o estilo para garantir que funcione
                if offsetXStr ~= "" and offsetXStr ~= "0" then
            local offsetXStr = trim(sk.offset_x or "")
                    local offsetX = tonumber(offsetXStr)
            if offsetXStr ~= "" and offsetXStr ~= "0" then
                    if offsetX and offsetX ~= 0 then
                local offsetX = tonumber(offsetXStr)
                        slot:attr('data-offset-x', tostring(offsetX))
                if offsetX and offsetX ~= 0 then
                    end
                    -- Garante que o valor seja uma string válida
                    slot:attr('data-offset-x', tostring(offsetX))
                 end
                 end
            end


                -- YouTube
            -- Spotlight do YouTube (parametro |youtube= na Predefinição:Skin)
                local yt = trim(sk.youtube or "")
            local yt = trim(sk.youtube or "")
                if yt ~= "" then
            if yt ~= "" then
                    if not yt:match("^https?://") then
                -- normaliza ID curto pra URL completa (ex.: "dQw4w9WgXcQ" -> "https://youtu.be/dQw4w9WgXcQ")
                        if yt:match("^[%w%-%_]+$") then
                if not yt:match("^https?://") then
                            yt = "https://youtu.be/" .. yt
                    if yt:match("^[%w%-%_]+$") then
                        else
                        yt = "https://youtu.be/" .. yt
                            yt = "https://" .. yt
                    else
                        end
                        yt = "https://" .. yt -- fallback besta se vier "www.youtube.com/..."
                     end
                     end
                    slot:attr('data-youtube', yt):addClass('is-clickable')
                        :attr('tabindex', '0')
                        :attr('role', 'button')
                        :attr('aria-label', 'YouTube: ' .. (skinTitle ~= "" and skinTitle or 'skin'))
                 end
                 end


                 if skinTitle ~= "" then
                 slot:attr('data-youtube', yt):addClass('is-clickable')
                    slot:attr('data-skin-title', skinTitle)
                    :attr('tabindex', '0')
                end
                    :attr('role', 'button'):attr('aria-label',
                if tipPack then
                    'YouTube: ' .. (mw.text.trim(sk.name or '') ~= '' and sk.name or 'skin'))
                    slot:attr('data-skin-tooltip-i18n', mw.text.jsonEncode(tipPack))
            end
                end
 
            if skinTitle ~= "" then
                slot:attr('data-skin-title', skinTitle)
            end
            if tipPack then
                slot:attr('data-skin-tooltip-i18n', mw.text.jsonEncode(tipPack))
            end
 
            -- Sprite container
            local spriteContainer = slot:tag('div'):addClass('podium-sprite-container')
            local spriteDiv = spriteContainer:tag('div'):addClass('podium-sprite')


                -- Sprite container
            if imageFile ~= "" then
                 local spriteContainer = slot:tag('div'):addClass('podium-sprite-container')
                 spriteDiv:wikitext(string.format('[[Arquivo:%s|link=]]', imageFile))
                 local spriteDiv = spriteContainer:tag('div'):addClass('podium-sprite')
            else
                 spriteDiv:wikitext("")
            end


                if imageFile ~= "" then
            -- Tile (piso isométrico)
                    spriteDiv:wikitext(string.format('[[Arquivo:%s|link=]]', imageFile))
            local platform = spriteDiv:tag('div'):addClass('podium-platform')
                else
            local platformTop = platform:tag('div'):addClass('podium-platform-top')
                    spriteDiv:wikitext("")
                end


                -- Tile
            -- Lógica de tile: se tile == "medium", usa SkintileM.png, senão Skintile.png
                local platform = spriteDiv:tag('div'):addClass('podium-platform')
            local tileParam = trim(sk.tile or "")
                 local platformTop = platform:tag('div'):addClass('podium-platform-top')
            local tileFile = "Skintile.png"
            if mw.ustring.lower(tileParam) == "medium" then
                 tileFile = "SkintileM.png"
            end


                local tileParam = trim(sk.tile or "")
            platformTop:wikitext(string.format('[[Arquivo:%s|link=]]', tileFile))
                local tileFile = "Skintile.png"
                if mw.ustring.lower(tileParam) == "medium" then
                    tileFile = "SkintileM.png"
                end


                platformTop:wikitext(string.format('[[Arquivo:%s|link=]]', tileFile))
            -- Aplica estilos inline para posição do tile se vierem parâmetros
            local tileX = trim(sk.tile_x or "")
            local tileY = trim(sk.tile_y or "")


                -- Posição do tile
            local platformStyle = ""
                local tileX = trim(sk.tile_x or "")
            if tileX ~= "" then
                local tileY = trim(sk.tile_y or "")
                platformStyle = platformStyle .. "right:" .. tileX .. "px;"
                local platformStyle = ""
            else
                if tileX ~= "" then
                platformStyle = platformStyle .. "right:-25px;"
                    platformStyle = platformStyle .. "right:" .. tileX .. "px;"
            end
                else
            if tileY ~= "" then
                    platformStyle = platformStyle .. "right:-25px;"
                platformStyle = platformStyle .. "bottom:" .. tileY .. "px;"
                end
            else
                if tileY ~= "" then
                platformStyle = platformStyle .. "bottom:-15px;"
                    platformStyle = platformStyle .. "bottom:" .. tileY .. "px;"
            end
                else
            if platformStyle ~= "" then
                    platformStyle = platformStyle .. "bottom:-15px;"
                local oldPlatformStyle = platform:getAttr('style')
                end
                platform:attr('style', oldPlatformStyle and (oldPlatformStyle .. " " .. platformStyle) or platformStyle)
                if platformStyle ~= "" then
                    platform:attr('style', platformStyle)
                end
             end
             end
         end
         end
Linha 415: Linha 493:
     ----------------------------------------------------------------------------
     ----------------------------------------------------------------------------
     do
     do
         local tierKey = mw.ustring.lower(rawTier or "")
         local key = mw.ustring.lower(rawTier or "")
         local tierMap = {
         local tierMap = {
             bronze = "tier-bronze",
             bronze = "tier-bronze",
Linha 426: Linha 504:
             diamante = "tier-diamond"
             diamante = "tier-diamond"
         }
         }
         local tierClass = tierMap[tierKey]
         local tierClass = tierMap[key]
         if tierClass then
         if tierClass and tierClass ~= "" then
             box:addClass(tierClass)
             box:addClass(tierClass)
         end
         end

Edição das 21h50min de 31 de dezembro de 2025

A documentação para este módulo pode ser criada em Módulo:C.Generate/doc

-- Módulo:C.Generate — função generate()
local p = {}

local utils = require("Módulo:C.Utils")
local i18n = require("Módulo:C.i18n")

local trim = utils.trim
local fileURL = utils.fileURL
local normalizeDim = utils.normalizeDim
local makeAttrString = utils.makeAttrString
local requireCharModule = utils.requireCharModule
local collectJsonObjects = utils.collectJsonObjects
local function ensureFileExists(fileName, fallback)
    fileName = trim(fileName or "")
    if fileName == "" then
        return fallback
    end
    local title = mw.title.new("Arquivo:" .. fileName)
    if title and title.exists then
        return fileName
    end
    return fallback
end

local ATTR_I18N = i18n.ATTR_I18N
local FLAGS_I18N = i18n.FLAGS_I18N
local TAB_I18N = i18n.TAB_I18N
local tierPackFrom = i18n.tierPackFrom
local tagsPackFrom = i18n.tagsPackFrom

-- Importa geradores
local iSkills = require("Módulo:I.Skills")

--------------------------------------------------------------------------------
-- Componente principal
--------------------------------------------------------------------------------

function p.generate(frame)
    local parent = frame:getParent() or frame
    local args = parent.args or {}

    local html = mw.html.create('div')
    local box = html:tag('div'):addClass('character-box')

    -- Requer |module= explícito
    local moduleName = trim(args.module or "")
    if moduleName == "" then
        return "<!-- C.Generate: |module= é obrigatório -->"
    end

    -- Carrega módulo do personagem
    local charData = requireCharModule(moduleName) or {}

    -- Nome: |name= ou |nome= ou do módulo
    local charName = trim(args.name or args.nome or charData.name or "")

    ----------------------------------------------------------------------------
    -- Background (suporta |background= ou |banner= como fallback, ou do módulo)
    ----------------------------------------------------------------------------
    do
        local bgParam = trim(frame:preprocess(args.background or ""))
        if bgParam == "" then
            bgParam = trim(frame:preprocess(args.banner or "")) -- opcional compat
        end
        if bgParam == "" then
            bgParam = charData.background or ""
        end
        if bgParam ~= "" then
            box:attr('data-bg-file', bgParam)
            local url = fileURL(bgParam)
            if url and url ~= "" then
                box:attr('data-bg-url', url)
                -- fallback inline para certos temas
                local style = string.format("--character-bg: url('%s'); background-image: url('%s');", url, url)
                local old = box:getAttr('style')
                box:attr('style', old and (old .. " " .. style) or style)
            end
        end
    end

    ----------------------------------------------------------------------------
    -- Weapon Icon (ícone global do weapon toggle)
    ----------------------------------------------------------------------------
    do
        local weaponIconParam = trim(frame:preprocess(args.weaponicon or ""))
        if weaponIconParam == "" then
            weaponIconParam = charData.weaponicon or ""
        end
        if weaponIconParam ~= "" and weaponIconParam ~= "Nada.png" then
            box:attr('data-weaponicon', weaponIconParam)
        end
    end

    ----------------------------------------------------------------------------
    -- Header
    ----------------------------------------------------------------------------
    local header = box:tag('div'):addClass('character-header')

    -- topbar (avatar + nome + tags)
    local topbar = header:tag('div'):addClass('character-topbar')
    local nameBox = topbar:tag('div'):addClass('character-name-box')

    local avatarImg = ensureFileExists(args.avatar or charData.avatar, "Franky_ts_medal.png")
    nameBox:wikitext(string.format('[[Arquivo:%s|class=topbar-icon|link=|alt=Avatar]]', avatarImg))

    local nameGroup = nameBox:tag('div'):addClass('character-name-group')
    nameGroup:tag('div'):addClass('character-name'):wikitext(charName)

    -- Class tags (TIER + TAGS, com i18n injetada)
    local classTags = nameGroup:tag('div'):addClass('class-tags')

    -- Resolve Tier/Tags em PT (render inicial)
    local rawTier = trim(frame:preprocess(args.tier or ""))
    local rawClasse = trim(frame:preprocess(args.classe or ""))

    -- Se vier tokens tipo "tier*", resolve via módulo
    if rawTier ~= "" and mw.ustring.lower(rawTier):sub(1, 4) == "tier" then
        rawTier = (charData.tier_i18n and charData.tier_i18n.pt) or charData.tier or rawTier
    end
    if rawClasse ~= "" and mw.ustring.lower(rawClasse):sub(1, 5) == "class" then
        local arr = (charData.tags_i18n and charData.tags_i18n.pt) or charData.tags
        if type(arr) == "table" then
            rawClasse = table.concat(arr, " / ")
        end
    end
    -- Se continuar vazio, puxa do módulo do personagem
    if rawTier == "" then
        rawTier = (charData.tier_i18n and charData.tier_i18n.pt) or charData.tier or ""
    end
    if rawClasse == "" then
        local arr = (charData.tags_i18n and charData.tags_i18n.pt) or charData.tags
        if type(arr) == "table" then
            rawClasse = table.concat(arr, " / ")
        else
            rawClasse = arr or ""
        end
    end

    -- Chip de TIER
    local tierDiv
    if rawTier ~= "" then
        tierDiv = classTags:tag('div'):addClass('class-tag tier'):wikitext(rawTier)
    end

    -- Injeta i18n do TIER como data-*
    do
        local tI = charData.tier_i18n
        if type(tI) ~= "table" then
            -- deduz do texto já resolvido (rawTier) ou do charData.tier
            tI = tierPackFrom(rawTier ~= "" and rawTier or (charData.tier or ""))
        else
            -- completa faltantes usando um seed
            local seed = tI.pt or tI.en or tI.es or tI.pl or rawTier or charData.tier or ""
            local base = tierPackFrom(seed)
            tI = {
                pt = tI.pt or base.pt,
                en = tI.en or base.en,
                es = tI.es or base.es,
                pl = tI.pl or base.pl
            }
        end
        if tierDiv then
            tierDiv:attr('data-tier-pt', tI.pt or rawTier):attr('data-tier-en', tI.en or tI.pt or rawTier):attr(
                'data-tier-es', tI.es or tI.pt or rawTier):attr('data-tier-pl', tI.pl or tI.pt or rawTier)
        end
    end

    -- Injeta i18n das TAGS em JSON no container
    do
        local tagsI = nil
        if type(charData.tags_i18n) == "table" then
            -- já tem i18n no módulo → só completa faltantes
            local basis = tagsPackFrom(charData.tags_i18n.pt or charData.tags_i18n.en or charData.tags_i18n.es or
                charData.tags_i18n.pl or {})
            tagsI = {
                pt = charData.tags_i18n.pt or basis.pt,
                en = charData.tags_i18n.en or basis.en,
                es = charData.tags_i18n.es or basis.es,
                pl = charData.tags_i18n.pl or basis.pl
            }
        else
            -- constrói i18n a partir da lista simples (pt ou en que o editor já colocou)
            local baseList = {}
            if type(charData.tags) == "table" then
                baseList = charData.tags
            elseif type(charData.tags) == "string" then
                for entry in mw.text.gsplit(charData.tags, '/', true) do
                    local t = mw.text.trim(entry or '')
                    if t ~= '' then
                        table.insert(baseList, t)
                    end
                end
            end
            tagsI = tagsPackFrom(baseList)
        end
        classTags:attr('data-tags-i18n', mw.text.jsonEncode(tagsI))
    end

    -- Render inicial das TAGS (PT)
    do
        for entry in mw.text.gsplit(rawClasse, '/', true) do
            local clean = mw.text.trim(entry or '')
            if clean ~= '' then
                classTags:tag('div'):addClass('class-tag'):wikitext(clean)
            end
        end
    end

    -- Descrição geral (se houver)
    local descText = args.desc or ""
    if descText == "" then
        if type(charData.desc) == "table" then
            descText = charData.desc.pt or charData.desc.en or charData.desc.es or charData.desc.pl or ""
        else
            descText = tostring(charData.desc or "")
        end
    end
    header:tag('div'):addClass('topbar-description'):wikitext(descText)

    ----------------------------------------------------------------------------
    -- Idioma para tabs (PT padrão + aceita pt-br,en-US,... via |lang=)
    ----------------------------------------------------------------------------
    local rawLang = trim(args.lang or "pt")
    rawLang = mw.ustring.lower(rawLang)
    local baseLang = rawLang:match("^([a-z][a-z])") or rawLang

    -- fallback caso TAB_I18N não exista
    local TAB_MAP = TAB_I18N or {
        pt = {
            skills = "Habilidades",
            skins = "Skins",
            skins_title = "SKINS & SPOTLIGHTS"
        },
        en = {
            skills = "Skills",
            skins = "Skins",
            skins_title = "SKINS & SPOTLIGHTS"
        },
        es = {
            skills = "Habilidades",
            skins = "Aspectos",
            skins_title = "ASPECTOS Y DESTACADOS"
        },
        pl = {
            skills = "Umiejętności",
            skins = "Skórki",
            skins_title = "SKÓRKI I PREZENTACJE"
        }
    }
    local TAB = TAB_MAP[rawLang] or TAB_MAP[baseLang] or TAB_MAP.pt

    ----------------------------------------------------------------------------
    -- Abas (tabs)
    ----------------------------------------------------------------------------
    local tabs = header:tag('div'):addClass('character-tabs')
    tabs:tag('div'):addClass('tab-btn active'):attr('data-tab', 'skills'):wikitext(TAB.skills)
    tabs:tag('div'):addClass('tab-btn'):attr('data-tab', 'skins'):wikitext(TAB.skins)

    ----------------------------------------------------------------------------
    -- Aba: Skills
    ----------------------------------------------------------------------------
    local skillsTab = box:tag('div'):addClass('tab-content active'):attr('id', 'skills')
    local iconBar = skillsTab:tag('div'):addClass('icon-bar')
    local skillsContainer = skillsTab:tag('div'):addClass('skills-container')
    local details = skillsContainer:tag('div'):addClass('skills-details')
    local descBox = details:tag('div'):addClass('desc-box')
    skillsContainer:tag('div'):addClass('video-container'):done()

    skillsTab:attr('data-i18n-attrs', mw.text.jsonEncode(ATTR_I18N))
    skillsTab:attr('data-i18n-flags', mw.text.jsonEncode(FLAGS_I18N))
    if args.lang and trim(args.lang) ~= "" then
        skillsTab:attr('data-i18n-default', baseLang)
    end

    -- Monta ícones de skill: tenta do módulo primeiro, depois de |skills=
    local skillsPacked = args.skills or ""
    if skillsPacked == "" then
        -- Tenta gerar do módulo
        local skillsJSON = iSkills.skill(frame)
        if skillsJSON and skillsJSON ~= "" and skillsJSON ~= "[]" then
            skillsPacked = skillsJSON
        end
    end

    local idx = 0
    for _, chunk in ipairs(collectJsonObjects(skillsPacked)) do
        local ok, sk = pcall(mw.text.jsonDecode, chunk)
        if ok and type(sk) == "table" then
            local name = trim(sk.name or sk.nome or sk.n or "")
            local icon = trim(sk.icon or "")
            local desc = trim(sk.desc or "")
            local level = trim(tostring(sk.level or ""))
            local pve = trim(sk.powerpve or "")
            local pvp = trim(sk.powerpvp or "")
            local energy = trim(sk.energy or "")
            local cd = trim(sk.cooldown or "")
            local video = trim(sk.video or "")
            if icon ~= "" then
                idx = idx + 1
                local attrs = makeAttrString(pve, pvp, energy, cd)

                local iconWrap = iconBar:tag('div'):addClass('skill-icon'):attr('data-index', idx):attr('data-nome',
                    name):attr('data-desc', desc):attr('data-atr', attrs):attr('data-video',
                    (video ~= "" and fileURL(video) or "")):attr('data-video-preload', 'auto'):attr('data-icon-file',
                    icon):attr('data-video-file', video or "")

                -- Level (para "Nível X" no JS)
                if level ~= "" and mw.ustring.upper(level) ~= "NIVEL" then
                    iconWrap:attr('data-level', level)
                end

                -- Descrições i18n (quando vierem do Info)
                if type(sk.desc_i18n) == "table" then
                    iconWrap:attr('data-desc-pt', sk.desc_i18n.pt or ""):attr('data-desc-en', sk.desc_i18n.en or "")
                        :attr('data-desc-es', sk.desc_i18n.es or ""):attr('data-desc-pl', sk.desc_i18n.pl or "")
                elseif desc and desc ~= "" then
                    -- Pelo menos PT
                    iconWrap:attr('data-desc-pt', desc)
                end

                -- Subskills: injeta dados no HTML pro Widget ler
                if type(sk.subs) == "table" and #sk.subs > 0 then
                    iconWrap:attr('data-subs', mw.text.jsonEncode(sk.subs))
                end
                if type(sk.suborder) == "table" and #sk.suborder > 0 then
                    iconWrap:attr('data-suborder', mw.text.jsonEncode(sk.suborder))
                end

                -- flags (características: aggro, bridge, wall, quickcast)
                if type(sk.flags) == "table" and #sk.flags > 0 then
                    iconWrap:attr('data-flags', mw.text.jsonEncode(sk.flags))
                end

                -- weapon (arma equipável que modifica atributos/descrição)
                if type(sk.weapon) == "table" then
                    iconWrap:attr('data-weapon', mw.text.jsonEncode(sk.weapon))
                end
                -- weaponicon (ícone do botão de toggle)
                local weaponIcon = sk.weaponicon or charData.weaponicon or ""
                if weaponIcon ~= "" and weaponIcon ~= "Nada.png" then
                    iconWrap:attr('data-weaponicon', weaponIcon)
                end

                -- Imagem do ícone
                iconWrap:wikitext(string.format('[[Arquivo:%s|class=skill-icon-img|link=]]', icon))

                -- Slot de descrição indexado (o JS usa para sincronizar)
                descBox:tag('div'):addClass('skill-desc'):attr('data-index', idx)
            end
        end
    end

    ----------------------------------------------------------------------------
    -- Aba: Skins (podium isométrico)
    ----------------------------------------------------------------------------
    local skinsTab = box:tag('div'):addClass('tab-content'):attr('id', 'skins')
    local cardSkins = skinsTab:tag('div'):addClass('card-skins')
    -- Título removido conforme requisito

    local podium = cardSkins:tag('div'):addClass('skins-podium')

    local skinsPacked = args.skins or ""
    if skinsPacked == "" then
        -- Tenta gerar do módulo
        local skinsJSON = iSkills.skin(frame)
        if skinsJSON and skinsJSON ~= "" and skinsJSON ~= "[]" then
            skinsPacked = skinsJSON
        end
    end

    local skinIndex = 0
    for _, chunk in ipairs(collectJsonObjects(skinsPacked)) do
        local ok, sk = pcall(mw.text.jsonDecode, chunk)
        if ok and type(sk) == "table" then
            skinIndex = skinIndex + 1
            local imageFile = trim(sk.sprite or "")
            local tooltipRaw = trim(sk.tooltip or "")

            -- Título: vem 100% do editor (|name=)
            local skinTitle = mw.text.trim(sk.name or "")

            -- PT (ou fallback) para render inicial; preserva i18n p/ trocar no JS
            local tipPack, chosen = nil, ""
            if tooltipRaw:match("^%s*{") then
                local ok2, obj2 = pcall(mw.text.jsonDecode, tooltipRaw)
                if ok2 and type(obj2) == "table" then
                    tipPack = obj2
                    chosen = mw.text.trim(obj2.pt or obj2.en or obj2.es or obj2.pl or "")
                end
            end
            if chosen == "" then
                chosen = tooltipRaw
            end

            -- HTML final do tooltip:
            -- 1) Título sem <br>, sem margem (pra não abrir um "buraco")
            local titleHtml = skinTitle ~= "" and
                ('<div class="skin-tooltip-title" style="margin:0">' .. skinTitle .. '</div>') or ""
            -- 2) Descrição com '''bold''' respeitado e TODA a linha em <b> (onde obtém)
            local bodyHtml = chosen:gsub("'''([^']+)'''", "<b>%1</b>"):gsub("\n", "<br>")
            bodyHtml = bodyHtml ~= "" and ('<b>' .. bodyHtml .. '</b>') or ""

            local tooltipHtml = titleHtml .. bodyHtml

            -- Podium slot
            local slot = podium:tag('div'):addClass('podium-slot')
                :attr('data-skin-tooltip', tooltipHtml)
                :attr('data-skin-index', skinIndex)

            -- Aplica deslocamento horizontal via data-attribute
            -- O JavaScript no widget aplicará o estilo para garantir que funcione
            local offsetXStr = trim(sk.offset_x or "")
            if offsetXStr ~= "" and offsetXStr ~= "0" then
                local offsetX = tonumber(offsetXStr)
                if offsetX and offsetX ~= 0 then
                    -- Garante que o valor seja uma string válida
                    slot:attr('data-offset-x', tostring(offsetX))
                end
            end

            -- Spotlight do YouTube (parametro |youtube= na Predefinição:Skin)
            local yt = trim(sk.youtube or "")
            if yt ~= "" then
                -- normaliza ID curto pra URL completa (ex.: "dQw4w9WgXcQ" -> "https://youtu.be/dQw4w9WgXcQ")
                if not yt:match("^https?://") then
                    if yt:match("^[%w%-%_]+$") then
                        yt = "https://youtu.be/" .. yt
                    else
                        yt = "https://" .. yt -- fallback besta se vier "www.youtube.com/..."
                    end
                end

                slot:attr('data-youtube', yt):addClass('is-clickable')
                    :attr('tabindex', '0')
                    :attr('role', 'button'):attr('aria-label',
                    'YouTube: ' .. (mw.text.trim(sk.name or '') ~= '' and sk.name or 'skin'))
            end

            if skinTitle ~= "" then
                slot:attr('data-skin-title', skinTitle)
            end
            if tipPack then
                slot:attr('data-skin-tooltip-i18n', mw.text.jsonEncode(tipPack))
            end

            -- Sprite container
            local spriteContainer = slot:tag('div'):addClass('podium-sprite-container')
            local spriteDiv = spriteContainer:tag('div'):addClass('podium-sprite')

            if imageFile ~= "" then
                spriteDiv:wikitext(string.format('[[Arquivo:%s|link=]]', imageFile))
            else
                spriteDiv:wikitext("")
            end

            -- Tile (piso isométrico)
            local platform = spriteDiv:tag('div'):addClass('podium-platform')
            local platformTop = platform:tag('div'):addClass('podium-platform-top')

            -- Lógica de tile: se tile == "medium", usa SkintileM.png, senão Skintile.png
            local tileParam = trim(sk.tile or "")
            local tileFile = "Skintile.png"
            if mw.ustring.lower(tileParam) == "medium" then
                tileFile = "SkintileM.png"
            end

            platformTop:wikitext(string.format('[[Arquivo:%s|link=]]', tileFile))

            -- Aplica estilos inline para posição do tile se vierem parâmetros
            local tileX = trim(sk.tile_x or "")
            local tileY = trim(sk.tile_y or "")

            local platformStyle = ""
            if tileX ~= "" then
                platformStyle = platformStyle .. "right:" .. tileX .. "px;"
            else
                platformStyle = platformStyle .. "right:-25px;"
            end
            if tileY ~= "" then
                platformStyle = platformStyle .. "bottom:" .. tileY .. "px;"
            else
                platformStyle = platformStyle .. "bottom:-15px;"
            end
            if platformStyle ~= "" then
                local oldPlatformStyle = platform:getAttr('style')
                platform:attr('style', oldPlatformStyle and (oldPlatformStyle .. " " .. platformStyle) or platformStyle)
            end
        end
    end

    ----------------------------------------------------------------------------
    -- Tier -> classe CSS (visual)
    ----------------------------------------------------------------------------
    do
        local key = mw.ustring.lower(rawTier or "")
        local tierMap = {
            bronze = "tier-bronze",
            bronce = "tier-bronze",
            silver = "tier-silver",
            prata = "tier-silver",
            gold = "tier-gold",
            ouro = "tier-gold",
            diamond = "tier-diamond",
            diamante = "tier-diamond"
        }
        local tierClass = tierMap[key]
        if tierClass and tierClass ~= "" then
            box:addClass(tierClass)
        end
    end

    ----------------------------------------------------------------------------
    -- Retorno
    ----------------------------------------------------------------------------
    return tostring(html)
end

return p