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

De Wiki Gla
Ir para navegação Ir para pesquisar
Etiqueta: Revertido
m
 
(2 revisões intermediárias por um outro usuário não estão sendo mostradas)
Linha 1: Linha 1:
local p = {}
local p = {}
local Item = require("Módulo:Item")


local BAU_IMAGENS = {
local BAU_IMAGENS = {
Linha 5: Linha 6:
     ouro  = 'GoldChest.png'
     ouro  = 'GoldChest.png'
}
}
local function formatNumber(num)
    num = tonumber(num) or 0
    if num >= 1e9 then
        return string.format("%.0f", num / 1e6) .. "KKK"
    elseif num >= 1e6 then
        return string.format("%.0f", num / 1e6) .. "KK"
    elseif num >= 1e4 then
        return string.format("%.0f", num / 1e3) .. "K"
    else
        local s = tostring(num)
        return s:reverse():gsub("(%d%d%d)", "%1,"):reverse():gsub("^,", "")
    end
end
local function parseItemEntry(entry)
    entry = mw.text.trim(entry)
    if entry == "" then return nil, nil end
    local ident, qtdStr
    if entry:find(";") then
        ident, qtdStr = entry:match("^(.-)%s*;%s*(%d+)$")
    else
        ident, qtdStr = entry:match("^(.-)%s*:%s*(%d+)$")
    end
    if not ident or not qtdStr then return nil, nil end
    return mw.text.trim(ident), tonumber(qtdStr)
end
local function renderRewards(itensRaw, lang)
    if not itensRaw or itensRaw == "" then return "" end
    local parts = {}
    for entry in mw.text.gsplit(itensRaw, ",", true) do
        local ident, qtdNum = parseItemEntry(entry)
        if ident and qtdNum then
            local item = Item.resolve(ident)
            if not item then
                item = {
                    id = 0,
                    image = ident:match("%.%w+$") and ident or (ident .. ".png"),
                    names = { pt = ident, en = ident },
                    category = "unknown"
                }
            end
            local qtdFormatada = formatNumber(qtdNum)
            parts[#parts + 1] = Item.renderOne(item, qtdFormatada, lang, {
                showTooltip = true,
                showCount = true
            })
        end
    end
    return table.concat(parts)
end


function p.render(frame)
function p.render(frame)
     local args = frame:getParent().args
     local args = frame:getParent().args
     local nome = mw.text.trim(args['nome'] or '')
     local nome = mw.text.trim(args['nome'] or '')
     local uid = 'lk' .. math.random(10000, 99999)
     local lang = mw.text.trim(args['lang'] or 'pt')


     local root = mw.html.create('div'):attr('class', 'lk-wrap')
     local root = mw.html.create('div'):attr('class', 'lk-wrap')
    root:tag('span'):attr('class', 'lk-theme-btn'):wikitext('☾ Dark')


     if nome ~= '' then
     if nome ~= '' then
