Module:InfoboxWeapon
Jump to navigation
Jump to search
Documentation for this module may be created at Module:InfoboxWeapon/doc
-- Module:InfoboxWeapon
local p = {}
-- Define CSS 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_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_HORIZONTAL_GROUP = 'display: flex !important; justify-content: space-around !important; padding: 10px !important; text-align: center !important;'
local STYLE_HORIZONTAL_ITEM = 'flex: 1 !important; padding: 5px !important;'
local STYLE_HORIZONTAL_LABEL = 'font-weight: 500 !important; color: #4A5568 !important; font-size: 0.9em !important; margin-bottom: 3px !important;'
local STYLE_HORIZONTAL_VALUE = 'font-weight: bold !important; color: #4A5568 !important; font-size: 1.1em !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 horizontal group (for requirements)
local function make_horizontal_group(items)
local html = {}
table.insert(html, string.format('<div style="%s">', STYLE_HORIZONTAL_GROUP))
for _, item in ipairs(items) do
if item.value and item.value ~= '' then
table.insert(html, string.format(
'<div style="%s"><div style="%s">%s</div><div style="%s">%s</div></div>',
STYLE_HORIZONTAL_ITEM,
STYLE_HORIZONTAL_LABEL,
item.label,
STYLE_HORIZONTAL_VALUE,
item.value
))
end
end
table.insert(html, '</div>')
return table.concat(html, '\n')
end
-- Function to create category links
local function make_category_links(args)
local categories = {}
-- Type category
if args.type and args.type ~= '' then
table.insert(categories, string.format('[[Category:%s weapons]]', args.type))
end
-- Handedness category
if args.handedness and args.handedness ~= '' then
table.insert(categories, string.format('[[Category:%s-hand weapons]]', args.handedness))
end
-- Rarity category
if args.rarity and args.rarity ~= '' then
table.insert(categories, string.format('[[Category:%s weapons]]', args.rarity))
end
-- Class categories
if args.class1 and args.class1 ~= '' then
table.insert(categories, string.format('[[Category:%s weapons]]', args.class1))
end
if args.class2 and args.class2 ~= '' then
table.insert(categories, string.format('[[Category:%s weapons]]', args.class2))
end
if args.class3 and args.class3 ~= '' then
table.insert(categories, string.format('[[Category:%s weapons]]', args.class3))
end
-- Drop categories
if args.drop1 and args.drop1 ~= '' then
table.insert(categories, string.format('[[Category:Dropped by %s]]', args.drop1))
end
if args.drop2 and args.drop2 ~= '' then
table.insert(categories, string.format('[[Category:Dropped by %s]]', args.drop2))
end
return table.concat(categories, '\n')
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="weapon-infobox" style="%s">', STYLE_FLOATING))
-- Header/Title
table.insert(html, string.format('<div class="weapon-header" style="%s">%s</div>', STYLE_HEADER, name))
-- Image Section
if args.image and args.image ~= '' then
local image_link = string.format('[[File:%s|250px|alt=%s]]', args.image, name)
table.insert(html, string.format('<div class="weapon-image" style="padding: 10px !important; text-align: center !important;">%s</div>', image_link))
end
-- Start Weapon Information Section
table.insert(html, '<div class="weapon-section">')
table.insert(html, string.format('<div class="section-title" style="%s">Weapon Information</div>', STYLE_SECTION_TITLE))
-- Data Rows
table.insert(html, make_data_row('Type', args.type))
table.insert(html, make_data_row('Hands', args.handedness and args.handedness .. '-hand' or ''))
table.insert(html, make_data_row('Char Allocation', args.allocation and args.allocation .. ' slots' or ''))
table.insert(html, make_data_row('Primary Class', args.class1))
table.insert(html, make_data_row('Secondary Class', args.class2))
table.insert(html, make_data_row('Tertiary Class', args.class3))
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('Rarity', args.rarity))
table.insert(html, make_data_row('Value', args.value and args.value .. ' gold' or ''))
table.insert(html, make_data_row('Drops From', args.drop1))
table.insert(html, make_data_row('Also Drops From', args.drop2))
table.insert(html, make_data_row('Special Notes', args.notes))
table.insert(html, '</div>') -- End weapon-section
-- Requirements Section (Horizontal Group)
if args.level or args.str or args.dex or args.int then
table.insert(html, '<div class="weapon-section">')
table.insert(html, string.format('<div class="section-title" style="%s">Requirements</div>', STYLE_SECTION_TITLE))
local requirements = {
{label = 'Level', value = args.level},
{label = 'STR', value = args.str},
{label = 'DEX', value = args.dex},
{label = 'INT', value = args.int}
}
table.insert(html, make_horizontal_group(requirements))
table.insert(html, '</div>') -- End weapon-section
end
-- End container
table.insert(html, '</div>') -- End weapon-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