Mudanças entre as edições de "Módulo:Reward"
Ir para navegação
Ir para pesquisar
| Linha 8: | Linha 8: | ||
end | end | ||
local function buscarChaveCorreta(nome) | local function buscarChaveCorreta(nome) | ||
local base = mw.text.trim(nome):lower():gsub("_", " "):gsub("%.png$", ""):gsub("%.gif$", ""):gsub("%.jpg$", ""):gsub("%.webp$", "") | local base = mw.text.trim(nome):lower():gsub("_", " "):gsub("%.png$", ""):gsub("%.gif$", ""):gsub("%.jpg$", ""):gsub("%.webp$", "") | ||
| Linha 57: | Linha 56: | ||
local data = itemData[chave] or {} | local data = itemData[chave] or {} | ||
local qtdFormatada = formatNumber(tonumber(qtd) or 0) | |||
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 bloco = { | |||
arquivo = chave, | |||
qtd = qtdFormatada, | |||
tooltip = tooltip, | |||
isBerries = chave:lower() == "berries.gif" | |||
} | |||
if bloco.isBerries then | if bloco.isBerries then | ||
| Linha 82: | Linha 80: | ||
end | end | ||
if berriesItem then | if berriesItem then | ||
local wrapper = line:tag("span") | local wrapper = line:tag("span") | ||
| Linha 96: | Linha 93: | ||
end | end | ||
for _, bloco in ipairs(itensOrdenados) do | for _, bloco in ipairs(itensOrdenados) do | ||
local wrapper = line:tag("span") | local wrapper = line:tag("span") | ||
Edição das 18h24min 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("_", " "):gsub("%.png$", ""):gsub("%.gif$", ""):gsub("%.jpg$", ""):gsub("%.webp$", "")
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")
local itensOrdenados = {}
local berriesItem = nil
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)
if not chave then
chave = nome .. ".png" -- fallback
end
local data = itemData[chave] or {}
local qtdFormatada = formatNumber(tonumber(qtd) or 0)
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 bloco = {
arquivo = chave,
qtd = qtdFormatada,
tooltip = tooltip,
isBerries = chave:lower() == "berries.gif"
}
if bloco.isBerries then
berriesItem = bloco
else
table.insert(itensOrdenados, bloco)
end
end
end
if berriesItem then
local wrapper = line:tag("span")
:addClass("item-wrapper")
:attr("data-tooltip", berriesItem.tooltip)
wrapper:tag("span")
:wikitext(string.format("[[Arquivo:%s|link=]]", berriesItem.arquivo))
wrapper:tag("span")
:addClass("item-count")
:wikitext(berriesItem.qtd)
end
for _, bloco in ipairs(itensOrdenados) do
local wrapper = line:tag("span")
:addClass("item-wrapper")
:attr("data-tooltip", bloco.tooltip)
wrapper:tag("span")
:wikitext(string.format("[[Arquivo:%s|link=]]", bloco.arquivo))
wrapper:tag("span")
:addClass("item-count")
:wikitext(bloco.qtd)
end
return tostring(container)
end
return p