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)
 
(67 revisões intermediárias por 3 usuários não estão sendo mostradas)
Linha 1: Linha 1:
local p = {}
local p = {}


function p.ficha(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 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 args = frame:getParent().args
     local html = mw.html.create('div')
     local cards = {}
   
 
    local function getVideoURL(filename)
    local i = 1
         if filename and filename ~= "" then
    while true do
            return tostring(mw.uri.fullUrl('Special:FilePath/' .. filename))
        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
         end
        return ""
    end


    -- Header básico
        local href      = tostring(mw.uri.localUrl(link))
    local box = html:tag('div'):addClass('character-box')
        local comumHtml = frame:preprocess('[[File:Chest_normal.png|link=]]')
    box:tag('h2'):wikitext(args.nome or 'Personagem')
        local ouroHtml  = frame:preprocess('[[File:Chest_gold.png|link=]]')
    box:tag('div'):addClass('character-tier'):wikitext(args.tier or '')
    box:tag('div'):addClass('character-class'):wikitext(args.classe or '')
    box:tag('div'):addClass('character-desc'):wikitext(args.desc or '')
    box:tag('div'):wikitext(string.format('[[Arquivo:%s|200px]]', args.image or ''))


    -- Barra de habilidades
        -- Banner 380x80: fundo = img da ilha, baus canto superior esquerdo, título canto inferior esquerdo
    local skills = {}
         local banner    = mw.html.create('span')
    for i = 1, 20 do
         banner:attr('class', 'island-banner')
         local nome = args['hab'..i..'-nome']
             :attr('data-href', href)
         if not nome or nome == '' then break end
             :attr('data-bgimg', img)
        table.insert(skills, {
             :attr('role', 'link')
             nome = nome,
             :attr('tabindex', '0')
            desc = args['hab'..i..'-desc'] or '',
             icon = args['hab'..i..'-icon'] or '',
             video = getVideoURL(args['hab'..i..'-video'] or ''),
             atr = args['hab'..i..'-atr'] or ''
        })
    end


    -- Exibe barra de skills
        local chests = banner:tag('span'):attr('class', 'island-chests')
    local skillBar = box:tag('div'):addClass('skills-bar')
        if comum > 0 then
    for idx, s in ipairs(skills) do
            chests:tag('span'):attr('class', 'island-chest-group')
        skillBar:tag('div')
                :node(mw.html.create(''):wikitext(comumHtml))
            :addClass('skill-icon')
                :tag('span'):attr('class', 'island-chest-count'):wikitext(tostring(comum))
            :attr('data-index', idx)
        end
            :attr('data-nome', s.nome)
        if ouro > 0 then
             :attr('data-desc', s.desc)
             chests:tag('span'):attr('class', 'island-chest-group')
            :attr('data-video', s.video)
                :node(mw.html.create(''):wikitext(ouroHtml))
            :attr('data-atr', s.atr)
                :tag('span'):attr('class', 'island-chest-count'):wikitext(tostring(ouro))
            :wikitext(string.format('[[Arquivo:%s|50px|link=]]', s.icon))
        end
    end


    -- Área da descrição dinâmica (preenchida pelo JS)
        banner:tag('span'):attr('class', 'island-title'):wikitext(nome)
    box:tag('div'):addClass('skill-detail'):wikitext('Selecione uma habilidade acima')


    -- Skins (carousel ou lista simples)
         cards[#cards + 1] = banner
    local skins = {}
         i = i + 1
    for j = 1, 10 do
         local img = args['skin'..j..'-image']
        if not img or img == '' then break end
         table.insert(skins, {
            image = img,
            banner = args['skin'..j..'-banner'] or '',
            tooltip = args['skin'..j..'-tooltip'] or ''
        })
     end
     end
     if #skins > 0 then
 
        local skinBar = box:tag('div'):addClass('skin-bar')
     local grid = mw.html.create('div')
        for _, s in ipairs(skins) do
    grid:attr('class', 'island-grid')
            local card = skinBar:tag('div'):addClass('skin-card')
    for _, card in ipairs(cards) do
            card:wikitext(string.format('[[Arquivo:%s|60px|link=]]', s.image))
        grid:node(card)
            if s.tooltip and s.tooltip ~= "" then
                card:attr('title', s.tooltip)
            end
        end
     end
     end


     return tostring(html)
     return tostring(grid)
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