Module:PerkOverview

local util_title = require('Module:TitleUtil') local util_table = require('Module:TableUtil') local GAMEORDER = mw.loadData('Module:GameOrder')

function makeGamesTable(frame, title) local games = frame:callParserFunction{ name = '#dpl', args = { '',			titleregexp = '^' .. title .. '/.*',			format = ',%PAGE%,;,' }	}	local games_tbl = mw.text.split(games, ';') table.remove(games_tbl,#games_tbl) for k, v in ipairs(games_tbl) do		games_tbl[k] = util_title.titleparts(v,1,2) end util_table.sortByKeyOrder(games_tbl,GAMEORDER) return games_tbl end

function writeSentence(games_tbl, title, canceled) local tbl = {} for k, v in ipairs(games_tbl) do		tbl[k] = string.format("%s",			title,			v,			v		) end return string.format(		"%s is a perk in %s. %sClick the tabs at the top of the page to see more information about the perk in each game.",		title,		util_table.printList(tbl),		printCanceledGames(canceled)	) end

function printCanceledGames(list) if not list then return '' end local tbl = mw.text.split(list,'%s*,%s*') for k, v in ipairs(tbl) do		tbl[k] = string.format("%s", v)	end return 'It was also to appear in the following canceled games: ' .. util_table.printList(tbl) .. '. ' end

function printInfobox(frame, args, games_tbl) for k, v in ipairs(games_tbl) do		args[k] = v	end return frame:expandTemplate{ title = 'Infobox perk/Overview', args = args } end

function printQuotation(frame, text, att) if not text then return '' end return frame:expandTemplate{title = 'Quotation', args = { text, att }} end

function printNavboxes(frame,games_tbl) local tbl = {} for k, v in ipairs(games_tbl) do local title = 'Navbox perks/' .. v		if mw.title.makeTitle('Template',title).exists then tbl[#tbl+1] = frame:expandTemplate{ title = title } end end return table.concat(tbl,'') end

local p = {} function p.main(frame) if frame == mw.getCurrentFrame then args = require('Module:ProcessArgs').merge(true) else frame = mw.getCurrentFrame end local title = mw.title.getCurrentTitle.text local games_tbl = makeGamesTable(frame, title) local output = { frame:expandTemplate{title = 'PerksTabsHeader'}, printInfobox(frame, args, games_tbl), writeSentence(games_tbl, title, args.canceled), printQuotation(frame, args.quotation, args.quotation2), printNavboxes(frame, games_tbl) }	return table.concat(output,'\n') end return p