Mudanças entre as edições de "Módulo:Gb"
Ir para navegação
Ir para pesquisar
Etiqueta: Revertido |
Etiqueta: Revertido |
||
| Linha 1: | Linha 1: | ||
local p = {} | |||
local | -------------------------------------------------------- | ||
-- Função auxiliar: obtém argumento ou valor padrão | |||
-------------------------------------------------------- | |||
local function getArg(args, key, default) | |||
return mw.text.trim(args[key] or "") ~= "" and args[key] or default | |||
end | |||
-------------------------------------------------------- | |||
-- Renderiza um único boss (usado internamente) | |||
-------------------------------------------------------- | |||
local function renderBoss(args, prefix) | |||
local function g(k, default) | local function g(k, default) | ||
return | return getArg(args, prefix .. k, default) | ||
end | end | ||
| Linha 24: | Linha 31: | ||
local muitoRaro = g("muitoraro", "") | local muitoRaro = g("muitoraro", "") | ||
local html = mw.html.create("div") | |||
:addClass("boss-card") | |||
:css{ | |||
["background"] = "#18181b", | |||
["border-radius"] = "12px", | |||
padding = "30px", | |||
color = "#fff", | |||
width = "100%", | |||
["box-sizing"] = "border-box", | |||
["margin-bottom"] = "32px", | |||
["font-family"] = "Verdana,sans-serif" | |||
} | |||
local html = mw.html.create | |||
---------------------------------------------------- | ---------------------------------------------------- | ||
-- Cabeçalho | -- Cabeçalho | ||
---------------------------------------------------- | ---------------------------------------------------- | ||
html:tag("div") | |||
:css{ ["font-size"] = "1.5em", ["font-weight"] = "bold", ["margin-bottom"] = "10px" } | :css{ ["font-size"] = "1.5em", ["font-weight"] = "bold", ["margin-bottom"] = "10px" } | ||
:wikitext( | :wikitext(nome) | ||
html:tag("div") | |||
:css{ | :css{ ["font-size"] = "95%", color = "#eaa85d", ["font-style"] = "italic", ["margin-bottom"] = "16px" } | ||
:wikitext('"' .. frase .. '"') | |||
:wikitext(" | |||
---------------------------------------------------- | ---------------------------------------------------- | ||
-- Corpo principal | -- Corpo principal | ||
---------------------------------------------------- | ---------------------------------------------------- | ||
local main = | local main = html:tag("div") | ||
:css{ | :css{ | ||
display = "flex", | display = "flex", | ||
["justify-content"] = "space-between", | |||
["align-items"] = "center", | ["align-items"] = "center", | ||
[" | ["flex-wrap"] = "wrap", | ||
gap = "20px" | |||
} | } | ||
main:tag("div") | main:tag("div") | ||
:css{ ["flex"] = "none" } | :css{ ["flex"] = "none" } | ||
:wikitext(string.format("[[Arquivo:%s|90px]]", img)) | :wikitext(string.format("[[Arquivo:%s|90px]]", img)) | ||
local | local statsBox = main:tag("div") | ||
:css{ [" | :css{ ["min-width"] = "200px", ["flex"] = "1" } | ||
statsBox:tag("div"):wikitext( | |||
: | string.format( | ||
'<span style="color:#fb3d3d;font-weight:bold;font-size:1.15em;">❤️ %s</span> ' .. | |||
'<span style="color:#ffe568;font-weight:bold;font-size:1.08em;">💰 %s</span> ' .. | |||
'<span style="color:#6ca8fb;font-weight:bold;font-size:1.04em;">⚔️ %s</span>', | |||
hp, exp, nivel | |||
) | |||
) | |||
statsBox:tag("div") | |||
:css{ | :css{ | ||
["margin-top"] = "5px", | ["margin-top"] = "5px", | ||
["font-size"] = "90%", | ["font-size"] = "90%", | ||
color = "#cfccff | color = "#cfccff" | ||
} | } | ||
:wikitext(string.format( | :wikitext(string.format( | ||
| Linha 177: | Linha 97: | ||
-- Tabela de loot | -- Tabela de loot | ||
---------------------------------------------------- | ---------------------------------------------------- | ||
local loot = | local loot = html:tag("div") | ||
:css{ | :css{ | ||
["margin-top"] = " | ["margin-top"] = "20px", | ||
background = "#232329", | background = "#232329", | ||
["border-radius"] = "10px", | ["border-radius"] = "10px", | ||
| Linha 209: | Linha 129: | ||
row("Raro:", "#e6e5ff", raro) | row("Raro:", "#e6e5ff", raro) | ||
row("Muito Raro:", "#f9538f", muitoRaro) | row("Muito Raro:", "#f9538f", muitoRaro) | ||
return tostring(html) | |||
end | |||
-------------------------------------------------------- | |||
-- Função principal: suporta 1 boss ou vários bosses | |||
-------------------------------------------------------- | |||
function p.bosses(frame) | |||
local args = frame:getParent().args | |||
local html = mw.html.create() | |||
-- CSS responsivo | |||
html:wikitext([[ | |||
<style> | |||
@media screen and (max-width: 650px) { | |||
.boss-card { | |||
text-align: center !important; | |||
} | |||
} | |||
</style> | |||
]]) | |||
---------------------------------------------------- | |||
-- Detecta quantos bosses existem no bloco | |||
---------------------------------------------------- | |||
local n = 0 | |||
for k, _ in pairs(args) do | |||
local num = string.match(k, "^(%d+)nome$") | |||
if num then | |||
num = tonumber(num) | |||
if num > n then n = num end | |||
end | |||
end | |||
---------------------------------------------------- | |||
-- Se não encontrar numéricos, renderiza boss único | |||
---------------------------------------------------- | |||
if n == 0 then | |||
html:wikitext(renderBoss(args, "")) | |||
return tostring(html) | |||
end | |||
---------------------------------------------------- | |||
-- Renderizar vários bosses | |||
---------------------------------------------------- | |||
for i = 1, n do | |||
html:wikitext(renderBoss(args, tostring(i))) | |||
end | |||
return tostring(html) | return tostring(html) | ||
Edição das 03h37min de 24 de novembro de 2025
A documentação para este módulo pode ser criada em Módulo:Gb/doc
local p = {}
--------------------------------------------------------
-- Função auxiliar: obtém argumento ou valor padrão
--------------------------------------------------------
local function getArg(args, key, default)
return mw.text.trim(args[key] or "") ~= "" and args[key] or default
end
--------------------------------------------------------
-- Renderiza um único boss (usado internamente)
--------------------------------------------------------
local function renderBoss(args, prefix)
local function g(k, default)
return getArg(args, prefix .. k, 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 fresco = g("fresco", "-")
local forte = g("forte", "-")
local reflete = g("reflete", "-")
local comum = g("comum", "")
local semiraro = g("semiraro", "")
local raro = g("raro", "")
local muitoRaro = g("muitoraro", "")
local html = mw.html.create("div")
:addClass("boss-card")
:css{
["background"] = "#18181b",
["border-radius"] = "12px",
padding = "30px",
color = "#fff",
width = "100%",
["box-sizing"] = "border-box",
["margin-bottom"] = "32px",
["font-family"] = "Verdana,sans-serif"
}
----------------------------------------------------
-- Cabeçalho
----------------------------------------------------
html:tag("div")
:css{ ["font-size"] = "1.5em", ["font-weight"] = "bold", ["margin-bottom"] = "10px" }
:wikitext(nome)
html:tag("div")
:css{ ["font-size"] = "95%", color = "#eaa85d", ["font-style"] = "italic", ["margin-bottom"] = "16px" }
:wikitext('"' .. frase .. '"')
----------------------------------------------------
-- Corpo principal
----------------------------------------------------
local main = html:tag("div")
:css{
display = "flex",
["justify-content"] = "space-between",
["align-items"] = "center",
["flex-wrap"] = "wrap",
gap = "20px"
}
main:tag("div")
:css{ ["flex"] = "none" }
:wikitext(string.format("[[Arquivo:%s|90px]]", img))
local statsBox = main:tag("div")
:css{ ["min-width"] = "200px", ["flex"] = "1" }
statsBox:tag("div"):wikitext(
string.format(
'<span style="color:#fb3d3d;font-weight:bold;font-size:1.15em;">❤️ %s</span> ' ..
'<span style="color:#ffe568;font-weight:bold;font-size:1.08em;">💰 %s</span> ' ..
'<span style="color:#6ca8fb;font-weight:bold;font-size:1.04em;">⚔️ %s</span>',
hp, exp, nivel
)
)
statsBox:tag("div")
:css{
["margin-top"] = "5px",
["font-size"] = "90%",
color = "#cfccff"
}
:wikitext(string.format(
"<b>Frescor:</b> %s <b>Forte:</b> %s <b>Reflete:</b> %s",
fresco, forte, reflete
))
----------------------------------------------------
-- Tabela de loot
----------------------------------------------------
local loot = html:tag("div")
:css{
["margin-top"] = "20px",
background = "#232329",
["border-radius"] = "10px",
padding = "18px"
}
local tableEl = loot:tag("table")
:css{
width = "100%",
color = "#fff",
["table-layout"] = "auto"
}
local function row(label, color, content)
local tr = tableEl:tag("tr")
tr:tag("th")
:css{
["text-align"] = "left",
color = color,
padding = "6px",
["font-size"] = "1.07em"
}
:wikitext(label)
tr:tag("td"):wikitext(content)
end
row("Comum:", "#f3e8bb", comum)
row("Semi-Raro:", "#aeccff", semiraro)
row("Raro:", "#e6e5ff", raro)
row("Muito Raro:", "#f9538f", muitoRaro)
return tostring(html)
end
--------------------------------------------------------
-- Função principal: suporta 1 boss ou vários bosses
--------------------------------------------------------
function p.bosses(frame)
local args = frame:getParent().args
local html = mw.html.create()
-- CSS responsivo
html:wikitext([[
<style>
@media screen and (max-width: 650px) {
.boss-card {
text-align: center !important;
}
}
</style>
]])
----------------------------------------------------
-- Detecta quantos bosses existem no bloco
----------------------------------------------------
local n = 0
for k, _ in pairs(args) do
local num = string.match(k, "^(%d+)nome$")
if num then
num = tonumber(num)
if num > n then n = num end
end
end
----------------------------------------------------
-- Se não encontrar numéricos, renderiza boss único
----------------------------------------------------
if n == 0 then
html:wikitext(renderBoss(args, ""))
return tostring(html)
end
----------------------------------------------------
-- Renderizar vários bosses
----------------------------------------------------
for i = 1, n do
html:wikitext(renderBoss(args, tostring(i)))
end
return tostring(html)
end
return p