Linha 28: Linha 91:
     if #baus == 0 then return tostring(root) end
     if #baus == 0 then return tostring(root) end


    -- Radio inputs ocultos para tabs principais
    for idx, n in ipairs(baus) do
        local radio = root:tag('input')
            :attr('type', 'radio')
            :attr('name', uid .. '-tab')
            :attr('id', uid .. '-tab-' .. n)
            :attr('class', 'lk-radio')
        if idx == 1 then radio:attr('checked', 'checked') end
    end
    -- Tab labels
     local tabs = root:tag('div'):attr('class', 'lk-tabs')
     local tabs = root:tag('div'):attr('class', 'lk-tabs')
     for idx, n in ipairs(baus) do
     for idx, n in ipairs(baus) do
         local tipo  = mw.text.trim(args['bau' .. n .. 'tipo'] or '')
         local tipo  = mw.text.trim(args['bau' .. n .. 'tipo'] or '')
         local tabImg = BAU_IMAGENS[tipo] or ''
         local tabImg = BAU_IMAGENS[tipo] or ''
         local label = tabs:tag('label')
         local tab    = tabs:tag('span')
             :attr('class', 'lk-tab')
             :attr('class', idx == 1 and 'lk-tab active' or 'lk-tab')
             :attr('for', uid .. '-tab-' .. n)
             :attr('data-tab', 'b' .. n)
         if tabImg ~= '' then
         if tabImg ~= '' then
             label:node(mw.html.create(''):wikitext('[[File:' .. tabImg .. '|20px|link=]]'))
             tab:node(mw.html.create(''):wikitext('[[File:' .. tabImg .. '|20px|link=]]'))
         end
         end
         label:tag('span'):wikitext('Baú ' .. string.format('%02d', n))
         tab:tag('span'):wikitext('Baú ' .. string.format('%02d', n))
     end
     end


    -- Painéis
     for idx, n in ipairs(baus) do
     for idx, n in ipairs(baus) do
         local px    = 'bau' .. n
         local px    = 'bau' .. n
         local tipo  = mw.text.trim(args[px .. 'tipo'] or '')
         local tipo  = mw.text.trim(args[px .. 'tipo'] or '')
        local itens = mw.text.trim(args[px .. 'itens'] or '')
         local video = mw.text.trim(args[px .. 'video'] or '')
         local video = mw.text.trim(args[px .. 'video'] or '')
         local rota  = mw.text.trim(args[px .. 'rota'] or '')
         local rota  = mw.text.trim(args[px .. 'rota'] or '')


         local panel = root:tag('div')
         local panel = root:tag('div')
             :attr('class', 'lk-panel')
             :attr('class', idx == 1 and 'lk-panel active' or 'lk-panel')
             :attr('id', uid .. '-panel-' .. n)
             :attr('data-panel', 'b' .. n)


        -- Recompensas
         local rsec = panel:tag('div')
         local rsec = panel:tag('div')
         rsec:tag('div'):attr('class', 'lk-slabel'):wikitext('Recompensas')
         rsec:tag('div'):attr('class', 'lk-slabel'):wikitext('Recompensas')
         local grid = rsec:tag('div'):attr('class', 'lk-rewards')
         local grid = rsec:tag('div'):attr('class', 'lk-rewards reward-items')


         local j = 1
         grid:wikitext(renderRewards(itens, lang))
        while true do
            local qty  = mw.text.trim(args[px .. 'reward'    .. j] or '')
            local rimg = mw.text.trim(args[px .. 'rewardimg' .. j] or '')
            if qty == '' and rimg == '' then break end
            local item  = grid:tag('div'):attr('class', 'lk-reward')
            local sprite = item:tag('div'):attr('class', 'lk-rsprite')
            if rimg ~= '' then
                sprite:node(mw.html.create(''):wikitext('[[File:' .. rimg .. '|36px|link=]]'))
            end
            if qty ~= '' then
                local num, sufixo = qty:match('^(%d+)(.*)')
                if num then
                    local qspan = item:tag('span'):attr('class', 'lk-rqty')
                    qspan:tag('span'):attr('class', 'lk-rqty-num'):wikitext(num)
                    qspan:tag('span'):attr('class', 'lk-rqty-x'):wikitext(sufixo ~= '' and sufixo or 'x')
                else
                    item:tag('span'):attr('class', 'lk-rqty'):wikitext(qty)
                end
            end
            j = j + 1
        end


        -- Seção "Como chegar"
         if video ~= '' or rota ~= '' then
         if video ~= '' or rota ~= '' then
             panel:tag('div'):attr('class', 'lk-divider')
             panel:tag('div'):attr('class', 'lk-divider')
             local csec = panel:tag('div'):attr('class', 'lk-media-section')
             local csec = panel:tag('div')
             csec:tag('div'):attr('class', 'lk-slabel'):wikitext('Como chegar')
             csec:tag('div'):attr('class', 'lk-slabel'):wikitext('Como chegar')
            local subuid = uid .. 'c' .. n
            -- Sub-radios
            if video ~= '' then
                local vr = csec:tag('input')
                    :attr('type', 'radio')
                    :attr('name', subuid)
                    :attr('id', subuid .. '-v')
                    :attr('class', 'lk-radio')
                    :attr('checked', 'checked')
            end
            if rota ~= '' and video == '' then
                csec:tag('input')
                    :attr('type', 'radio')
                    :attr('name', subuid)
                    :attr('id', subuid .. '-r')
                    :attr('class', 'lk-radio')
                    :attr('checked', 'checked')
            elseif rota ~= '' then
                csec:tag('input')
                    :attr('type', 'radio')
                    :attr('name', subuid)
                    :attr('id', subuid .. '-r')
                    :attr('class', 'lk-radio')
            end


             local ctabs = csec:tag('div'):attr('class', 'lk-ctabs')
             local ctabs = csec:tag('div'):attr('class', 'lk-ctabs')
             if video ~= '' then
             if video ~= '' then
                 ctabs:tag('label')
                 ctabs:tag('span')
                     :attr('class', 'lk-ctab')
                     :attr('class', 'lk-ctab active')
                     :attr('for', subuid .. '-v')
                     :attr('data-ctab', 'v' .. n)
                     :wikitext('Vídeo')
                     :wikitext('Vídeo')
             end
             end
             if rota ~= '' then
             if rota ~= '' then
                 ctabs:tag('label')
                 ctabs:tag('span')
                     :attr('class', 'lk-ctab')
                     :attr('class', video ~= '' and 'lk-ctab' or 'lk-ctab active')
                     :attr('for', subuid .. '-r')
                     :attr('data-ctab', 'r' .. n)
                     :wikitext('Imagem')
                     :wikitext('Imagem')
             end
             end
