Module:MBNavbox: Difference between revisions
Jump to navigation
Jump to search
(Created page with "local p = {} function p.main(frame) local args = frame:getParent().args -- Color values extracted from your CSS local colors = { -- Light theme (default) theme_border_color = '#a1e9dc', theme_accent_label_color = '#ffffff', teal_600 = '#2c7a7b', teal_800 = '#234e52', teal_050 = '#e6fffa', teal_100 = '#b2f5ea', teal_200 = '#81e6d9', teal_700 = '#285e61', teal_900 = '#1d4044',...") |
mNo edit summary |
||
| Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
-- Helper function to check if a file exists (requires expensive function overhead, | |||
-- so we usually just assume the naming convention: Item Name.png) | |||
local function getIcon(item) | |||
return string.format('[[File:%s.png|22px|link=%s|alt=%s]]', item, item, item) | |||
end | |||
function p.main(frame) | function p.main(frame) | ||
local args = frame:getParent().args | local args = frame:getParent().args | ||
local title = args.title or 'Character Info' | |||
-- | -- MB Theme Colors (Map these to your Rarity/Tiers) | ||
local | local theme = { | ||
bg = '#1a1a1a', -- Deep dark background | |||
header = '#2c7a7b', -- Default Teal | |||
border = '#a1e9dc', -- Glowing border | |||
text = '#f5fdfb' | |||
} | } | ||
-- | -- Handle Rarity/Tier coloring | ||
if args.tier == '7' or args.tier == 'Noble' then | |||
theme.header = 'linear-gradient(135deg, #38b2ac 0%, #2c7a7b 100%)' | |||
theme.border = '#81e6d9' | |||
end | end | ||
-- Title | -- Container | ||
local container = mw.html.create('table') | |||
local | :addClass('mb-navbox') | ||
:css({ | |||
['width'] = '100%', | |||
['background'] = theme.bg, | |||
['border'] = '2px solid ' .. theme.border, | |||
['border-radius'] = '8px', | |||
['color'] = theme.text, | |||
['border-collapse'] = 'separate', | |||
['border-spacing'] = '2px', | |||
['margin'] = '10px 0' | |||
}) | |||
-- Title Bar | |||
container:tag('tr'):tag('th') | |||
:attr('colspan', '2') | |||
:css({ | |||
['background'] = theme.header, | |||
['padding'] = '10px', | |||
['font-size'] = '1.1em', | |||
['text-shadow'] = '1px 1px 2px #000' | |||
}) | |||
:wikitext(title) | |||
-- Row Logic (Smarter Loop) | |||
local i = 1 | |||
while args['group' .. i] or args['list' .. i] do | |||
local groupName = args['group' .. i] or '' | |||
local listData = args['list' .. i] or '' | |||
local | local row = container:tag('tr') | ||
-- Group Header (Left side) | |||
row:tag('td') | |||
:addClass('mb-group') | |||
:css({ | |||
['background'] = 'rgba(255,255,255,0.05)', | |||
['width'] = '150px', | |||
['font-weight'] = 'bold', | |||
['padding'] = '8px', | |||
['border-right'] = '1px solid ' .. theme.border .. '33' | |||
}) | |||
:wikitext(groupName) | |||
-- List Content (Right side) | |||
local listCell = row:tag('td') | |||
:addClass('mb-content') | |||
:css('padding', '8px') | |||
-- SMART PARSER: Check if we should auto-icon | |||
if args.auto_icons == 'yes' then | |||
local items = mw.text.split(listData, ',%s*') -- Split by comma | |||
local formattedItems = {} | |||
for _, item in ipairs(items) do | |||
-- Remove bullets if present to clean string | |||
local cleanItem = item:gsub('^%s*%*%s*', '') | |||
table.insert(formattedItems, getIcon(cleanItem) .. ' [[' .. cleanItem .. ']]') | |||
end | end | ||
listCell:wikitext(table.concat(formattedItems, ' • ')) | |||
else | |||
listCell:wikitext(listData) | |||
end | end | ||
i = i + 1 | |||
end | end | ||
return tostring(container) | |||
return tostring( | |||
end | end | ||
return p | return p | ||
Latest revision as of 07:19, 19 December 2025
Documentation for this module may be created at Module:MBNavbox/doc
local p = {}
-- Helper function to check if a file exists (requires expensive function overhead,
-- so we usually just assume the naming convention: Item Name.png)
local function getIcon(item)
return string.format('[[File:%s.png|22px|link=%s|alt=%s]]', item, item, item)
end
function p.main(frame)
local args = frame:getParent().args
local title = args.title or 'Character Info'
-- MB Theme Colors (Map these to your Rarity/Tiers)
local theme = {
bg = '#1a1a1a', -- Deep dark background
header = '#2c7a7b', -- Default Teal
border = '#a1e9dc', -- Glowing border
text = '#f5fdfb'
}
-- Handle Rarity/Tier coloring
if args.tier == '7' or args.tier == 'Noble' then
theme.header = 'linear-gradient(135deg, #38b2ac 0%, #2c7a7b 100%)'
theme.border = '#81e6d9'
end
-- Container
local container = mw.html.create('table')
:addClass('mb-navbox')
:css({
['width'] = '100%',
['background'] = theme.bg,
['border'] = '2px solid ' .. theme.border,
['border-radius'] = '8px',
['color'] = theme.text,
['border-collapse'] = 'separate',
['border-spacing'] = '2px',
['margin'] = '10px 0'
})
-- Title Bar
container:tag('tr'):tag('th')
:attr('colspan', '2')
:css({
['background'] = theme.header,
['padding'] = '10px',
['font-size'] = '1.1em',
['text-shadow'] = '1px 1px 2px #000'
})
:wikitext(title)
-- Row Logic (Smarter Loop)
local i = 1
while args['group' .. i] or args['list' .. i] do
local groupName = args['group' .. i] or ''
local listData = args['list' .. i] or ''
local row = container:tag('tr')
-- Group Header (Left side)
row:tag('td')
:addClass('mb-group')
:css({
['background'] = 'rgba(255,255,255,0.05)',
['width'] = '150px',
['font-weight'] = 'bold',
['padding'] = '8px',
['border-right'] = '1px solid ' .. theme.border .. '33'
})
:wikitext(groupName)
-- List Content (Right side)
local listCell = row:tag('td')
:addClass('mb-content')
:css('padding', '8px')
-- SMART PARSER: Check if we should auto-icon
if args.auto_icons == 'yes' then
local items = mw.text.split(listData, ',%s*') -- Split by comma
local formattedItems = {}
for _, item in ipairs(items) do
-- Remove bullets if present to clean string
local cleanItem = item:gsub('^%s*%*%s*', '')
table.insert(formattedItems, getIcon(cleanItem) .. ' [[' .. cleanItem .. ']]')
end
listCell:wikitext(table.concat(formattedItems, ' • '))
else
listCell:wikitext(listData)
end
i = i + 1
end
return tostring(container)
end
return p