Módulo:CharacterInfobox: mudanças entre as edições
De Cronicas Eternas Wiki
Sem resumo de edição |
Sem resumo de edição |
||
Linha 4: | Linha 4: | ||
local args = frame:getParent().args | local args = frame:getParent().args | ||
local sections = { | local sections = { | ||
{ | { | ||
Linha 78: | Linha 77: | ||
) | ) | ||
-- Adiciona as seções e os campos | -- Adiciona as seções e os campos | ||
for _, section in ipairs(sections) do | for _, section in ipairs(sections) do | ||
local | local hasContent = false | ||
-- Verifica se há pelo menos um valor preenchido na seção | |||
for _, field in ipairs(fields) do | for _, field in ipairs(section.fields) do | ||
local | local _, value = field[1], field[2] | ||
if value and value ~= "" then | if value and value ~= "" then | ||
infobox = infobox .. string.format('<div style="padding:2px 5px;"><strong>%s:</strong> %s</div>', label, value) | hasContent = true | ||
break | |||
end | |||
end | |||
-- Renderiza a seção somente se houver conteúdo | |||
if hasContent then | |||
infobox = infobox .. string.format('<div style="text-align:center; background:#ddd; font-size:110%%; padding:4px; margin-top:5px;">%s</div>', section.title) | |||
for _, field in ipairs(section.fields) do | |||
local label, value = field[1], field[2] | |||
if value and value ~= "" then | |||
infobox = infobox .. string.format('<div style="padding:2px 5px;"><strong>%s:</strong> %s</div>', label, value) | |||
end | |||
end | end | ||
end | end |
Edição das 00h01min de 24 de novembro de 2024
A documentação para este módulo pode ser criada em Módulo:CharacterInfobox/doc
local p = {}
function p.infobox(frame)
local args = frame:getParent().args
local sections = {
{
title = "INFORMAÇÕES BÁSICAS",
fields = {
{"Títulos", args["titles"]},
{"Conhecido como", args["known_as"]},
{"Apelidos", args["nicknames"]},
{"Nome verdadeiro", args["real_name"]},
{"Lar", args["home"]},
{"Lares anteriores", args["previous_homes"]},
{"Sexo", args["gender"]},
{"Espécie", args["species"]},
{"Etnia", args["ethnicity"]},
{"Ocupação", args["occupation"]},
{"Idade", args["age"]},
{"Divindade Padroeira", args["patron_deity"]},
{"Linguagens", args["languages"]},
},
},
{
title = "DATAS",
fields = {
{"Nascido", args["born"]},
{"Transformado", args["transformed"]},
{"Morte", args["death"]},
{"Destruído", args["destroyed"]},
},
},
{
title = "FAMÍLIA",
fields = {
{"Pais", args["parents"]},
{"Irmãos", args["siblings"]},
{"Filhos", args["children"]},
{"Parentes", args["relatives"]},
},
},
{
title = "DINASTIA",
fields = {
{"Início de reinado", args["reign_start"]},
{"Fim de reinado", args["reign_end"]},
{"Predecessor", args["predecessor"]},
{"Sucessor", args["successor"]},
},
},
{
title = "INFORMAÇÕES MECÂNICAS",
fields = {
{"Alinhamento", args["alignment"]},
{"Nível de desafio", args["challenge_rating"]},
{"Classe", args["class"]},
},
},
}
-- Início da infobox
local infobox = '<div style="width:22em; background:#f9f9f9; border:1px solid #aaa; float:right; padding:5px; font-size:90%;">'
-- Adiciona a imagem no topo, se fornecida
if args["image"] and args["image"] ~= "" then
infobox = infobox .. string.format(
'<div style="text-align:center; margin-bottom:10px;">%s</div>',
frame:preprocess(string.format('[[File:%s|center|frameless|200px]]', args["image"]))
)
end
-- Adiciona o nome do personagem
infobox = infobox .. string.format(
'<div style="text-align:center; background:#ccc; font-size:120%%; padding:4px;">%s</div>',
args["name"] or "NOME DO PERSONAGEM"
)
-- Adiciona as seções e os campos
for _, section in ipairs(sections) do
local hasContent = false
-- Verifica se há pelo menos um valor preenchido na seção
for _, field in ipairs(section.fields) do
local _, value = field[1], field[2]
if value and value ~= "" then
hasContent = true
break
end
end
-- Renderiza a seção somente se houver conteúdo
if hasContent then
infobox = infobox .. string.format('<div style="text-align:center; background:#ddd; font-size:110%%; padding:4px; margin-top:5px;">%s</div>', section.title)
for _, field in ipairs(section.fields) do
local label, value = field[1], field[2]
if value and value ~= "" then
infobox = infobox .. string.format('<div style="padding:2px 5px;"><strong>%s:</strong> %s</div>', label, value)
end
end
end
end
infobox = infobox .. '</div>'
return infobox
end
return p