Module:InfoboxMonster
Jump to navigation
Jump to search
Documentation for this module may be created at Module:InfoboxMonster/doc
-- Module:InfoboxMonster
local p = {}
-- Define CSS styles (matching weapon infobox for consistency)
local STYLE_FLOATING = 'float: right !important; clear: right !important; max-width: 350px !important; margin: 0 0 16px 16px !important; border: 1px solid #7a1a1a !important; border-radius: 10px !important; background-color: #FFFFFF !important; font-size: .9em !important;'
local STYLE_HEADER = 'background: #7a1a1a !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_SECTION_TITLE = 'padding: 5px 10px !important; color: #4A5568 !important; font-weight: bold !important; border-bottom: 1px solid #A2A9B1 !important; margin: 10px 0 5px 0 !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;'
local STYLE_PHASE_HEADER = 'background: #f0f0f0 !important; padding: 8px 10px !important; font-weight: bold !important; color: #7a1a1a !important; border-left: 3px solid #7a1a1a !important; margin: 10px 0 5px 0 !important;'
local STYLE_PHASE_DESC = 'padding: 5px 10px 10px 10px !important; color: #4A5568 !important; line-height: 1.4 !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
-- Function to generate phase sections
local function make_phase_section(phase_num, description)
if description and description ~= '' then
local html = {}
table.insert(html, string.format('<div style="%s">Phase %s</div>', STYLE_PHASE_HEADER, phase_num))
table.insert(html, string.format('<div style="%s">%s</div>', STYLE_PHASE_DESC, description))
return table.concat(html, '\n')
end
return ''
end
-- Function to create category links
local function make_category_links(args)
local categories = {}
-- Element category
if args.element and args.element ~= '' then
table.insert(categories, string.format('[[Category:%s monsters]]', args.element))
end
-- Type category
if args.type and args.type ~= '' then
table.insert(categories, string.format('[[Category:%s type monsters]]', args.type))
end
-- Difficulty category
if args.difficulty and args.difficulty ~= '' then
table.insert(categories, string.format('[[Category:%s difficulty monsters]]', args.difficulty))
end
-- Zone category
if args.zone and args.zone ~= '' then
table.insert(categories, string.format('[[Category:%s monsters]]', args.zone))
end
-- Size category
if args.size and args.size ~= '' then
table.insert(categories, string.format('[[Category:%s monsters]]', args.size))
end
-- Behavior category
if args.behavior and args.behavior ~= '' then
table.insert(categories, string.format('[[Category:%s monsters]]', args.behavior))
end
return table.concat(categories, '\n')
end
-- Function to format list items (for drops, weaknesses, etc.)
local function format_list(value, delimiter)
if not value or value == '' then return '' end
local items = {}
for item in string.gmatch(value, '([^'..delimiter..']+)') do
item = item:gsub('^%s*(.-)%s*$', '%1') -- trim whitespace
if item ~= '' then
table.insert(items, string.format('<li>%s</li>', item))
end
end
if #items > 0 then
return string.format('<ul style="margin: 0 !important; padding-left: 20px !important;">%s</ul>', table.concat(items, ''))
end
return ''
end
-- Main function
function p.infobox(frame)
local args = frame:getParent().args
-- Use title parameter or page name as default
local name = args.title or args.name or frame:getParent().title.text
local html = {}
-- Start the main infobox container
table.insert(html, string.format('<div class="monster-infobox" style="%s">', STYLE_FLOATING))
-- Header/Title
table.insert(html, string.format('<div class="monster-header" style="%s">%s</div>', STYLE_HEADER, name))
-- Image Section
if args.image and args.image ~= '' then
local image_link = string.format('[[File:%s|300px|alt=%s]]', args.image, name)
table.insert(html, string.format('<div class="monster-image" style="padding: 10px !important; text-align: center !important;">%s</div>', image_link))
end
-- Start Basic Information Section
table.insert(html, '<div class="monster-section">')
table.insert(html, string.format('<div class="section-title" style="%s">Basic Information</div>', STYLE_SECTION_TITLE))
-- Data Rows
table.insert(html, make_data_row('Element', args.element))
table.insert(html, make_data_row('Type', args.type))
table.insert(html, make_data_row('Size', args.size))
table.insert(html, make_data_row('Zone', args.zone))
table.insert(html, make_data_row('Habitat', args.habitat))
table.insert(html, make_data_row('Difficulty', args.difficulty))
table.insert(html, make_data_row('Behavior', args.behavior))
table.insert(html, make_data_row('HP', args.hp))
table.insert(html, make_data_row('Attack', args.attack))
table.insert(html, make_data_row('Defense', args.defense))
table.insert(html, make_data_row('Magic', args.magic))
table.insert(html, make_data_row('Speed', args.speed))
table.insert(html, make_data_row('EXP', args.exp))
table.insert(html, make_data_row('Gold', args.gold))
table.insert(html, '</div>') -- End basic info section
-- Weaknesses Section
if args.weaknesses and args.weaknesses ~= '' then
table.insert(html, '<div class="monster-section">')
table.insert(html, string.format('<div class="section-title" style="%s">Weaknesses</div>', STYLE_SECTION_TITLE))
table.insert(html, format_list(args.weaknesses, ','))
table.insert(html, '</div>')
end
-- Resistances Section
if args.resistances and args.resistances ~= '' then
table.insert(html, '<div class="monster-section">')
table.insert(html, string.format('<div class="section-title" style="%s">Resistances</div>', STYLE_SECTION_TITLE))
table.insert(html, format_list(args.resistances, ','))
table.insert(html, '</div>')
end
-- Drops Section
if args.drops and args.drops ~= '' then
table.insert(html, '<div class="monster-section">')
table.insert(html, string.format('<div class="section-title" style="%s">Drops</div>', STYLE_SECTION_TITLE))
table.insert(html, format_list(args.drops, ','))
table.insert(html, '</div>')
end
-- Phases Section
if args.phase1 or args.phase2 or args.phase3 or args.phase4 then
table.insert(html, '<div class="monster-section">')
table.insert(html, string.format('<div class="section-title" style="%s">Battle Phases</div>', STYLE_SECTION_TITLE))
table.insert(html, make_phase_section('1', args.phase1))
table.insert(html, make_phase_section('2', args.phase2))
table.insert(html, make_phase_section('3', args.phase3))
table.insert(html, make_phase_section('4', args.phase4))
table.insert(html, '</div>')
end
-- Description/Behavior Section
if args.description and args.description ~= '' then
table.insert(html, '<div class="monster-section">')
table.insert(html, string.format('<div class="section-title" style="%s">Description & Behavior</div>', STYLE_SECTION_TITLE))
table.insert(html, string.format('<div style="%s">%s</div>', STYLE_PHASE_DESC, args.description))
table.insert(html, '</div>')
end
-- Tactics Section
if args.tactics and args.tactics ~= '' then
table.insert(html, '<div class="monster-section">')
table.insert(html, string.format('<div class="section-title" style="%s">Combat Tactics</div>', STYLE_SECTION_TITLE))
table.insert(html, string.format('<div style="%s">%s</div>', STYLE_PHASE_DESC, args.tactics))
table.insert(html, '</div>')
end
-- End container
table.insert(html, '</div>') -- End monster-infobox
-- Add categories (hidden from display, for wiki organization)
table.insert(html, '\n<!-- Categories -->\n' .. make_category_links(args))
return table.concat(html, '\n')
end
return p