Module:Game

local getArgs = require('Module:Arguments').getArgs

local p = {}

local args = {} local root

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 ) :cssText( rowArgs.rowstyles or 'text-align: center;' ) end dataCell :wikitext( rowArgs.data ) end end

local function renderTitle args.title = args.title or mw.title.getCurrentTitle.text

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

local function renderImage if not args.image then root:wikitext( '' ) return end

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

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

local function renderRows if args.japanese then addRow( {label = 'Japanese title', data = args.japanese} ) end addRow( { label = 'Developer(s)', data = args.developer, rowclass = 'mw-row-no-collapse' } ) addRow( { label = 'Publisher(s)', data = args.publisher } ) if args.distributor then addRow( {label = 'Distributor(s)', data = args.distributor} ) end if args.designer then addRow( {label = 'Designer(s)', data = args.designer} ) end if args.version then addRow( {label = 'Latest version', data = args.version} ) end addRow( { label = 'Release date(s)', labelstyle = 'white-space: nowrap;', data = args.released } ) addRow( { label = 'Genre(s)', data = args.genre, rowclass = 'mw-row-no-collapse' } ) addRow( { label = 'System(s)', data = args.systems, rowclass = 'mw-row-no-collapse' } ) if args.players then addRow( {label = 'Players', data = args.players} ) end if args.modes then addRow( {label = 'Modes', data = args.modes} ) end if args.ratings then addRow( { label = 'Rating(s)', data = args.ratings, rowclass = 'mw-row-no-collapse' } ) end if args.input then addRow( {label = 'Modes', data = args.input} ) end if args.expansion then addRow( { label = 'Expansion pack(s)', labelstyle = 'white-space: nowrap;', data = args.expansion, rowclass = 'mw-row-no-collapse' } ) end if args['preceded by'] then addRow( { label = 'Preceded by', labelstyle = 'white-space: nowrap;', data = "" .. args['preceded by'] .. "" } ) end if args['followed by'] then addRow( { label = 'Followed by', labelstyle = 'white-space: nowrap;', data = "" .. args['followed by'] .. "" } ) end if args.series then local data2 = '' if args.series2 then data2 = ' and ' .. args.series2 .. '' end addRow( { label = 'Series', data =  .. args.series ..  .. data2, rowclass = 'mw-row-no-collapse' } ) end if args.website then addRow( {label = 'Website', data = args.website} ) end if args.pcgamingwiki then local data1 = '' .. mw.title.getCurrentTitle.text .. ' at PCGamingWiki' addRow( { header = 'PCGamingWiki', headerstyle = 'background-color: #c8c8c8;', rowclass = 'mw-row-no-collapse' } ) addRow( { data = data1, rowclass = 'mw-row-no-collapse', rowstyles = 'text-align: left;' } ) end end

local function renderSocialRows local twitterData, facebookData, twitchData local pagename = mw.uri.encode( mw.title.getCurrentTitle.text, "PATH" )

if args.twitch then twitchData = '[https://www.twitch.tv/directory/game/' .. mw.uri.encode( args.twitch, "PATH" ) .. ' ' .. args.twitch .. ' Channel]' else twitchData = '[https://www.twitch.tv/directory/game/' .. pagename .. ' ' .. mw.title.getCurrentTitle.text .. ' Channel]' end

if args.twitter then twitterData = '[https://twitter.com/' .. args.twitter .. ' ' .. args.twitter .. ']'   else twitterData = '[https://twitter.com/search?f=user&q=' .. pagename .. ' Search]' end

if args.facebook then facebookData = '[https://www.facebook.com/' .. args.facebook .. ' ' .. args.facebook .. ']'   else facebookData = '[https://www.facebook.com/search/pages/?q=' .. pagename .. ' Search]' end

addRow( { rowclass = 'mw-row-no-collapse', label = 'Twitch', data = twitchData } ) addRow( { rowclass = 'mw-row-no-collapse', label = 'Twitter', data = twitterData } ) addRow( { rowclass = 'mw-row-no-collapse', label = 'Facebook', data = facebookData } )

end

local function renderTrackingCategories root:wikitext( '' )

if not args.developer or not args.publisher or not args.released or not args.genre or not args.systems then root:wikitext( '' ) end

if args.series then root:wikitext( '' ) end if args.series2 then root:wikitext( '' ) end end

local function _game root = mw.html.create( 'table' )

root :addClass( 'infobox' ) :addClass( 'bordered' ) :addClass( 'mw-collapsible' ) :attr( 'cellpadding', 2 )

renderTitle renderImage renderRows

root:wikitext( mw.getCurrentFrame:preprocess( '' ) )

renderSocialRows renderTrackingCategories

return tostring(root) end

function p.game( frame ) args = getArgs( frame, { wrappers = 'Template:Game' } )

return _game end

return p