Mudanças entre as edições de "Módulo:Teste"

De Wiki Gla
Ir para navegação Ir para pesquisar
m
Etiqueta: Revertido
m (bannerzin)
 
(57 revisões intermediárias por 3 usuários não estão sendo mostradas)
Linha 1: Linha 1:
local p = {}
local p = {}


function p.skin(frame)
-- Parseia bau no formato "2 comum, 8 ouro" ou "8 ouro, 2 comum". Retorna comum, ouro (números) ou nil,nil se for só tipo (comum/ouro).
    local a = frame.args
local function parseBau(s)
     local obj = {
     if not s or s == '' then return nil, nil end
        sprite = a.sprite or '',
    s          = mw.text.trim(s)
        background = a.background or '',
     local comum = tonumber(s:match('(%d+)%s*[Cc]omum')) or 0
        tooltip = a.tooltip or ''
    local ouro  = tonumber(s:match('(%d+)%s*[Oo]uro')) or 0
    }
    if comum > 0 or ouro > 0 then
    return mw.text.jsonEncode(obj)
         return comum, ouro
end
     end
 
     return nil, nil
function p.skill(frame)
     local a = frame.args
    local obj = {
        name = a.name or a.nome or '',
        icon = a.icon or '',
        level = tonumber(a.level) or nil,
        desc = a.desc or '',
        energy = a.energy or nil,
        powerpve = a.powerpve or nil,
        powerpvp = a.powerpvp or nil,
         cooldown = a.cooldown or nil,
        video = a.video or ''
     }
     return mw.text.jsonEncode(obj)
end
end


