Mudanças entre as edições de "Módulo:Reward"
Ir para navegação
Ir para pesquisar
| Linha 2: | Linha 2: | ||
local itemData = require("Módulo:ItemData") | local itemData = require("Módulo:ItemData") | ||
-- Formatador com K / KK / KKK (padrão BR gamer) | |||
local function formatNumber(num) | local function formatNumber(num) | ||
local s = tostring(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 | end | ||
| Linha 52: | Linha 61: | ||
local chave = buscarChaveCorreta(nome) | local chave = buscarChaveCorreta(nome) | ||
if not chave then | if not chave then | ||
chave = nome .. ".png" | chave = nome .. ".png" | ||
end | end | ||
local data = itemData[chave] or {} | local data = itemData[chave] or {} | ||
local qtdFormatada = formatNumber(tonumber(qtd) or 0) | local qtdFormatada = formatNumber(tonumber(qtd) or 0) | ||
local nomeCompleto = data.nome or nome | local nomeCompleto = data.nome or nome | ||
local descricao = data.desc | local descricao = data.desc | ||
local tooltip = nomeCompleto | local tooltip = nomeCompleto | ||
if descricao and descricao ~= "" then | if descricao and descricao ~= "" then | ||
tooltip = tooltip .. "\n—\n" .. descricao | |||
end | end | ||
local bloco = { | local bloco = { | ||
arquivo = chave, | |||
qtd = qtdFormatada, | |||
tooltip = tooltip, | |||
isBerries = chave:lower() == "berries.gif" | |||
} | } | ||
if bloco.isBerries then | if bloco.isBerries then | ||
Edição das 18h46min 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")
-- Formatador com K / KK / KKK (padrão BR gamer)
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 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"
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