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

De Wiki Gla
Ir para navegação Ir para pesquisar
(fix dos nomes)
Linha 1: Linha 1:
local p = {}
local p = {}
local itemData = require("Módulo:ItemData")
local itemData = require("Módulo:Itemdata")


local function formatNumber(num)
local function formatNumber(num)
Linha 8: Linha 8:
end
end


local function normalizarChave(nome)
local function buscarChaveCorreta(nome)
     nome = mw.text.trim(nome)
     local base = mw.text.trim(nome):lower():gsub("_", " ")
    nome = nome:gsub("_", " ")
     for chave, _ in pairs(itemData) do
     nome = nome:sub(1, 1):upper() .. nome:sub(2)
        local kbase = chave:lower():gsub("_", " "):gsub("%.png$", ""):gsub("%.gif$", ""):gsub("%.jpg$", ""):gsub("%.webp$", "")
    local temExt = nome:match("%.png$") or nome:match("%.gif$") or nome:match("%.jpg$") or nome:match("%.webp$")
        if kbase == base then
    if not temExt then
            return chave
         nome = nome .. ".png"
         end
     end
     end
     return nome
     return nil
end
end


Linha 46: Linha 46:
         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 chave = normalizarChave(nome)
            nome = mw.text.trim(nome)
             local data = itemData[chave] or {}
             local chave = buscarChaveCorreta(nome)
            local arquivo = chave or (nome .. ".png")
             local data = itemData[chave or (nome .. ".png")] or {}


             local numero = tonumber(qtd) or 0
             local numero = tonumber(qtd) or 0
             local qtdFormatada = formatNumber(numero)
             local qtdFormatada = formatNumber(numero)


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


             local nomeCompleto = data.nome or nome
             local nomeCompleto = data.nome or nome
Linha 70: Linha 69:


             wrapper:tag("span")
             wrapper:tag("span")
                 :wikitext(string.format("[[Arquivo:%s|link=]]", chave))
                 :wikitext(string.format("[[Arquivo:%s|link=]]", arquivo))


             wrapper:tag("span")
             wrapper:tag("span")

Edição das 03h05min de 11 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()
    return result:gsub("^,", "")
end

local function buscarChaveCorreta(nome)
    local base = mw.text.trim(nome):lower():gsub("_", " ")
    for chave, _ in pairs(itemData) do
        local kbase = chave:lower():gsub("_", " "):gsub("%.png$", ""):gsub("%.gif$", ""):gsub("%.jpg$", ""):gsub("%.webp$", "")
        if kbase == base then
            return chave
        end
    end
    return nil
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
            nome = mw.text.trim(nome)
            local chave = buscarChaveCorreta(nome)
            local arquivo = chave or (nome .. ".png")
            local data = itemData[chave or (nome .. ".png")] or {}

            local numero = tonumber(qtd) or 0
            local qtdFormatada = formatNumber(numero)

            local prefix = nome:lower():match("^berries") and "" or "x"

            local nomeCompleto = data.nome or nome
            local descricao = data.desc
            local tooltip = nomeCompleto

            if descricao and descricao ~= "" then
                tooltip = tooltip .. "\n—\n" .. descricao
            end

            local wrapper = line:tag("span")
                :addClass("item-wrapper")
                :attr("data-tooltip", tooltip)

            wrapper:tag("span")
                :wikitext(string.format("[[Arquivo:%s|link=]]", arquivo))

            wrapper:tag("span")
                :addClass("item-count")
                :wikitext(prefix .. qtdFormatada)
        end
    end

    return tostring(container)
end

return p