Mudanças entre as edições de "Módulo:Quest"
Ir para navegação
Ir para pesquisar
(Criou página com 'local p = {} local itemData = require("Módulo:ItemData") local function formatNumber(n) local s = tostring(n) local result = s:reverse():gsub("(%d%d%d)", "%1,"):reve...') |
|||
| Linha 80: | Linha 80: | ||
end | end | ||
return tostring(html) | if next(total) == nil then | ||
return "" | |||
end | |||
return tostring(html) | |||
end | end | ||
return p | return p | ||
Edição das 02h05min de 9 de junho de 2025
A documentação para este módulo pode ser criada em Módulo:Quest/doc
local p = {}
local itemData = require("Módulo:ItemData")
local function formatNumber(n)
local s = tostring(n)
local result = s:reverse():gsub("(%d%d%d)", "%1,"):reverse()
return result:gsub("^,", "")
end
local function parseItens(raw)
local resultado = {}
for item in mw.text.gsplit(raw or "", ",", true) do
local nome, qtd = item:match("^%s*(.-)%s*:%s*(%d+)%s*$")
if nome and qtd then
nome = mw.text.trim(nome)
if not nome:match("%.png$") and not nome:match("%.gif$") and not nome:match("%.jpg$") and not nome:match("%.webp$") then
nome = nome .. ".png"
end
qtd = tonumber(qtd) or 0
resultado[nome] = (resultado[nome] or 0) + qtd
end
end
return resultado
end
local function mergeRecompensas(lista)
local total = {}
for _, raw in ipairs(lista) do
local dados = parseItens(raw)
for nome, qtd in pairs(dados) do
total[nome] = (total[nome] or 0) + qtd
end
end
return total
end
function p.total(frame)
local args = frame:getParent().args or {}
local bonus = args.bonus or ""
local content = mw.title.getCurrentTitle():getContent()
local rewardCalls = {}
for bloco in content:gmatch("{{%s*[Rr]eward.-}}") do
local itens = bloco:match("itens%s*=%s*([^|}]+)")
if itens then
table.insert(rewardCalls, itens)
end
end
if bonus and bonus ~= "" then
table.insert(rewardCalls, bonus)
end
local total = mergeRecompensas(rewardCalls)
local html = mw.html.create("div")
html:addClass("introquest-items")
for nome, qtd in pairs(total) do
local data = itemData[nome] or {}
local nomeCompleto = data.nome or nome
local desc = data.desc
local tooltip = nomeCompleto
if desc and desc ~= "" then
tooltip = tooltip .. "\n—\n" .. desc
end
local wrapper = html:tag("span")
wrapper:addClass("introquest-item")
wrapper:addClass("item-wrapper")
wrapper:attr("data-tooltip", tooltip)
wrapper:tag("span")
:wikitext(string.format("[[Arquivo:%s|link=]]", nome))
wrapper:tag("span")
:addClass("introquest-count")
:wikitext((nome:lower():match("^berries") and "" or "x") .. formatNumber(qtd))
end
if next(total) == nil then
return ""
end
return tostring(html)
end
return p