Mudanças entre as edições de "Módulo:Quest"
Ir para navegação
Ir para pesquisar
| Linha 73: | Linha 73: | ||
local bloco = { | local bloco = { | ||
arquivo = nome, | arquivo = nome, | ||
qtd = formatNumber(qtd), | qtd = formatNumber(qtd), | ||
tooltip = tooltip | tooltip = tooltip | ||
} | } | ||
Edição das 18h24min de 11 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 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
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
local chave = buscarChaveCorreta(nome) or (nome .. ".png")
qtd = tonumber(qtd) or 0
resultado[chave] = (resultado[chave] 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)
if next(total) == nil then return "" end
local html = mw.html.create("div")
html:addClass("introquest-items")
local berriesItem = nil
local outros = {}
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 bloco = {
arquivo = nome,
qtd = formatNumber(qtd),
tooltip = tooltip
}
if nome:lower() == "berries.gif" then
berriesItem = bloco
else
table.insert(outros, bloco)
end
end
local function addBloco(bloco)
local wrap = html:tag("span")
wrap:addClass("item-wrapper")
wrap:attr("data-tooltip", bloco.tooltip)
wrap:tag("span"):wikitext(string.format("[[Arquivo:%s|link=]]", bloco.arquivo))
wrap:tag("span"):addClass("item-count"):wikitext(bloco.qtd)
end
if berriesItem then addBloco(berriesItem) end
for _, b in ipairs(outros) do addBloco(b) end
return tostring(html)
end
function p.requisitos(frame)
local args = frame:getParent().args or ""
local raw = args.requisitos or ""
if mw.text.trim(raw) == "" then return "" end
local output = {}
for item in mw.text.gsplit(raw, ",", true) do
local clean = mw.text.trim(item)
if clean ~= "" then table.insert(output, "* " .. clean) end
end
return table.concat(output, "\n")
end
return p