Mudanças entre as edições de "Módulo:Gb"
Ir para navegação
Ir para pesquisar
| Linha 1: | Linha 1: | ||
-- | |||
-- | 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 | |||
local | -- 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 | 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) | |||
bronze | local tf = tierIndex(fimTier) | ||
prata | if not ti or not tf then | ||
ouro | return "Erro: tier inválido. Use: bronze, prata, ouro, diamante." | ||
diamante | end | ||
if (ti > tf) or (ti == tf and inicioEst > fimEst) then | |||
return "Erro: o alvo precisa ser maior que o estado inicial." | |||
end | end | ||
local | local steps, total = computePath(ti, inicioEst, tf, fimEst) | ||
local | local opts = { titulo = titulo, sepMilhar = sepMilhar } | ||
if | |||
if layout == 'compacto' then | |||
return renderCompact(total, opts) | |||
else | |||
return renderTable(steps, total, opts) | |||
end | end | ||
end | end | ||
return p | return p | ||
Edição das 20h52min de 26 de setembro de 2025
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