Módulo:CharacterInfobox: mudanças entre as edições

De Cronicas Eternas Wiki
Sem resumo de edição
Sem resumo de edição
 
(3 revisões intermediárias pelo mesmo usuário não estão sendo mostradas)
Linha 1: Linha 1:
local p = {}
local p = {}
-- Lista de valores que indicam ausência de informação
local ignoredValues = {
    ["Unknown"] = true,
    ["None"] = true,
    ["Nenhum"] = true,
    ["-"] = true
}


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


    -- Define as seções e os campos em uma tabela ordenada
     local sections = {
     local sections = {
         {
         {
Linha 78: Linha 85:
     )
     )


     -- Adiciona as seções e os campos em ordem fixa
     -- Adiciona as seções e os campos
     for _, section in ipairs(sections) do
     for _, section in ipairs(sections) do
         local title = section.title
         local sectionContent = {}
        local fields = section.fields
 
         infobox = infobox .. string.format('<div style="text-align:center; background:#ddd; font-size:110%%; padding:4px; margin-top:5px;">%s</div>', title)
         -- Monta os campos com conteúdo da seção
         for _, field in ipairs(fields) do
         for _, field in ipairs(section.fields) do
             local label, value = field[1], field[2]
             local label, value = field[1], field[2]
             if value and value ~= "" then
             if value and value ~= "" and not ignoredValues[value] then
                 infobox = infobox .. string.format('<div style="padding:2px 5px;"><strong>%s:</strong> %s</div>', label, value)
                 table.insert(sectionContent, string.format('<div style="padding:2px 5px;"><strong>%s:</strong> %s</div>', label, value))
             end
             end
        end
        -- Adiciona a seção somente se tiver conteúdo
        if #sectionContent > 0 then
            infobox = infobox .. string.format('<div style="text-align:center; background:#ddd; font-size:110%%; padding:4px; margin-top:5px;">%s</div>', section.title)
            infobox = infobox .. table.concat(sectionContent)
         end
         end
     end
     end

Edição atual tal como às 00h05min de 24 de novembro de 2024

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

local p = {}

-- Lista de valores que indicam ausência de informação
local ignoredValues = {
    ["Unknown"] = true,
    ["None"] = true,
    ["Nenhum"] = true,
    ["-"] = true
}

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 sectionContent = {}

        -- Monta os campos com conteúdo da seção
        for _, field in ipairs(section.fields) do
            local label, value = field[1], field[2]
            if value and value ~= "" and not ignoredValues[value] then
                table.insert(sectionContent, string.format('<div style="padding:2px 5px;"><strong>%s:</strong> %s</div>', label, value))
            end
        end

        -- Adiciona a seção somente se tiver conteúdo
        if #sectionContent > 0 then
            infobox = infobox .. string.format('<div style="text-align:center; background:#ddd; font-size:110%%; padding:4px; margin-top:5px;">%s</div>', section.title)
            infobox = infobox .. table.concat(sectionContent)
        end
    end

    infobox = infobox .. '</div>'

    return infobox
end

return p