Linha 139: Linha 142:
             if video ~= '' then
             if video ~= '' then
                 local vpanel = csec:tag('div')
                 local vpanel = csec:tag('div')
                     :attr('class', 'lk-cpanel')
                     :attr('class', 'lk-cpanel active')
                     :attr('id', subuid .. '-vp')
                     :attr('data-cpanel', 'v' .. n)
                 vpanel:tag('div'):attr('class', 'lk-media-wrap')
                 local mwrap = vpanel:tag('div'):attr('class', 'lk-media-wrap')
                    :tag('iframe')
                mwrap:attr('data-video', video)
                        :attr('src', 'https://www.youtube.com/embed/' .. video)
                        :attr('allowfullscreen', '')
                        :attr('frameborder', '0')
             end
             end


             if rota ~= '' then
             if rota ~= '' then
                 local rpanel = csec:tag('div')
                 local rpanel = csec:tag('div')
                     :attr('class', 'lk-cpanel')
                     :attr('class', video ~= '' and 'lk-cpanel' or 'lk-cpanel active')
                     :attr('id', subuid .. '-rp')
                     :attr('data-cpanel', 'r' .. n)


                 local slider = rpanel:tag('div'):attr('class', 'lk-slider')
                 local slider = rpanel:tag('div'):attr('class', 'lk-slider')
                 local track  = slider:tag('div'):attr('class', 'lk-slider-track')
                 local track  = slider:tag('div'):attr('class', 'lk-slider-track')
                 local imgs = mw.text.split(rota, '%s*,%s*')
 
                 local total = 0
                 local imgs   = mw.text.split(rota, '%s*,%s*')
                 local total = 0
                 for _, imgname in ipairs(imgs) do
                 for _, imgname in ipairs(imgs) do
                     imgname = mw.text.trim(imgname)
                     imgname = mw.text.trim(imgname)
Linha 165: Linha 166:
                     end
                     end
                 end
                 end
                -- Nota: slider prev/next ainda precisa JS, mas as imagens aparecem
 
                 if total > 1 then
                 if total > 1 then
                    slider:tag('span')
                        :attr('class', 'lk-slide-btn lk-slide-prev')
                        :attr('aria-label', 'anterior')
                        :wikitext('<')
                    slider:tag('span')
                        :attr('class', 'lk-slide-btn lk-slide-next')
                        :attr('aria-label', 'proximo')
                        :wikitext('>')
                     slider:tag('span')
                     slider:tag('span')
                         :attr('class', 'lk-slide-counter')
                         :attr('class', 'lk-slide-counter')
                        :attr('data-total', tostring(total))
                         :wikitext('1 / ' .. total)
                         :wikitext('1 / ' .. total)
                 end
                 end

Edição atual tal como às 23h25min de 16 de março de 2026

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

local p = {}
local Item = require("Módulo:Item")

local BAU_IMAGENS = {
    comum = 'CommonChest.png',
    ouro  = 'GoldChest.png'
}

local function formatNumber(num)
    num = tonumber(num) or 0
    if num >= 1e9 then
        return string.format("%.0f", num / 1e6) .. "KKK"
    elseif num >= 1e6 then
        return string.format("%.0f", num / 1e6) .. "KK"
    elseif num >= 1e4 then
        return string.format("%.0f", num / 1e3) .. "K"
    else
        local s = tostring(num)
        return s:reverse():gsub("(%d%d%d)", "%1,"):reverse():gsub("^,", "")
    end
end

local function parseItemEntry(entry)
    entry = mw.text.trim(entry)
    if entry == "" then return nil, nil end

    local ident, qtdStr

    if entry:find(";") then
        ident, qtdStr = entry:match("^(.-)%s*;%s*(%d+)$")
    else
        ident, qtdStr = entry:match("^(.-)%s*:%s*(%d+)$")
    end

    if not ident or not qtdStr then return nil, nil end
    return mw.text.trim(ident), tonumber(qtdStr)
end

local function renderRewards(itensRaw, lang)
    if not itensRaw or itensRaw == "" then return "" end

    local parts = {}

    for entry in mw.text.gsplit(itensRaw, ",", true) do
        local ident, qtdNum = parseItemEntry(entry)
        if ident and qtdNum then
            local item = Item.resolve(ident)

            if not item then
                item = {
                    id = 0,
                    image = ident:match("%.%w+$") and ident or (ident .. ".png"),
                    names = { pt = ident, en = ident },
                    category = "unknown"
                }
            end

            local qtdFormatada = formatNumber(qtdNum)
            parts[#parts + 1] = Item.renderOne(item, qtdFormatada, lang, {
                showTooltip = true,
                showCount = true
            })
        end
    end

    return table.concat(parts)
