Module:InfoboxNPC
Jump to navigation
Jump to search
Documentation for this module may be created at Module:InfoboxNPC/doc
local p = {}
-- Define the CSS variables/hex codes as Lua constants for use in inline styles
-- Refined color scheme: Using #0E4D64 (deep teal-blue) for header, softer #E8F4F8 for section bg
local STYLE_FLOATING = 'float: right !important; clear: right !important; max-width: 300px !important; margin: 0 0 16px 16px !important; border: 1px solid #B0C4D9 !important; border-radius: 10px !important; background-color: #FFFFFF !important; font-size: .9em !important; box-shadow: 0 2px 8px rgba(14, 77, 100, 0.1) !important;'
local STYLE_HEADER = 'background: linear-gradient(135deg, #0E4D64 0%, #1a6a7a 100%) !important; color: white !important; padding: 10px 12px !important; text-align: center !important; font-weight: bold !important; font-size: 1.5em !important; border-top-left-radius: 9px !important; border-top-right-radius: 9px !important; text-shadow: 1px 1px 2px rgba(0,0,0,0.2) !important;'
local STYLE_DATAROW = 'display: flex !important; justify-content: space-between !important; padding: 6px 10px !important; border-bottom: 1px dotted #D1DCE6 !important;'
local STYLE_DATALABEL = 'font-weight: 600 !important; color: #2C3E50 !important; width: 40% !important; text-align: left !important;'
local STYLE_DATAVALUE = 'color: #34495E !important; text-align: right !important; width: 60% !important;'
-- Function to generate a single data row
local function make_data_row(label, value, is_optional)
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
)
elseif is_optional then
return ''
else
-- For non-optional fields, show "Unknown" if empty
return string.format(
'<div style="%s"><span style="%s">%s:</span> <span style="%s"><em>Unknown</em></span></div>',
STYLE_DATAROW,
STYLE_DATALABEL,
label,
STYLE_DATAVALUE
)
end
end
-- Function to create a section divider
local function make_section(title)
return string.format(
'<div class="section-title" style="padding: 8px 10px; background-color: #E8F4F8 !important; color: #0E4D64 !important; font-weight: bold; font-size: 1.1em; border-top: 1px solid #B0C4D9; border-bottom: 1px solid #B0C4D9; margin-top: 5px;">%s</div>',
title
)
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="npc-infobox" style="%s">', STYLE_FLOATING))
-- Header/Title
table.insert(html, string.format('<div class="npc-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|class=npc-portrait]]', image, name)
table.insert(html, string.format('<div class="npc-image" style="padding: 12px !important; text-align: center !important; background-color: #F8FAFC;">%s</div>', image_link))
end
-- Start Quick Facts Section
table.insert(html, make_section('Character Details'))
-- Core Character Data Rows
table.insert(html, make_data_row('Gender', args.gender))
table.insert(html, make_data_row('Age', args.age, true)) -- optional
table.insert(html, make_data_row('Race', args.race))
table.insert(html, make_data_row('Role', args.role))
table.insert(html, make_data_row('Alignment', args.alignment, true))
table.insert(html, make_data_row('Location', args.location))
-- Start Gameplay Section (if relevant data exists)
local has_gameplay_data = args.body_weight or args.category or args.sub
if has_gameplay_data then
table.insert(html, make_section('Game Information'))
table.insert(html, make_data_row('Body Type', args.body_weight, true))
table.insert(html, make_data_row('Category', args.category, true))
table.insert(html, make_data_row('Subcategory', args.sub, true))
end
-- Start Schedule Section (if schedule data exists)
local has_schedule = args.schedule1 or args.schedule2 or args.schedule3
if has_schedule then
table.insert(html, make_section('Daily Schedule'))
-- Create a mini-schedule table
local schedule_html = '<div style="padding: 5px 10px; font-size: 0.95em;">'
if args.schedule1 and args.schedule1 ~= '' then
schedule_html = schedule_html .. '<div style="padding: 3px 0;">• ' .. args.schedule1 .. '</div>'
end
if args.schedule2 and args.schedule2 ~= '' then
schedule_html = schedule_html .. '<div style="padding: 3px 0;">• ' .. args.schedule2 .. '</div>'
end
if args.schedule3 and args.schedule3 ~= '' then
schedule_html = schedule_html .. '<div style="padding: 3px 0;">• ' .. args.schedule3 .. '</div>'
end
schedule_html = schedule_html .. '</div>'
table.insert(html, schedule_html)
end
-- Metadata note (for internal references)
if args.note and args.note ~= '' then
table.insert(html, make_section('Notes'))
table.insert(html, string.format('<div style="padding: 8px 10px; font-size: 0.85em; color: #7B8A8B; font-style: italic; background-color: #F5F7FA; border-radius: 4px; margin: 5px 10px;">%s</div>', args.note))
end
-- End container
table.insert(html, '</div>') -- End npc-infobox
return table.concat(html, '\n')
end
return p