Módulo:Gb
Revisão de 20h52min de 26 de setembro de 2025 por GhoulBlack (discussão | contribs)
A documentação para este módulo pode ser criada em Módulo:Gb/doc
local function renderCompact(total, opts)
local h = mw.html.create('div'):addClass('calc-tier')
if opts.titulo then h:tag('h3'):wikitext(opts.titulo) end
local box = h:tag('div'):addClass('calc-tier-total')
box:wikitext(string.format(
'<b>Total:</b> %s • %s • %s: %s',
pill('gold', formatNumber(total.berry, opts.sepMilhar)),
pill('green', formatNumber(total.frag, opts.sepMilhar)),
CONFIG.labels.pedras,
formatNumber(total.pedras, opts.sepMilhar)
))
return tostring(h)
end
-- =====================
-- ENTRADA PÚBLICA
-- =====================
local function parseInt(v, default)
local n = tonumber(v)
if not n then return default end
return math.floor(n)
end
function p.calcular(frame)
local args = frame:getParent() and frame:getParent().args or frame.args
-- parâmetros principais
local inicioTier = args.inicio_tier or args.de_tier or args.tier_inicial
local fimTier = args.fim_tier or args.ate_tier or args.tier_final
local inicioEst = clamp(parseInt(args.inicio_estrela or 0, 0), 0, 5)
local fimEst = clamp(parseInt(args.fim_estrela or 0, 0), 0, 5)
-- opções visuais e formato
local titulo = args.titulo
local mostrarTabela = tostring(args.mostrar_tabela or 'sim') ~= 'nao' -- compat
local layout = norm(args.layout or (mostrarTabela and 'tabela' or 'compacto')) -- 'tabela' | 'compacto'
local sepMilhar = args.separador_milhar or '.'
if not inicioTier or not fimTier then
return "Erro: defina 'inicio_tier' e 'fim_tier'."
end
local ti = tierIndex(inicioTier)
local tf = tierIndex(fimTier)
if not ti or not tf then
return "Erro: tier inválido. Use: bronze, prata, ouro, diamante."
end
if (ti > tf) or (ti == tf and inicioEst > fimEst) then
return "Erro: o alvo precisa ser maior que o estado inicial."
end
local steps, total = computePath(ti, inicioEst, tf, fimEst)
local opts = { titulo = titulo, sepMilhar = sepMilhar }
if layout == 'compacto' then
return renderCompact(total, opts)
else
return renderTable(steps, total, opts)
end
end
return p