Mudanças entre as edições de "Módulo:Gb"

De Wiki Gla
Ir para navegação Ir para pesquisar
Linha 1: Linha 1:
-- Módulo:Gb
 
-- Calculadora de custos para evolução de tiers/estrelas
local function renderCompact(total, opts)
-- Compatível com MediaWiki + Scribunto
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 p = {}
-- 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)




-- Custos baseados na tabela enviada
-- opções visuais e formato
local COSTS = {
local titulo = args.titulo
tiers = {"bronze", "prata", "ouro", "diamante"},
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 '.'




star = {
if not inicioTier or not fimTier then
bronze = {
return "Erro: defina 'inicio_tier' e 'fim_tier'."
[2] = { berry = 270, frag = 40 },
end
[3] = { berry = 1800, frag = 80 },
[4] = { berry = 13500, frag = 180 },
[5] = { berry = 75000, frag = 540 },
},
prata = {
[2] = { berry = 540, frag = 40 },
[3] = { berry = 3600, frag = 80 },
[4] = { berry = 27000, frag = 180 },
[5] = { berry = 180000, frag = 540 },
},
ouro = {
[2] = { berry = 1800, frag = 40 },
[3] = { berry = 18000, frag = 80 },
[4] = { berry = 180000, frag = 180 },
[5] = { berry = 1800000, frag = 540 },
},
diamante = {
[2] = { berry = 18000, frag = 40 },
[3] = { berry = 180000, frag = 80 },
[4] = { berry = 1800000, frag = 180 },
[5] = { berry = 5000000, frag = 0, despertar = 100 },
},
},




tierUp = {
local ti = tierIndex(inicioTier)
bronze = { berry = 0, frag = 0 },
local tf = tierIndex(fimTier)
prata = { berry = 0, frag = 0 },
if not ti or not tf then
ouro = { berry = 0, frag = 0 },
return "Erro: tier inválido. Use: bronze, prata, ouro, diamante."
diamante = nil,
end
},
}




-- Normaliza texto
if (ti > tf) or (ti == tf and inicioEst > fimEst) then
local function norm(s)
return "Erro: o alvo precisa ser maior que o estado inicial."
if type(s) ~= 'string' then return nil end
s = mw.ustring.lower(s)
s = s:gsub("á", "a"):gsub("â", "a"):gsub("ã", "a")
:gsub("é", "e"):gsub("ê", "e")
:gsub("í", "i")
:gsub("ó", "o"):gsub("ô", "o")
:gsub("ú", "u")
return s
end
end




local function tierIndex(name)
local steps, total = computePath(ti, inicioEst, tf, fimEst)
local n = norm(name)
local opts = { titulo = titulo, sepMilhar = sepMilhar }
for i, t in ipairs(COSTS.tiers) do
 
if n == t then return i end
 
if layout == 'compacto' then
return renderCompact(total, opts)
else
return renderTable(steps, total, opts)
end
end
return nil
end
end




local function getTierName(idx)
return p
return p
end

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