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

De Wiki Gla
Ir para navegação Ir para pesquisar
 
(35 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)
-- Idiomático para MediaWiki (Scribunto), com parsing de argumentos via Module:Arguments (se existir)
-- Autor: Você ; Licença: CC BY-SA 4.0 (ajuste conforme a wiki)


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"
        }


local p = {}
    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
        ))


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


-- Dependências opcionais
    -- Espaço livre para conteúdo customizável do editor
local getArgs
local ok, Args = pcall(require, 'Module:Arguments')
if ok and type(Args) == 'table' then
getArgs = function(frame)
return Args.getArgs(frame, { remap = { ["mostrar_tabela"] = "mostrar_tabela" } })
end
else
-- Fallback simples se Module:Arguments não existir
getArgs = function(frame)
return frame:getParent() and frame:getParent().args or frame.args or {}
end
end


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


-- =============== CONFIG ===============
    local conteudo = box:tag("div")
local CONFIG = {
tiers = { 'bronze', 'prata', 'ouro', 'diamante' },
labels = { berry = 'Berry', frag = 'Fragmentos', pedras = 'Pedras' },
costs = {
star = {
bronze = { [2]={berry=270,frag=40}, [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,pedras=100} },
},
tierUp = { bronze={berry=0,frag=0,pedras=0}, prata={berry=0,frag=0,pedras=0}, ouro={berry=0,frag=0,pedras=0}, diamante=nil },
},
aliases = { ouro = {'gold'} },
}


        :addClass("boss-custom-content")


-- ============== UTIL ==================
        :css{
local function norm(s)
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


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


local function yesno(v)
            background = "#232329",
local t = type(v)
if t == 'boolean' then return v end
if t == 'number' then return v ~= 0 end
if t == 'string' then
v = norm(v)
return not (v == 'nao' or v == 'não' or v == 'n' or v == 'no' or v == 'false' or v == '0' or v == '')
end
return false
end


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


local function clamp(v, lo, hi)
            padding = "18px",
v = tonumber(v) or lo
if v < lo then return lo end
if v > hi then return hi end
return math.floor(v)
end


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


local function tierIndex(name)
        }
local n = norm(name)
if not n then return nil end
for i, t in ipairs(CONFIG.tiers) do if n == t then return i end end
for base, list in pairs(CONFIG.aliases or {}) do
for _, alias in ipairs(list) do if n == alias then return tierIndex(base) end end
end
return nil
end


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


local function getTierName(idx) return CONFIG.tiers[idx] end




local function addCost(a, b)
a = a or { berry=0, frag=0, pedras=0 }
b = b or { berry=0, frag=0, pedras=0 }
return { berry=(a.berry or 0)+(b.berry or 0), frag=(a.frag or 0)+(b.frag or 0), pedras=(a.pedras or 0)+(b.pedras or 0) }
end


    return tostring(html)end


local function starCost(tierName, starTo)
local t = CONFIG.costs.star[tierName]
return p
return p
end

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