Mudanças entre as edições de "Módulo:Reward"
Ir para navegação
Ir para pesquisar
| Linha 18: | Linha 18: | ||
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$", "") | ||
for chave, dados in pairs(itemData) do | for chave, dados in pairs(itemData) do | ||
local kbase = chave:lower():gsub("_", " "):gsub("%.png$", ""):gsub("%.gif$", ""):gsub("%.jpg$", ""):gsub("%.webp$", "") | local kbase = chave:lower():gsub("_", " "):gsub("%.png$", ""):gsub("%.gif$", ""):gsub("%.jpg$", ""):gsub("%.webp$", "") | ||
| Linha 24: | Linha 23: | ||
return chave | return chave | ||
end | end | ||
local nomeTraduzido = (dados.nome or ""):lower():gsub("_", " "):gsub("%.png$", ""):gsub("%.gif$", ""):gsub("%.jpg$", ""):gsub("%.webp$", "") | local nomeTraduzido = (dados.nome or ""):lower():gsub("_", " "):gsub("%.png$", ""):gsub("%.gif$", ""):gsub("%.jpg$", ""):gsub("%.webp$", "") | ||
if nomeTraduzido == base then | if nomeTraduzido == base then | ||
| Linha 30: | Linha 28: | ||
end | end | ||
end | end | ||
return nil | return nil | ||
end | end | ||
| Linha 37: | Linha 34: | ||
local args = frame:getParent().args or {} | local args = frame:getParent().args or {} | ||
local itens = args.itens or "" | local itens = args.itens or "" | ||
local ilhaParam = args.ilha or "" | |||
local rawTitle = args[1] or "" | local rawTitle = args[1] or "" | ||
local titulo = "" | local titulo = "" | ||
| Linha 71: | Linha 69: | ||
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 chave:lower() == "pose.png" and ilhaParam ~= "" then | |||
tooltip = "Eternal Pose - " .. ilhaParam | |||
elseif descricao and descricao ~= "" then | |||
tooltip = tooltip .. "\n—\n" .. descricao | tooltip = tooltip .. "\n—\n" .. descricao | ||
end | end | ||
Edição das 23h40min de 15 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)
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, dados in pairs(itemData) do
local kbase = chave:lower():gsub("_", " "):gsub("%.png$", ""):gsub("%.gif$", ""):gsub("%.jpg$", ""):gsub("%.webp$", "")
if kbase == base then
return chave
end
local nomeTraduzido = (dados.nome or ""):lower():gsub("_", " "):gsub("%.png$", ""):gsub("%.gif$", ""):gsub("%.jpg$", ""):gsub("%.webp$", "")
if nomeTraduzido == 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 ilhaParam = args.ilha 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 = {}
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 chave:lower() == "pose.png" and ilhaParam ~= "" then
tooltip = "Eternal Pose - " .. ilhaParam
elseif descricao and descricao ~= "" then
tooltip = tooltip .. "\n—\n" .. descricao
end
table.insert(itensOrdenados, {
arquivo = chave,
qtd = qtdFormatada,
tooltip = tooltip,
isBerries = chave:lower() == "berries.gif"
})
end
end
table.sort(itensOrdenados, function(a, b)
if a.isBerries then
return false
elseif b.isBerries then
return true
else
return a.arquivo < b.arquivo
end
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))
local quantidade = wrapper:tag("span"):addClass("item-count")
if not bloco.isBerries then
quantidade:tag("span"):addClass("item-count-x"):wikitext("x")
end
quantidade:wikitext(bloco.qtd)
end
return tostring(container)
end
return p