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

De Wiki Gla
Ir para navegação Ir para pesquisar
Linha 1: Linha 1:
-- Módulo:Reward
local p = {}
local p = {}
local itemData = require("Módulo:ItemData")
local itemData = require("Módulo:ItemData")
Linha 35: Linha 34:


     for item in mw.text.gsplit(itens, ",", true) do
     for item in mw.text.gsplit(itens, ",", true) do
        local nome, qtd = item:match("^%s*(.-)%s*:%s*(%d+)%s*$")
    local nome, qtd = item:match("^%s*(.-)%s*:%s*(%d+)%s*$")
        if nome and qtd then
    if nome and qtd then
            local temExt = nome:match("%.png$")
        local data = itemData[nome] or {}
                        or nome:match("%.gif$")
                        or nome:match("%.jpg$")
                        or nome:match("%.webp$")
            local arquivo = temExt and nome or (nome .. ".png")
            local numero = tonumber(qtd) or 0
            local qtdFormatada = formatNumber(numero)


            local prefix = ""
        local temExt = nome:match("%.png$")
            if not nome:lower():match("^berries") then
                    or nome:match("%.gif$")
                prefix = "x"
                    or nome:match("%.jpg$")
            end
                    or nome:match("%.webp$")
        local arquivo = temExt and nome or (nome .. ".png")
        local numero = tonumber(qtd) or 0
        local qtdFormatada = formatNumber(numero)


            local data = itemData[nome] or {}
        local prefix = ""
            local nomeCompleto = data.nome or nome
        if not nome:lower():match("^berries") then
            local descricao = data.desc or ""
             prefix = "x"
             local alt = descricao ~= "" and (nomeCompleto .. " – " .. descricao) or nomeCompleto
        end


            local span = line:tag("span")
        local nomeCompleto = data.nome
                :addClass("item-wrapper")
        local descricao = data.desc
                :attr("title", alt)
        local alt = nil


             span:wikitext(string.format("[[Arquivo:%s|link=]]", arquivo))
        if nomeCompleto then
             alt = nomeCompleto
            if descricao and descricao ~= "" then
                alt = alt .. " " .. descricao
            end
        end


            span:tag("span")
        local span = line:tag("span"):addClass("item-wrapper")
                :addClass("item-count")
        if alt then
                :wikitext(prefix .. qtdFormatada)
            span:attr("title", alt)
         end
         end
        span:wikitext(string.format("[[Arquivo:%s|link=]]", arquivo))
        span:tag("span")
            :addClass("item-count")
            :wikitext(prefix .. qtdFormatada)
     end
     end
end


     return tostring(container)
     return tostring(container)

Edição das 20h17min de 8 de junho de 2025

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

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

local function formatNumber(num)
    local s = tostring(num)
    local result = s:reverse():gsub("(%d%d%d)", "%1,"):reverse()
    result = result:gsub("^,", "")
    return result
end

function p.exibir(frame)
    local args = frame:getParent().args or {}
    local itens = args.itens or ""
    local rawTitle = args[1] or ""
    local titulo = ""

    if rawTitle == "t" then
        titulo = "Recompensas:"
    elseif rawTitle ~= "" then
        titulo = rawTitle
    end

    local container = mw.html.create("div")
    container:addClass("reward-wrapper")

    if titulo ~= "" then
        container:tag("div")
            :addClass("reward-title")
            :wikitext(titulo)
    end

    local line = container:tag("div")
    line:addClass("reward-items")

    for item in mw.text.gsplit(itens, ",", true) do
    local nome, qtd = item:match("^%s*(.-)%s*:%s*(%d+)%s*$")
    if nome and qtd then
        local data = itemData[nome] or {}

        local temExt = nome:match("%.png$")
                    or nome:match("%.gif$")
                    or nome:match("%.jpg$")
                    or nome:match("%.webp$")
        local arquivo = temExt and nome or (nome .. ".png")
        local numero = tonumber(qtd) or 0
        local qtdFormatada = formatNumber(numero)

        local prefix = ""
        if not nome:lower():match("^berries") then
            prefix = "x"
        end

        local nomeCompleto = data.nome
        local descricao = data.desc
        local alt = nil

        if nomeCompleto then
            alt = nomeCompleto
            if descricao and descricao ~= "" then
                alt = alt .. " – " .. descricao
            end
        end

        local span = line:tag("span"):addClass("item-wrapper")
        if alt then
            span:attr("title", alt)
        end

        span:wikitext(string.format("[[Arquivo:%s|link=]]", arquivo))
        span:tag("span")
            :addClass("item-count")
            :wikitext(prefix .. qtdFormatada)
    end
end

    return tostring(container)
end

return p