end

function p.render(frame)
    local args = frame:getParent().args
    local nome = mw.text.trim(args['nome'] or '')
    local lang = mw.text.trim(args['lang'] or 'pt')

    local root = mw.html.create('div'):attr('class', 'lk-wrap')

    root:tag('span'):attr('class', 'lk-theme-btn'):wikitext('☾ Dark')

    if nome ~= '' then
        root:tag('div'):attr('class', 'lk-titulo'):wikitext(nome)
    end

    local baus = {}
    local i = 1
    while true do
        local tipo = mw.text.trim(args['bau' .. i .. 'tipo'] or '')
        if tipo == '' then break end
        baus[#baus + 1] = i
        i = i + 1
    end

    if #baus == 0 then return tostring(root) end

    local tabs = root:tag('div'):attr('class', 'lk-tabs')
    for idx, n in ipairs(baus) do
        local tipo   = mw.text.trim(args['bau' .. n .. 'tipo'] or '')
        local tabImg = BAU_IMAGENS[tipo] or ''
        local tab    = tabs:tag('span')
            :attr('class', idx == 1 and 'lk-tab active' or 'lk-tab')
            :attr('data-tab', 'b' .. n)
        if tabImg ~= '' then
            tab:node(mw.html.create(''):wikitext('[[File:' .. tabImg .. '|20px|link=]]'))
        end
        tab:tag('span'):wikitext('Baú ' .. string.format('%02d', n))
    end

    for idx, n in ipairs(baus) do
        local px    = 'bau' .. n
        local tipo  = mw.text.trim(args[px .. 'tipo'] or '')
        local itens = mw.text.trim(args[px .. 'itens'] or '')
        local video = mw.text.trim(args[px .. 'video'] or '')
        local rota  = mw.text.trim(args[px .. 'rota'] or '')

        local panel = root:tag('div')
            :attr('class', idx == 1 and 'lk-panel active' or 'lk-panel')
            :attr('data-panel', 'b' .. n)

        local rsec  = panel:tag('div')
        rsec:tag('div'):attr('class', 'lk-slabel'):wikitext('Recompensas')
        local grid = rsec:tag('div'):attr('class', 'lk-rewards reward-items')

        grid:wikitext(renderRewards(itens, lang))

        if video ~= '' or rota ~= '' then
            panel:tag('div'):attr('class', 'lk-divider')
            local csec = panel:tag('div')
            csec:tag('div'):attr('class', 'lk-slabel'):wikitext('Como chegar')

            local ctabs = csec:tag('div'):attr('class', 'lk-ctabs')
            if video ~= '' then
                ctabs:tag('span')
                    :attr('class', 'lk-ctab active')
                    :attr('data-ctab', 'v' .. n)
                    :wikitext('Vídeo')
            end
            if rota ~= '' then
                ctabs:tag('span')
                    :attr('class', video ~= '' and 'lk-ctab' or 'lk-ctab active')
                    :attr('data-ctab', 'r' .. n)
                    :wikitext('Imagem')
            end

            if video ~= '' then
                local vpanel = csec:tag('div')
                    :attr('class', 'lk-cpanel active')
                    :attr('data-cpanel', 'v' .. n)
                local mwrap = vpanel:tag('div'):attr('class', 'lk-media-wrap')
                mwrap:attr('data-video', video)
            end

            if rota ~= '' then
                local rpanel = csec:tag('div')
                    :attr('class', video ~= '' and 'lk-cpanel' or 'lk-cpanel active')
                    :attr('data-cpanel', 'r' .. n)

                local slider = rpanel:tag('div'):attr('class', 'lk-slider')
                local track  = slider:tag('div'):attr('class', 'lk-slider-track')

                local imgs   = mw.text.split(rota, '%s*,%s*')
                local total  = 0
                for _, imgname in ipairs(imgs) do
                    imgname = mw.text.trim(imgname)
                    if imgname ~= '' then
                        local slide = track:tag('div'):attr('class', 'lk-slide')
                        slide:node(mw.html.create(''):wikitext('[[File:' .. imgname .. '|link=]]'))
                        total = total + 1
                    end
                end

                if total > 1 then
                    slider:tag('span')
                        :attr('class', 'lk-slide-btn lk-slide-prev')
                        :attr('aria-label', 'anterior')
                        :wikitext('<')
                    slider:tag('span')
                        :attr('class', 'lk-slide-btn lk-slide-next')
                        :attr('aria-label', 'proximo')
                        :wikitext('>')
                    slider:tag('span')
                        :attr('class', 'lk-slide-counter')
                        :attr('data-total', tostring(total))
                        :wikitext('1 / ' .. total)
                end
            end
        end
    end

    return tostring(root)
end

return p