Mudanças entre as edições de "Módulo:Reward"
Ir para navegação
Ir para pesquisar
| (29 revisões intermediárias por 2 usuários não estão sendo mostradas) | |||
| Linha 3: | Linha 3: | ||
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 | ||
local function | 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$", "") | |||
local | 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 | end | ||
return | return nil | ||
end | end | ||
| Linha 22: | 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 42: | Linha 55: | ||
local line = container:tag("div") | local line = container:tag("div") | ||
line:addClass("reward-items") | line:addClass("reward-items") | ||
local itensOrdenados = {} | |||
local berriesItem = nil | |||
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 | ||
nome = mw.text.trim(nome) | |||
local | local chave = buscarChaveCorreta(nome) | ||
if not chave then | |||
chave = nome .. ".png" | |||
if not chave | |||
end | end | ||
local data = itemData[chave] or {} | |||
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 | ||
local | local bloco = { | ||
arquivo = chave, | |||
: | qtd = qtdFormatada, | ||
tooltip = tooltip, | |||
isBerries = chave:lower() == "berries.gif" | |||
} | |||
wrapper:tag("span") | if bloco.isBerries then | ||
berriesItem = bloco | |||
else | |||
table.insert(itensOrdenados, bloco) | |||
end | |||
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 | end | ||
quantidade:wikitext(bloco.qtd) | |||
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 | end | ||
Edição atual tal como às 21h36min de 16 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 = {}
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 chave:lower() == "pose.png" and ilhaParam ~= "" then
tooltip = "Eternal Pose - " .. ilhaParam
elseif 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
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
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
return tostring(container)
end
return p