Module:InfoboxCharacter

From MB Wiki
Revision as of 12:09, 22 December 2025 by Ais (talk | contribs)
Jump to navigation Jump to search

Documentation for this module may be created at Module:InfoboxCharacter/doc

-- Module:InfoboxCharacter
local p = {}

-- Define the CSS variables/hex codes as Lua constants for use in inline styles
local STYLE_FLOATING = 'float: right !important; clear: right !important; max-width: 300px !important; margin: 0 0 16px 16px !important; border: 1px solid #1a6a7a !important; border-radius: 10px !important; background-color: #FFFFFF !important; font-size: .9em !important;'
local STYLE_HEADER = 'background: #1a6a7a !important; color: white !important; padding: 8px 10px !important; text-align: center !important; font-weight: bold !important; font-size: 1.5em !important; border-top-left-radius: 10px !important; border-top-right-radius: 10px !important;'
local STYLE_DATAROW = 'display: flex !important; justify-content: space-between !important; padding: 5px 10px !important; border-bottom: 1px dotted #A2A9B1 !important;'
local STYLE_DATALABEL = 'font-weight: 500 !important; color: #4A5568 !important; width: 40% !important; text-align: left !important;'
local STYLE_DATAVALUE = 'color: #4A5568 !important; text-align: right !important; width: 60% !important;'

-- Function to generate a single data row
local function make_data_row(label, value)
    if value and value ~= '' then
        return string.format(
            '<div style="%s"><span style="%s">%s:</span> <span style="%s">%s</span></div>',
            STYLE_DATAROW,
            STYLE_DATALABEL,
            label,
            STYLE_DATAVALUE,
            value
        )
    end
    return ''
end

-- Main function to create the infobox HTML
function p.infobox(frame)
    local args = frame:getParent().args
    
    local name = args.name or 'Unknown Character'
    local image = args.image
    
    local html = {}
    
    -- Start the main infobox container
    table.insert(html, string.format('<div class="character-infobox" style="%s">', STYLE_FLOATING))
    
    -- Header/Title
    table.insert(html, string.format('<div class="character-header" style="%s">%s</div>', STYLE_HEADER, name))
    
    -- Image Section
    if image and image ~= '' then
        local image_link = string.format('[[File:%s|250px|alt=%s]]', image, name)
        table.insert(html, string.format('<div class="character-image" style="padding: 10px !important; text-align: center !important;">%s</div>', image_link))
    end
    
    -- Start Quick Facts Section
    table.insert(html, '<div class="character-section">')
    table.insert(html, '<div class="section-title" style="padding: 5px 10px; font-weight: bold; border-bottom: 1px solid #A2A9B1;">Quick Facts</div>')
    
    -- Data Rows (Using make_data_row function)
    table.insert(html, make_data_row('Nickname', args.nickname))
    table.insert(html, make_data_row('Age', args.age))
    table.insert(html, make_data_row('Race', args.race))
    table.insert(html, make_data_row('Element', args.element))
    table.insert(html, make_data_row('Occupation', args.occupation)) -- ADDED THIS LINE
    table.insert(html, make_data_row('Weapon', args.weapon))
    table.insert(html, make_data_row('Guild Status', args.guild_status))
    table.insert(html, make_data_row('Birthday', args.birthday))
    table.insert(html, make_data_row('Romance', args.romance))
    table.insert(html, make_data_row('Residency', args.residency)) -- ADDED THIS LINE
    table.insert(html, make_data_row('Voice Style', args.voice_style)) -- ADDED THIS LINE (optional)
    
    -- End sections and container
    table.insert(html, '</div>') -- End character-section
    table.insert(html, '</div>') -- End character-infobox
    
    return table.concat(html, '\n')
end

return p