Module:Game

local p = {}

local args = {} local root

local function renderTitle if not args.title then return end

root :tag( 'tr' ) :tag( 'th' ) :attr( 'colspan', 2 ) :addClass( 'infobox_heading' ) :wikitext( args.title ) end

local function renderImages if not args.image then root:wikitext( '[ [ Category:Pages needing box artwork ] ]' ) end

local data = mw.html.create:wikitext( '' )

addRow( {       data = tostring( data ),        class = args.imageclass,        rowclass = 'mw-row-no-collapse'    } ) end

local function renderRows -- Gets the union of the header and data argument numbers, -- and renders them all in order using addRow. local rownums = union( getArgNums( 'header' ), getArgNums( 'data' ) ) table.sort( rownums ) for k, num in ipairs( rownums ) do       addRow( {            header = args[ 'header' .. tostring( num ) ],            label = args[ 'label' .. tostring( num ) ],            labelstyle = args[ 'labelstyle' .. tostring( num ) ],            data = args[ 'data' .. tostring( num ) ],            rowclass = args[ 'rowclass' .. tostring( num ) ],        } ) end end

local function addRow( rowArgs ) -- Adds a row to the infobox, with either a header cell -- or a label/data cell combination. if rowArgs.header then root :tag( 'tr' ) :addClass( rowArgs.rowclass ) :tag( 'th' ) :attr( 'colspan', 2 ) :css( 'text-align', 'center' ) :cssText( rowArgs.headerstyle ) :wikitext( rowArgs.header ) elseif rowArgs.data then local row = root:tag( 'tr' ):addClass( rowArgs.rowclass )

if rowArgs.label then row :tag( 'th' ) :cssText( args.labelstyle ) :wikitext( rowArgs.label ) :done end local dataCell = row:tag( 'td' ) if not rowArgs.label then dataCell :attr( 'colspan', 2 ) :css( 'text-align', 'center' ) end dataCell :wikitext( rowArgs.data ) end end

local function _game root = mw.html.create( 'table' ) root :addClass( 'infobox' ) :addClass( 'bordered' ) :addClass( 'mw-collapsible' ) :attr( 'cellpadding', 2 ) renderTitle renderImages

return tostring(root) end

function p.game( frame ) local title = frame:getParent.args[ 'title' ] or mw.title.getCurrentTitle.text args.title = title

return _game end

return p