Difference between revisions of "Module:MonsterBox"
m |
|||
(24 intermediate revisions by 2 users not shown) | |||
Line 2: | Line 2: | ||
local pagename = mw.title.getCurrentTitle().fullText | local pagename = mw.title.getCurrentTitle().fullText | ||
+ | |||
+ | function basic_row(table, key, value) | ||
+ | local row = table:tag('tr') | ||
+ | |||
+ | row:tag('td'):wikitext('<b>' .. key .. '</b>') | ||
+ | row:tag('td'):wikitext(value) | ||
+ | |||
+ | return row | ||
+ | end | ||
function export.show(frame) | function export.show(frame) | ||
local table = mw.html.create('table'):addClass('coa-infobox'):addClass('monster') | local table = mw.html.create('table'):addClass('coa-infobox'):addClass('monster') | ||
− | -- | + | -- Create title header |
local td = table:tag('tr'):tag('td') | local td = table:tag('tr'):tag('td') | ||
− | td:addClass('infobox-header') | + | td:addClass('infobox-header'):attr('colspan', '2') |
− | td:attr('colspan', ' | + | :wikitext(frame.args.name) |
− | td: | + | |
− | td: | + | -- Add image box |
+ | table:tag('tr'):tag('td'):addClass('infobox-image'):attr('colspan', 2) | ||
+ | :wikitext('[[File:' .. frame.args.image .. ']]') | ||
+ | |||
+ | -- Separation header | ||
+ | table:tag('tr'):tag('td'):addClass('infobox-header'):attr('colspan', 2) | ||
+ | |||
+ | -- Monster basic attributes | ||
+ | basic_row(table, 'Level', frame.args.level) | ||
+ | basic_row(table, '[[HP]]', frame.args.hp) | ||
+ | if frame.args.xp then | ||
+ | basic_row(table, '[[Melee]] [[XP]]', frame.args.xp) | ||
+ | end | ||
+ | if frame.args.mgxp then | ||
+ | basic_row(table, '[[Magic]] [[XP]]', frame.args.mgxp) | ||
+ | end | ||
+ | if frame.args.rgxp then | ||
+ | basic_row(table, '[[Ranged]] [[XP]]', frame.args.rgxp) | ||
+ | end | ||
+ | basic_row(table, '[[Gold]]', frame.args.gold .. ' gold') | ||
+ | basic_row(table, 'Attack speed', frame.args.speed .. ' second(s)') | ||
+ | |||
+ | -- Optional values | ||
+ | if frame.args.damage then | ||
+ | basic_row(table, '[[Damage]]', frame.args.damage) | ||
+ | end | ||
+ | if frame.args.respawn then | ||
+ | basic_row(table, '[[Respawn]] time', frame.args.respawn .. ' second(s)') | ||
+ | end | ||
+ | if frame.args.found then | ||
+ | basic_row(table, 'Found', frame.args.found) | ||
+ | end | ||
+ | if frame.args.action then | ||
+ | basic_row(table, 'Special Action', frame.args.action) | ||
+ | end | ||
+ | if frame.args.date then | ||
+ | basic_row(table, 'Release Date', frame.args.date) | ||
+ | end | ||
+ | |||
+ | -- Separation header | ||
+ | table:tag('tr'):tag('td'):addClass('infobox-header'):attr('colspan', 2) | ||
return tostring(table) | return tostring(table) |
Latest revision as of 10:15, 15 July 2022
Documentation for this module may be created at Module:MonsterBox/doc
local export = {} local pagename = mw.title.getCurrentTitle().fullText function basic_row(table, key, value) local row = table:tag('tr') row:tag('td'):wikitext('<b>' .. key .. '</b>') row:tag('td'):wikitext(value) return row end function export.show(frame) local table = mw.html.create('table'):addClass('coa-infobox'):addClass('monster') -- Create title header local td = table:tag('tr'):tag('td') td:addClass('infobox-header'):attr('colspan', '2') :wikitext(frame.args.name) -- Add image box table:tag('tr'):tag('td'):addClass('infobox-image'):attr('colspan', 2) :wikitext('[[File:' .. frame.args.image .. ']]') -- Separation header table:tag('tr'):tag('td'):addClass('infobox-header'):attr('colspan', 2) -- Monster basic attributes basic_row(table, 'Level', frame.args.level) basic_row(table, '[[HP]]', frame.args.hp) if frame.args.xp then basic_row(table, '[[Melee]] [[XP]]', frame.args.xp) end if frame.args.mgxp then basic_row(table, '[[Magic]] [[XP]]', frame.args.mgxp) end if frame.args.rgxp then basic_row(table, '[[Ranged]] [[XP]]', frame.args.rgxp) end basic_row(table, '[[Gold]]', frame.args.gold .. ' gold') basic_row(table, 'Attack speed', frame.args.speed .. ' second(s)') -- Optional values if frame.args.damage then basic_row(table, '[[Damage]]', frame.args.damage) end if frame.args.respawn then basic_row(table, '[[Respawn]] time', frame.args.respawn .. ' second(s)') end if frame.args.found then basic_row(table, 'Found', frame.args.found) end if frame.args.action then basic_row(table, 'Special Action', frame.args.action) end if frame.args.date then basic_row(table, 'Release Date', frame.args.date) end -- Separation header table:tag('tr'):tag('td'):addClass('infobox-header'):attr('colspan', 2) return tostring(table) end return export