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

De Wiki Gla
Ir para navegação Ir para pesquisar
 
(36 revisões intermediárias pelo mesmo usuário não estão sendo mostradas)
Linha 1: Linha 1:
-- [[Module:Gb]] — Calculadora de custos de tiers/estrelas
-- Módulo:BossDisplay (responsivo)


local p = {}


-- ============== CORE ==================
function p.bossInfo(frame)
local function computePath(ti, si, tf, sf)
    local args = frame:getParent().args
local steps, total = {}, { berry=0, frag=0, pedras=0 }
local iTier, iStar = ti, si
local function push(step) steps[#steps+1]=step; total=addCost(total, step.custo) end
while (iTier < tf) or (iTier == tf and iStar < sf) do
if iStar < 5 and (iTier < tf or (iTier == tf and iStar < sf)) then
local tierName = getTierName(iTier)
local toStar = iStar + 1
push({ tipo='estrela', tier=tierName, de=iStar, para=toStar, custo=starCost(tierName, toStar) })
iStar = toStar
else
if iTier >= #CONFIG.tiers then break end
local fromTier = getTierName(iTier)
push({ tipo='tier', de=fromTier, para=getTierName(iTier+1), custo=tierUpCost(fromTier) })
iTier = iTier + 1; iStar = 0
end
end
return steps, total
end


    local function g(k, default)
        return mw.text.trim(args[k] or "") ~= "" and args[k] or default
    end


-- ============= RENDER =================
    local img        = g("img",        "Placeholder.png")
local function pill(class, value)
    local nome      = g("nome",      "Nome do Boss")
return string.format('<span class="gb-pill %s">%s</span>', class, value)
    local frase      = g("frase",      "Frase ou lema do boss.")
end
    local hp        = g("hp",        "???")
    local exp        = g("exp",        "???")
    local nivel      = g("nivel",      "???")
    local necessario = g("necessario",    "-")
    local comum      = g("comum",      "")
    local semiraro  = g("semiraro",  "")
    local raro      = g("raro",       "")
    local muitoRaro  = g("muitoraro", "")


    ----------------------------------------------------
    -- CSS responsivo embutido
    ----------------------------------------------------
    local css = [[


local function renderTable(steps, total, opts)
]]
local h = mw.html.create('div'):addClass('calc-tier')
if opts.titulo and opts.titulo ~= '' then h:tag('h3'):wikitext(opts.titulo) end
local tbl = h:tag('table'):addClass('wikitable'):css('width','100%')
local tr = tbl:tag('tr')
tr:tag('th'):wikitext('Passo'); tr:tag('th'):wikitext('Ação')
tr:tag('th'):wikitext(CONFIG.labels.berry)
tr:tag('th'):wikitext(CONFIG.labels.frag)
tr:tag('th'):wikitext(CONFIG.labels.pedras)
for i, st in ipairs(steps) do
local r = tbl:tag('tr')
r:tag('td'):wikitext(i)
if st.tipo == 'estrela' then r:tag('td'):wikitext(('Tier %s: %d → %d★'):format(st.tier, st.de, st.para))
else r:tag('td'):wikitext(('Subir de %s → %s'):format(st.de, st.para)) end
r:tag('td'):wikitext(pill('gold', formatNumber(st.custo.berry, opts.sep)))
r:tag('td'):wikitext(pill('green', formatNumber(st.custo.frag, opts.sep)))
r:tag('td'):wikitext(formatNumber(st.custo.pedras, opts.sep))
end
local box = h:tag('div'):addClass('calc-tier-total'):css('margin-top','8px')
box:wikitext(('<b>Total:</b> %s • %s • %s: %s')
:format(pill('gold', formatNumber(total.berry, opts.sep)), pill('green', formatNumber(total.frag, opts.sep)), CONFIG.labels.pedras, formatNumber(total.pedras, opts.sep)))
return tostring(h)
end




local function renderCompact(total, opts)
    local html = mw.html.create()
local h = mw.html.create('div'):addClass('calc-tier')
if opts.titulo and opts.titulo ~= '' then h:tag('h3'):wikitext(opts.titulo) end
local box = h:tag('div'):addClass('calc-tier-total')
box:wikitext(('<b>Total:</b> %s • %s • %s: %s')
:format(pill('gold', formatNumber(total.berry, opts.sep)), pill('green', formatNumber(total.frag, opts.sep)), CONFIG.labels.pedras, formatNumber(total.pedras, opts.sep)))
return tostring(h)
end


    html:wikitext(css)


-- ============= ENTRY ==================
    local box = html:tag("div")
function p.calcular(frame)
    :addClass("boss-container")
local args = getArgs(frame)
    :css{
local inicioTier = args.inicio_tier or args.de_tier or args.tier_inicial
        background = "#18181b",
local fimTier = args.fim_tier or args.ate_tier or args.tier_final
        ["border-radius"] = "12px",
if not inicioTier or not fimTier then return "Erro: defina 'inicio_tier' e 'fim_tier'." end
        padding = "30px",
        color = "#fff",
        width = "100%",
        margin = "auto",
        ["font-family"] = "Verdana,sans-serif",
        ["box-sizing"] = "border-box"
    }


    ----------------------------------------------------
    -- Cabeçalho
    ----------------------------------------------------
    box:tag("div")
        :css{ ["font-size"] = "1.5em", ["font-weight"] = "bold", ["margin-bottom"] = "10px" }
        :wikitext("Bosses")


local ti, tf = tierIndex(inicioTier), tierIndex(fimTier)
    local var = box:tag("div")
if not ti or not tf then return 'Erro: tier inválido. Use: bronze, prata, ouro, diamante.' end
        :css("margin-bottom", "24px")


    var:tag("span")
        :css{
            ["background-color"] = "#232329",
            ["border-radius"] = "7px 0 0 7px",
            padding = "7px 20px",
            ["font-size"] = "1em",
            color = "#cbcdd7",
            ["font-weight"] = "600"
        }
        :wikitext("Mecanica Elite")


local inicioEst = clamp(args.inicio_estrela or 0, 0, 5)
    var:tag("span")
local fimEst = clamp(args.fim_estrela or 0, 0, 5)
        :css{
if (ti > tf) or (ti == tf and inicioEst > fimEst) then return 'Erro: o alvo precisa ser maior que o estado inicial.' end
            ["background-color"] = "#19171c",
            ["border-radius"] = "0 7px 7px 0",
            padding = "7px 20px",
            ["font-size"] = "1em",
            color = "#fff",
            ["font-weight"] = "600",
            border = "2px solid #c7a047",
            ["border-left"] = "0"
        }
        :wikitext("Mecanica Hard")


    ----------------------------------------------------
    -- Corpo principal (responsivo)
    ----------------------------------------------------
    local main = box:tag("div")
        :addClass("boss-main")
        :css{
            display = "flex",
            gap = "20px",
            ["align-items"] = "center",
            ["justify-content"] = "space-between",
            ["flex-wrap"] = "wrap"
        }


local steps, total = computePath(ti, inicioEst, tf, fimEst)
    main:tag("div")
        :addClass("boss-img-box")
        :css{ ["flex"] = "none" }
        :wikitext(string.format("[[Arquivo:%s|90px]]", img))


    local textBox = main:tag("div")
        :css{ ["flex"] = "1", ["min-width"] = "200px" }


local layout = norm(args.layout or '')
    textBox:tag("div")
local mostrarTabela = yesno(args.mostrar_tabela ~= 'nao') -- compat
        :css{ ["font-size"] = "1.2em", ["font-weight"] = "bold", color = "#e82b2b" }
if layout == '' then layout = mostrarTabela and 'tabela' or 'compacto' end
        :wikitext(nome)


    textBox:tag("div")
        :css{ ["font-size"] = "95%", color = "#eaa85d", ["font-style"] = "italic" }
        :wikitext(string.format('"%s"', frase))


local opts = { titulo = args.titulo, sep = args.separador_milhar or '.' }
    ----------------------------------------------------
if layout == 'compacto' then return renderCompact(total, opts) end
    -- Stats
return renderTable(steps, total, opts)
    ----------------------------------------------------
end
    local stats = main:tag("div")
        :addClass("boss-stats")
        :css{
            display = "flex",
            ["flex-direction"] = "column",
            ["align-items"] = "flex-end",
            gap = "6px",
            ["min-width"] = "160px"
        }


    local statBox = stats:tag("div")
        :css{
            ["background-color"] = "#222126",
            ["border-radius"] = "8px",
            padding = "12px 20px",
            ["min-width"] = "170px"
        }
    local sline = statBox:tag("div")
        :css{
            display = "flex",
            ["align-items"] = "center",
            ["justify-content"] = "center",
            gap = "16px",
            ["flex-wrap"] = "wrap"
        }
    sline:wikitext(string.format('<span style="color:#fb3d3d;font-weight:bold;font-size:1.15em;">&#x2764;&#xFE0F; %s</span>', hp))
    sline:wikitext(string.format('<span style="color:#ffe568;font-weight:bold;font-size:1.08em;">&#x1F4B0; %s</span>', exp))
    sline:wikitext(string.format('<span style="color:#6ca8fb;font-weight:bold;font-size:1.04em;">&#x2694;&#xFE0F; %s</span>', nivel))
    stats:tag("div")
        :css{
            ["margin-top"] = "5px",
            ["font-size"] = "90%",
            color = "#cfccff",
            ["text-align"] = "right"
        }
        :wikitext(string.format(
            "<b>Necessario:</b> %s &nbsp;&nbsp; ",
            necessario, forte, reflete
        ))
    ----------------------------------------------------
    -- Espaço livre para conteúdo customizável do editor
    ----------------------------------------------------
    local conteudo = box:tag("div")
        :addClass("boss-custom-content")
        :css{
            ["margin-top"] = "28px",
            background = "#232329",
            ["border-radius"] = "10px",
            padding = "18px",
            ["min-height"] = "40px"
        }
        :wikitext(g("conteudo", ""))  -- permite o uso de |conteudo= na predefinição
    return tostring(html)end


return p
return p

Edição atual tal como às 18h27min de 5 de dezembro de 2025

A documentação para este módulo pode ser criada em Módulo:Gb/doc

-- Módulo:BossDisplay (responsivo)

local p = {}

function p.bossInfo(frame)
    local args = frame:getParent().args

    local function g(k, default)
        return mw.text.trim(args[k] or "") ~= "" and args[k] or default
    end

    local img        = g("img",        "Placeholder.png")
    local nome       = g("nome",       "Nome do Boss")
    local frase      = g("frase",      "Frase ou lema do boss.")
    local hp         = g("hp",         "???")
    local exp        = g("exp",        "???")
    local nivel      = g("nivel",      "???")
    local necessario = g("necessario",     "-")
    local comum      = g("comum",      "")
    local semiraro   = g("semiraro",   "")
    local raro       = g("raro",       "")
    local muitoRaro  = g("muitoraro",  "")

    ----------------------------------------------------
    -- CSS responsivo embutido
    ----------------------------------------------------
    local css = [[

]]


    local html = mw.html.create()

    html:wikitext(css)

    local box = html:tag("div")
    :addClass("boss-container")
    :css{
        background = "#18181b",
        ["border-radius"] = "12px",
        padding = "30px",
        color = "#fff",
        width = "100%",
        margin = "auto",
        ["font-family"] = "Verdana,sans-serif",
        ["box-sizing"] = "border-box"
    }

    ----------------------------------------------------
    -- Cabeçalho
    ----------------------------------------------------
    box:tag("div")
        :css{ ["font-size"] = "1.5em", ["font-weight"] = "bold", ["margin-bottom"] = "10px" }
        :wikitext("Bosses")

    local var = box:tag("div")
        :css("margin-bottom", "24px")

    var:tag("span")
        :css{
            ["background-color"] = "#232329",
            ["border-radius"] = "7px 0 0 7px",
            padding = "7px 20px",
            ["font-size"] = "1em",
            color = "#cbcdd7",
            ["font-weight"] = "600"
        }
        :wikitext("Mecanica Elite")

    var:tag("span")
        :css{
            ["background-color"] = "#19171c",
            ["border-radius"] = "0 7px 7px 0",
            padding = "7px 20px",
            ["font-size"] = "1em",
            color = "#fff",
            ["font-weight"] = "600",
            border = "2px solid #c7a047",
            ["border-left"] = "0"
        }
        :wikitext("Mecanica Hard")

    ----------------------------------------------------
    -- Corpo principal (responsivo)
    ----------------------------------------------------
    local main = box:tag("div")
        :addClass("boss-main")
        :css{
            display = "flex",
            gap = "20px",
            ["align-items"] = "center",
            ["justify-content"] = "space-between",
            ["flex-wrap"] = "wrap"
        }

    main:tag("div")
        :addClass("boss-img-box")
        :css{ ["flex"] = "none" }
        :wikitext(string.format("[[Arquivo:%s|90px]]", img))

    local textBox = main:tag("div")
        :css{ ["flex"] = "1", ["min-width"] = "200px" }

    textBox:tag("div")
        :css{ ["font-size"] = "1.2em", ["font-weight"] = "bold", color = "#e82b2b" }
        :wikitext(nome)

    textBox:tag("div")
        :css{ ["font-size"] = "95%", color = "#eaa85d", ["font-style"] = "italic" }
        :wikitext(string.format('"%s"', frase))

    ----------------------------------------------------
    -- Stats
    ----------------------------------------------------
    local stats = main:tag("div")
        :addClass("boss-stats")
        :css{
            display = "flex",
            ["flex-direction"] = "column",
            ["align-items"] = "flex-end",
            gap = "6px",
            ["min-width"] = "160px"
        }

    local statBox = stats:tag("div")
        :css{
            ["background-color"] = "#222126",
            ["border-radius"] = "8px",
            padding = "12px 20px",
            ["min-width"] = "170px"
        }

    local sline = statBox:tag("div")
        :css{
            display = "flex",
            ["align-items"] = "center",
            ["justify-content"] = "center",
            gap = "16px",
            ["flex-wrap"] = "wrap"
        }

    sline:wikitext(string.format('<span style="color:#fb3d3d;font-weight:bold;font-size:1.15em;">&#x2764;&#xFE0F; %s</span>', hp))
    sline:wikitext(string.format('<span style="color:#ffe568;font-weight:bold;font-size:1.08em;">&#x1F4B0; %s</span>', exp))
    sline:wikitext(string.format('<span style="color:#6ca8fb;font-weight:bold;font-size:1.04em;">&#x2694;&#xFE0F; %s</span>', nivel))

    stats:tag("div")
        :css{
            ["margin-top"] = "5px",
            ["font-size"] = "90%",
            color = "#cfccff",
            ["text-align"] = "right"
        }
        :wikitext(string.format(
            "<b>Necessario:</b> %s &nbsp;&nbsp; ",
            necessario, forte, reflete
        ))

    ----------------------------------------------------

    -- Espaço livre para conteúdo customizável do editor

    ----------------------------------------------------

    local conteudo = box:tag("div")

        :addClass("boss-custom-content")

        :css{

            ["margin-top"] = "28px",

            background = "#232329",

            ["border-radius"] = "10px",

            padding = "18px",

            ["min-height"] = "40px"

        }

        :wikitext(g("conteudo", ""))  -- permite o uso de |conteudo= na predefinição




    return tostring(html)end

return p