function p.generate(frame)
function p.main(frame)
     local args = frame:getParent().args
     local args = frame:getParent().args
     local html = mw.html.create('div')
     local cards = {}
    local function getVideoURL(filename)
        return tostring(mw.uri.fullUrl('Special:FilePath/' .. filename))
    end
    local tier = (args.tier or ""):lower()
    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[tier]
    local box = html:tag('div'):addClass('personaje-box')
    if tierClass then
        box:addClass(tierClass)
    end
    local header = box:tag('div'):addClass('personaje-header')
    local topbar = header:tag('div'):addClass('personaje-topbar')
    local nomeBox = topbar:tag('div'):addClass('personaje-nome-box')
 
    local avatarImg = args.avatar or 'Franky_ts_medal.png'
    nomeBox:wikitext(string.format('[[Arquivo:%s|class=topbar-icon|link=|alt=Medal]]', avatarImg))
 
    local nomeCat = nomeBox:tag('div'):addClass('personaje-nome-category')
    nomeCat:tag('div'):addClass('nome'):wikitext(args.nome or 'Franky (TS)')
    local classesDiv = nomeCat:tag('div'):addClass('classes')
    -- Dividir clases por "/"
    local classeString = args.classe or ''
    local tierUpper = tier:gsub("^%l", string.upper)
    classesDiv:tag('div'):addClass('classe tier'):wikitext(tierUpper)
    for classe in mw.text.gsplit(classeString, '/', true) do
        classesDiv:tag('div'):addClass('classe'):wikitext(classe)
    end
 
    header:tag('div'):addClass('topbar-description'):wikitext(args.desc)
 
    local banner = args.banner or ''
    local bannerFile = mw.title.new('Arquivo:' .. banner)
    if bannerFile and bannerFile.exists then
        header:tag('div'):addClass('banner'):wikitext(string.format(
            '[[Arquivo:%s|class=banner-personaje|link=|alt=Artwork do personagem]]', banner))
    else
        header:tag('div'):addClass('banner')
    end
 
    local tabs = header:tag('div'):addClass('personaje-tabs')
    tabs:tag('div'):addClass('tab-btn active'):attr('data-tab', 'habilidades'):wikitext('Habilidades')
    tabs:tag('div'):addClass('tab-btn'):attr('data-tab', 'skins'):wikitext('Skins')
 
    local artImg = args.artwork or 'Franky_ts_splash.png'
    header:tag('div'):css('text-align', 'center'):wikitext(string.format(
        '[[Arquivo:%s|class=art-personaje|link=|alt=Arte do personagem]]', artImg))
 
    -- HABILIDADE
    local habilidadesTab = box:tag('div'):addClass('tab-content active'):attr('id', 'habilidades')
    local cuadros = habilidadesTab:tag('div'):addClass('cuadros-container')
    local habilidadesContainer = habilidadesTab:tag('div'):addClass('habilidades-container')
 
    local details = habilidadesContainer:tag('div'):addClass('habilidades-details')
    local descripcionContainer = details:tag('div'):addClass('descripcion-container')
    -- ====== NOVO: bloco de skills via subtemplate ======
    local skillsPacked = args.skills
    local usedSkills = false
    if skillsPacked and skillsPacked:match("{") then
        -- Concat de objetos JSON: ...}{...}{...  -> ...},{...},{...
        local arr = "[" .. skillsPacked:gsub("}%s*{", "},{") .. "]"
        local ok, parsed = pcall(mw.text.jsonDecode, arr)
        if ok and type(parsed) == "table" and #parsed > 0 then
            usedSkills = true
            for i, sk in ipairs(parsed) do
                local nome = sk.name or sk.nome
                if nome and nome ~= "" then
                    local icon = sk.icon or ""
                    local level = sk.level or ""
                    local desc = sk.desc or ""
                    -- monta a string de atributos no formato esperado pelo JS:
                    -- PVE, PVP, Energia, Recarga
                    local atr = table.concat({sk.powerpve or "-", sk.powerpvp or "-", sk.energy or "-",
                                              sk.cooldown or "-"}, ", ")


                    local rawVideo = sk.video or ""
    local i = 1
                    local videoURL = rawVideo ~= "" and getVideoURL(rawVideo) or ""
    while true do
        local nome = args['nome' .. i]
        if not nome or mw.text.trim(nome) == '' then break end


                    cuadros:tag('div'):addClass('cuadro'):attr('data-index', i):attr('data-nome', nome):attr(
        local link        = mw.text.trim(args['link' .. i] or '')
                        'data-desc', desc):attr('data-atr', atr):attr('data-video', videoURL):attr('data-video-preload',
        local img        = mw.text.trim(args['img' .. i] or '')
                        'auto'):wikitext(string.format("[[Arquivo:%s|class=habilidad-icon|link=]]", icon))
        local qtd        = mw.text.trim(args['qtd' .. i] or '0')
        local bauParam    = mw.text.trim(args['bau' .. i] or 'comum')


                    descripcionContainer:tag('div'):addClass('habilidad-descripcion'):attr('data-index', i)
        local comum, ouro = parseBau(bauParam)
                 end
        if comum == nil and ouro == nil then
            -- Modo antigo: bau = comum ou ouro, qtd = quantidade
            local n = tonumber(qtd) or 0
            if bauParam:lower() == 'ouro' then
                comum, ouro = 0, n
            else
                 comum, ouro = n, 0
             end
             end
         end
         end
    end


    -- ====== Fallback: mantém suporte aos hab1..hab21 se não usar 'skills' ======
        local href      = tostring(mw.uri.localUrl(link))
    if not usedSkills then
         local comumHtml = frame:preprocess('[[File:Chest_normal.png|link=]]')
         for i = 1, 21 do
        local ouroHtml  = frame:preprocess('[[File:Chest_gold.png|link=]]')
            local nome = args['hab' .. i .. '-nome']
            if nome then
                local icon = args['hab' .. i .. '-icon'] or ''
                local level = args['hab' .. i .. '-level'] or ''
                local desc = args['hab' .. i .. '-desc'] or ''
                local atr = args['hab' .. i .. '-atr'] or ''
                local rawVideo = args['hab' .. i .. '-video'] or ''
                local videoURL = rawVideo ~= '' and getVideoURL(rawVideo) or ''


                cuadros:tag('div'):addClass('cuadro'):attr('data-index', i):attr('data-nome', nome):attr('data-desc',
        -- Banner 380x80: fundo = img da ilha, baus canto superior esquerdo, título canto inferior esquerdo
                    desc):attr('data-atr', atr):attr('data-video', videoURL):attr('data-video-preload', 'auto')
        local banner    = mw.html.create('span')
                    :wikitext(string.format("[[Arquivo:%s|class=habilidad-icon|link=]]", icon))
        banner:attr('class', 'island-banner')
            :attr('data-href', href)
            :attr('data-bgimg', img)
            :attr('role', 'link')
            :attr('tabindex', '0')


                descripcionContainer:tag('div'):addClass('habilidad-descripcion'):attr('data-index', i)
        local chests = banner:tag('span'):attr('class', 'island-chests')
            end
        if comum > 0 then
            chests:tag('span'):attr('class', 'island-chest-group')
                :node(mw.html.create(''):wikitext(comumHtml))
                :tag('span'):attr('class', 'island-chest-count'):wikitext(tostring(comum))
         end
         end
    end
         if ouro > 0 then
 
             chests:tag('span'):attr('class', 'island-chest-group')
    for i = 1, 21 do
                :node(mw.html.create(''):wikitext(ouroHtml))
        local nome = args['hab' .. i .. '-nome']
                 :tag('span'):attr('class', 'island-chest-count'):wikitext(tostring(ouro))
         if nome then
             local icon = args['hab' .. i .. '-icon'] or ''
            local level = args['hab' .. i .. '-level'] or ''
            local desc = args['hab' .. i .. '-desc'] or ''
            local atr = args['hab' .. i .. '-atr'] or ''
            local rawVideo = args['hab' .. i .. '-video'] or ''
            local videoURL = rawVideo ~= '' and getVideoURL(rawVideo) or ''
 
            cuadros:tag('div'):addClass('cuadro'):attr('data-index', i):attr('data-nome', nome):attr('data-desc', desc)
                 :attr('data-atr', atr):attr('data-video', videoURL):attr('data-video-preload', 'auto'):wikitext(
                    string.format("[[Arquivo:%s|class=habilidad-icon|link=]]", icon))
 
            descripcionContainer:tag('div'):addClass('habilidad-descripcion'):attr('data-index', i)
         end
         end
    end


    details:done()
        banner:tag('span'):attr('class', 'island-title'):wikitext(nome)
    habilidadesContainer:tag('div'):addClass('video-container'):done()
    habilidadesTab:done()


    -- SKINS
         cards[#cards + 1] = banner
    local skinsTab = box:tag('div'):addClass('tab-content'):attr('id', 'skins')
         i = i + 1
    local cardSkins = skinsTab:tag('div'):addClass('card-skins')
 
    cardSkins:tag('span'):addClass('card-skins-title'):wikitext('SKINS & SPOTLIGHTS')
 
    local wrapper = cardSkins:tag('div'):addClass('skins-carousel-wrapper')
    wrapper:tag('div'):addClass('skins-arrow left'):wikitext('«')
 
    local carousel = wrapper:tag('div'):addClass('skins-carousel')
    -- ====== NOVO: bloco de skins via subtemplate (robusto) ======
    local skinsPacked = args.skins
    local usedSkins = false
    if skinsPacked and skinsPacked:find("{", 1, true) then
         local count = 0
        for obj in skinsPacked:gmatch("%b{}") do
            local ok, sk = pcall(mw.text.jsonDecode, obj)
            if ok and type(sk) == "table" then
                count = count + 1
                local banner = sk.background or ''
                local image = sk.sprite or ''
                local tooltipRaw = sk.tooltip or ''
                local tooltipHtml = tooltipRaw:gsub("'''([^']+)'''", "<b>%1</b>"):gsub("\n", "<br>")
 
                local skinCard = carousel:tag('div'):addClass(
                    'skin-card simple-tooltip simple-tooltip-inline tooltipstered'):attr('data-simple-tooltip',
                    tooltipHtml)
 
                skinCard:tag('div'):addClass('skins--imageBanner'):wikitext(banner ~= '' and
                                                                                string.format("[[Arquivo:%s|link=]]",
                        banner) or ''):attr('alt', 'banner')
 
                skinCard:tag('div'):addClass('skins--imageSkin'):wikitext(image ~= '' and
                                                                              string.format("[[Arquivo:%s|link=]]",
                        image) or ''):attr('alt', 'skin')
            end
         end
        if count > 0 then
            usedSkins = true
        end
     end
     end


     -- ====== Fallback antigo (só roda se não vierem skins novas) ======
     local grid = mw.html.create('div')
    if not usedSkins then
    grid:attr('class', 'island-grid')
        for j = 1, 11 do
    for _, card in ipairs(cards) do
            local image = args['skin' .. j .. '-image']
         grid:node(card)
            if image then
                local banner = args['skin' .. j .. '-banner'] or ''
                local tooltipRaw = args['skin' .. j .. '-tooltip'] or ''
                local tooltipHtml = tooltipRaw:gsub("'''([^']+)'''", "<b>%1</b>"):gsub("\n", "<br>")
 
                local skinCard = carousel:tag('div'):addClass(
                    'skin-card simple-tooltip simple-tooltip-inline tooltipstered'):attr('data-simple-tooltip',
                    tooltipHtml)
 
                skinCard:tag('div'):addClass('skins--imageBanner'):wikitext(banner ~= '' and
                                                                                string.format("[[Arquivo:%s|link=]]",
                        banner) or ''):attr('alt', 'banner')
 
                skinCard:tag('div'):addClass('skins--imageSkin'):wikitext(string.format("[[Arquivo:%s|link=]]", image))
                    :attr('alt', 'skin')
            end
        end
    end
 
    for j = 1, 11 do
         local image = args['skin' .. j .. '-image']
        if image then
            local banner = args['skin' .. j .. '-banner'] or ''
            local tooltip = args['skin' .. j .. '-tooltip'] or ''
            local tooltipRaw = args['skin' .. j .. '-tooltip'] or ''
            local tooltipHtml = tooltipRaw:gsub("'''([^']+)'''", "<b>%1</b>")
            tooltipHtml = tooltipHtml:gsub("\n", "<br>")
 
            local skinCard = carousel:tag('div')
                :addClass('skin-card simple-tooltip simple-tooltip-inline tooltipstered'):attr('data-simple-tooltip',
                    tooltipHtml)
 
            skinCard:tag('div'):addClass('skins--imageBanner'):wikitext(string.format("[[Arquivo:%s|link=]]", banner))
                :attr('alt', 'banner')
 
            skinCard:tag('div'):addClass('skins--imageSkin'):wikitext(string.format("[[Arquivo:%s|link=]]", image))
                :attr('alt', 'skin')
        end
     end
     end


    wrapper:tag('div'):addClass('skins-arrow right'):wikitext('»')
     return tostring(grid)
 
     return tostring(html)
end
end


return p
return p

Edição atual tal como às 23h47min de 12 de março de 2026

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

local p = {}

-- Parseia bau no formato "2 comum, 8 ouro" ou "8 ouro, 2 comum". Retorna comum, ouro (números) ou nil,nil se for só tipo (comum/ouro).
local function parseBau(s)
    if not s or s == '' then return nil, nil end
    s           = mw.text.trim(s)
    local comum = tonumber(s:match('(%d+)%s*[Cc]omum')) or 0
    local ouro  = tonumber(s:match('(%d+)%s*[Oo]uro')) or 0
    if comum > 0 or ouro > 0 then
        return comum, ouro
    end
    return nil, nil
end

function p.main(frame)
    local args = frame:getParent().args
    local cards = {}

    local i = 1
    while true do
        local nome = args['nome' .. i]
        if not nome or mw.text.trim(nome) == '' then break end

        local link        = mw.text.trim(args['link' .. i] or '')
        local img         = mw.text.trim(args['img' .. i] or '')
        local qtd         = mw.text.trim(args['qtd' .. i] or '0')
        local bauParam    = mw.text.trim(args['bau' .. i] or 'comum')

        local comum, ouro = parseBau(bauParam)
        if comum == nil and ouro == nil then
            -- Modo antigo: bau = comum ou ouro, qtd = quantidade
            local n = tonumber(qtd) or 0
            if bauParam:lower() == 'ouro' then
                comum, ouro = 0, n
            else
                comum, ouro = n, 0
            end
        end

        local href      = tostring(mw.uri.localUrl(link))
        local comumHtml = frame:preprocess('[[File:Chest_normal.png|link=]]')
        local ouroHtml  = frame:preprocess('[[File:Chest_gold.png|link=]]')

        -- Banner 380x80: fundo = img da ilha, baus canto superior esquerdo, título canto inferior esquerdo
        local banner    = mw.html.create('span')
        banner:attr('class', 'island-banner')
            :attr('data-href', href)
            :attr('data-bgimg', img)
            :attr('role', 'link')
            :attr('tabindex', '0')

        local chests = banner:tag('span'):attr('class', 'island-chests')
        if comum > 0 then
            chests:tag('span'):attr('class', 'island-chest-group')
                :node(mw.html.create(''):wikitext(comumHtml))
                :tag('span'):attr('class', 'island-chest-count'):wikitext(tostring(comum))
        end
        if ouro > 0 then
            chests:tag('span'):attr('class', 'island-chest-group')
                :node(mw.html.create(''):wikitext(ouroHtml))
                :tag('span'):attr('class', 'island-chest-count'):wikitext(tostring(ouro))
        end

        banner:tag('span'):attr('class', 'island-title'):wikitext(nome)

        cards[#cards + 1] = banner
        i = i + 1
    end

    local grid = mw.html.create('div')
    grid:attr('class', 'island-grid')
    for _, card in ipairs(cards) do
        grid:node(card)
    end

    return tostring(grid)
end

return p