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

De Cronicas Eternas Wiki
Criou página com 'local p = {} function p.infobox(frame) local args = frame:getParent().args local sections = { ["INFORMAÇÃO BÁSICA"] = { {"Nome", args["name"]}, {"Tamanho", args["size"]}, {"Tipo", args["type"]}, {"Subtipo", args["subtype"]}, {"Alinhamento", args["alignment"]}, {"Nível de Desafio", args["challenge_rating"]}, {"Divindade Padroeira", args["patron_deity"]}, {...'
 
Sem resumo de edição
 
(10 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,
    ["--"] = true,
    [""] = true
}


function p.infobox(frame)
function p.infobox(frame)
Linha 5: Linha 15:


     local sections = {
     local sections = {
         ["INFORMAÇÃO BÁSICA"] = {
         {
            {"Nome", args["name"]},
            title = "INFORMAÇÃO BÁSICA",
            {"Tamanho", args["size"]},
            fields = {
            {"Tipo", args["type"]},
                {"Nome", args["name"]},
            {"Subtipo", args["subtype"]},
                {"Tamanho", args["size"]},
            {"Alinhamento", args["alignment"]},
                {"Tipo", args["type"]},
            {"Nível de Desafio", args["challenge_rating"]},
                {"Subtipo", args["subtype"]},
            {"Divindade Padroeira", args["patron_deity"]},
                {"Alinhamento", args["alignment"]},
            {"Movimento", args["movement"]},
                {"Nível de Desafio", args["challenge_rating"]},
            {"Visão", args["vision"]},
                {"Divindade Padroeira", args["patron_deity"]},
            {"Ciclo Ativo", args["active_cycle"]},
                {"Movimento", args["movement"]},
            {"Dieta", args["diet"]},
                {"Visão", args["vision"]},
            {"Tempo de Vida", args["lifespan"]},
                {"Ciclo Ativo", args["active_cycle"]},
            {"Localidade", args["locality"]},
                {"Dieta", args["diet"]},
            {"Linguagens", args["languages"]},
                {"Tempo de Vida", args["lifespan"]},
            {"Subespécies", args["subspecies"]},
                {"Localidade", args["locality"]},
            {"Clima", args["climate"]},
                {"Linguagens", args["languages"]},
            {"Terreno", args["terrain"]},
                {"Subespécies", args["subspecies"]},
                {"Clima", args["climate"]},
                {"Terreno", args["terrain"]},
            },
         },
         },
         ["APARÊNCIA"] = {
         {
            {"Altura", args["height"]},
            title = "APARÊNCIA",
            {"Comprimento", args["length"]},
            fields = {
            {"Envergadura da Asa", args["wingspan"]},
                {"Altura", args["height"]},
            {"Peso", args["weight"]},
                {"Comprimento", args["length"]},
            {"Cor da Pele", args["skin_color"]},
                {"Envergadura da Asa", args["wingspan"]},
            {"Cor do Cabelo", args["hair_color"]},
                {"Peso", args["weight"]},
            {"Tipo de Cabelo", args["hair_type"]},
                {"Cor da Pele", args["skin_color"]},
            {"Penas", args["feathers"]},
                {"Cor do Cabelo", args["hair_color"]},
            {"Cor de Olho", args["eye_color"]},
                {"Tipo de Cabelo", args["hair_type"]},
            {"Tipo Corporal", args["body_type"]},
                {"Penas", args["feathers"]},
                {"Cor de Olho", args["eye_color"]},
                {"Tipo Corporal", args["body_type"]},
            },
         },
         },
     }
     }


     local infobox = string.format('<div style="width:22em; background:#f9f9f9; border:1px solid #aaa; float:right; padding:5px; font-size:90%%;">' ..
    -- Início da infobox
        '<div style="text-align:center; background:#ccc; font-size:120%%; padding:4px;">%s</div>', args["name"] or "NOME DA ESPÉCIE")
     local infobox = '<div style="width:22em; background:#f9f9f9; border:1px solid #aaa; float:right; padding:5px; font-size:90%;">'


     for section, fields in pairs(sections) do
     -- Adiciona a imagem no topo, se fornecida
         infobox = infobox .. string.format('<div style="text-align:center; background:#ddd; font-size:110%%; padding:4px; margin-top:5px;">%s</div>', section)
    if args["image"] and args["image"] ~= "" then
         for _, field in ipairs(fields) do
        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 da espécie
    infobox = infobox .. string.format(
        '<div style="text-align:center; background:#ccc; font-size:120%%; padding:4px;">%s</div>',
        args["name"] or "NOME DA ESPÉCIE"
    )
 
    -- 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]
             local label, value = field[1], field[2]
             if value and value ~= "" then
            -- Verifica se o valor é válido (não está na lista de ignorados)
                 infobox = infobox .. string.format('<div style="padding:2px 5px;"><strong>%s:</strong> %s</div>', label, value)
             if value and not ignoredValues[value:match("^%s*(.-)%s*$")] then
                 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 00h11min de 24 de novembro de 2024

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

local p = {}

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

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

    local sections = {
        {
            title = "INFORMAÇÃO BÁSICA",
            fields = {
                {"Nome", args["name"]},
                {"Tamanho", args["size"]},
                {"Tipo", args["type"]},
                {"Subtipo", args["subtype"]},
                {"Alinhamento", args["alignment"]},
                {"Nível de Desafio", args["challenge_rating"]},
                {"Divindade Padroeira", args["patron_deity"]},
                {"Movimento", args["movement"]},
                {"Visão", args["vision"]},
                {"Ciclo Ativo", args["active_cycle"]},
                {"Dieta", args["diet"]},
                {"Tempo de Vida", args["lifespan"]},
                {"Localidade", args["locality"]},
                {"Linguagens", args["languages"]},
                {"Subespécies", args["subspecies"]},
                {"Clima", args["climate"]},
                {"Terreno", args["terrain"]},
            },
        },
        {
            title = "APARÊNCIA",
            fields = {
                {"Altura", args["height"]},
                {"Comprimento", args["length"]},
                {"Envergadura da Asa", args["wingspan"]},
                {"Peso", args["weight"]},
                {"Cor da Pele", args["skin_color"]},
                {"Cor do Cabelo", args["hair_color"]},
                {"Tipo de Cabelo", args["hair_type"]},
                {"Penas", args["feathers"]},
                {"Cor de Olho", args["eye_color"]},
                {"Tipo Corporal", args["body_type"]},
            },
        },
    }

    -- 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 da espécie
    infobox = infobox .. string.format(
        '<div style="text-align:center; background:#ccc; font-size:120%%; padding:4px;">%s</div>',
        args["name"] or "NOME DA ESPÉCIE"
    )

    -- 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]
            -- Verifica se o valor é válido (não está na lista de ignorados)
            if value and not ignoredValues[value:match("^%s*(.-)%s*$")] 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