Mudanças entre as edições de "Módulo:Quest"
Ir para navegação
Ir para pesquisar
| Linha 11: | Linha 11: | ||
nome = mw.text.trim(nome) | nome = mw.text.trim(nome) | ||
nome = nome:gsub("_", " ") | nome = nome:gsub("_", " ") | ||
nome = nome: | -- Capitaliza só a primeira letra do nome inteiro | ||
nome = nome:sub(1, 1):upper() .. nome:sub(2) | |||
local temExt = nome:match("%.png$") or nome:match("%.gif$") or nome:match("%.jpg$") or nome:match("%.webp$") | local temExt = nome:match("%.png$") or nome:match("%.gif$") or nome:match("%.jpg$") or nome:match("%.webp$") | ||
if not temExt then | if not temExt then | ||
Edição das 20h29min de 10 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 normalizarChave(nome)
nome = mw.text.trim(nome)
nome = nome:gsub("_", " ")
-- Capitaliza só a primeira letra do nome inteiro
nome = nome:sub(1, 1):upper() .. nome:sub(2)
local temExt = nome:match("%.png$") or nome:match("%.gif$") or nome:match("%.jpg$") or nome:match("%.webp$")
if not temExt then
nome = nome .. ".png"
end
return nome
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 = normalizarChave(nome)
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")
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("item-wrapper")
wrapper:addClass("introquest-item")
wrapper:attr("data-tooltip", tooltip)
wrapper:tag("span")
:wikitext(string.format("[[Arquivo:%s|link=]]", nome))
wrapper:tag("span")
:addClass("item-count")
:wikitext((nome:lower():match("^berries") and "" or "x") .. formatNumber(qtd))
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