Module:Infobox/Player

local lang = mw.getLanguage('en') local m_team = require('Module:Team') local m_role = require('Module:Role') --local m_champion = require('Module:Champion') local m_region = require('Module:Region') local m_country = require('Module:Country') local social = require('Module:Infobox/Social') local teamhist = require('Module:Infobox/TeamHist') local util_infobox = require('Module:InfoboxUtil') local util_html = require('Module:HtmlUtil') local util_cargo = require('Module:CargoUtil') local util_dpl = require('Module:DPLUtil') local util_table = require('Module:TableUtil') local util_args = require('Module:ArgsUtil')

local NOIMAGE = 'Unknown Infobox Image - Player.png'

local LAYOUT = { tabs = 'PlayerTabsHeader', sections = { 'Background Information', 'Competitive', 'Social Media & Links', 'Team History' }, contents = { { 'Name', 'Country', 'Birthday', 'Residency', 'ResidencyPrev' }, { 'Team', 'Role', 'PreviousRole', 'Champions', 'CompIDs', 'SoloIDs' }, { 'social', social = 'wide' }, { 'teamhist', teamhist = 'wide' }, },	i18n = { -- not a true i18n as-is but could be made into one whatever Country = 'Country of Birth', CompIDs = 'Competitive IDs', SoloIDs = 'Soloqueue IDs', PreviousRole = 'Previous Role(s)', Champions = 'Favorite Champs', ResidencyPrev = 'Prev Residencies', } }

local directstore = { ID = 'id', AltIDs = 'compIDs', Stream = 'stream', Twitter = 'twitter', Facebook = 'facebook', Askfm = 'askfm', Reddit = 'reddit', Youtube = 'youtube', Youtube2 = 'Youtube2', Weibo = 'weibo', Vk = 'vk', Instagram = 'instagram', IsRetired = 'isretired', IsPersonality = 'checkboxIsPersonality' }

local h = {} -- helper functions

function h.getProcessed(args) local tbl = { pagename = mw.title.getCurrentTitle.text, bday = util_infobox.makeBday(args.birth_date_year, args.birth_date_month, args.birth_date_day), lc = args.id and lang:lcfirst(args.id) == args.id, }	tbl.redirects = util_dpl.whatRedirectsHere(		tbl.pagename,		{ notuses = 'Template:NoDPL/PlayerRedirects' }	) return tbl end

function h.processDisplay(args, processed) local social = social.makeSocialSection(args) local display = { title = args.id or processed.pagename, image = util_infobox.getFile(args.image, NOIMAGE), notice = args.isretired == 'Yes' and 'Player has retired.', -- background info Name = args.name and (args.name .. (args.nativename and (' (%s)'):format(args.nativename) or '')), Country = args.country and m_country.rightlong(args.country), Birthday = processed.bday.displayandage, Residency = args.residency and m_region.rightmedium(args.residency), ResidencyPrev = util_table.concatFromArgs(args, 'residency-prev', ' ', m_region.rightmedium), -- competitive Team = args.team and util_table.concatFromArgs(args, 'team', ' ', m_team.rightmediumlinked), Role = args.role and m_role.rolename(args.role), PreviousRole = args.prev1 and util_table.concatFromArgs(args, 'prev', ' ', m_role.roleonly), --Champions = util_table.concatFromArgs(args, 'favchamp', '', m_champion.onlyimagelinked), CompIDs = util_table.concatFromArgs(args, 'compID',', '), SoloIDs = args.ids, -- social social = next(social) and tostring(util_html.blockBox(social)), }	processed.last = teamhist.teamHist(display, args) return display end

function h.processCargo(args, processed) local idlist = mw.clone(processed.redirects) idlist[#idlist+1] = processed.pagename local cargo = { {			_table = 'Players', IDList = table.concat(idlist,','), Image = args.image or NOIMAGE, Name = args.name, NativeName = args.nativename, NameAlphabet = args.namealphabet, NameFull = args.name and (args.name .. (args.nativename and (' (%s)'):format(args.nativename) or '')), Country = args.country, Age = processed.bday.age or '', Birthdate = processed.bday.store or '', ResidencyFormer = args['residency-prev1'], Team = args.team and m_team.teamlinkname(args.team), Team2 = args.team2 and m_team.teamlinkname(args.team2) or '', TeamSystem = 'PC', Team2System = 'PC', Residency = args.residency and m_region.long(args.residency), Role = args.role, --FavChamps = util_table.concatFromArgs(args, 'favchamp', ','), TeamLast = processed.last.team, RoleLast = processed.last.role and m_role.roleonly(processed.last.role) or args.role, IsSubstitute = args.checkboxIsSub, IsLowercase = processed.lc and 'Yes' or 'No' },		{			_table = 'PlayerRedirects', AllName = processed.pagename }	}	h.addUnprocessedArgs(cargo[1], args, directstore) for _, v in ipairs(processed.redirects) do		cargo[#cargo+1] = h.saveRedirectCargo(v) end return cargo end

function h.addUnprocessedArgs(tbl, args, arglist) for k, v in pairs(arglist) do		tbl[k] = args[v] end end

function h.saveRedirectCargo(name) return { _table = 'PlayerRedirects', AllName = name, OtherName = name } end

function h.processVariables(args, processed) local name = mw.text.split(args.name or '', ' ') local firstname = table.remove(name, 1) local lastname = table.concat(name, ' ') local tbl = { twitchstream = args.stream and (args.stream):find('twitch.tv',1,true) and 'true', STREAM = args.stream and args.stream:gsub('.*/([^/]*)','%1'), id = args.id, firstname = firstname, lastname = lastname, nativename = args.nativename, namealphabet = args.namealphabet, lastteam = processed.last.team, team = args.team and m_team.teamname(args.team), teamStr = args.team and m_team.teamlinkname(args.team), role = args.role or processed.lastrole, sharesrole = args.checkboxSharesRole, isasub = args.checkboxIsSub, ispersonality = args.checkboxIsPersonality, lastteampresent = processed.last.date and processed.last.date:find('Present') and 'true', whatredirectshere = table.concat(processed.redirects,';'), suppressorgnavbox = args.checkboxSuppressOrgNavbox == 'Yes' and 'true', }	local i = 2 repeat thisteam = 'team' .. i		tbl[thisteam] = args[thisteam] and m_team.teamlinkname(args[thisteam]) i = i + 1 until(not args[thisteam]) return tbl end

function h.processCategories(args, processed) local tbl = { args.residency and m_region.adjective(args.residency) .. ' Residents', args['residency-prev1'] and ('Former %s Residents'):format(m_region.adjective(args['residency-prev1'])), args['residency-prev2'] and ('Former %s Residents'):format(m_region.adjective(args['residency-prev2'])), (not args.role) and 'Players Without Role', processed.last.team == 'Suspended' and processed.last.date:find('Present') and 'Suspended Players', (not args.team and args.isretired ~= 'Yes') and 'Free Agents', args.isretired == 'Yes' and 'Retired Players', args.birth_date_year and 'Players Born In ' .. args.birth_date_year }	if args.country then if args.checkboxIsPersonality == 'Yes' then tbl[#tbl+1] = ('%s Personalities'):format(m_country.localization(args.country)) elseif args.checkboxIsPersonality == 'No' then tbl[#tbl+1] = 'Players Born in ' .. m_country.namethe(args.country) end end return tbl end

local p = {} function p.main(args) local processed = h.getProcessed(args) local settings = { lc = processed.lc, nocargo = mw.title.getCurrentTitle.nsText ~= '' or args.nocargo, nocat = mw.title.getCurrentTitle.nsText ~= '' or args['no-cat'], }	local display = h.processDisplay(args, processed) local cargo = h.processCargo(args, processed) local variables = h.processVariables(args, processed) local categories = h.processCategories(args, processed) return { display = display, cargo = cargo, settings = settings, categories = categories, variables = variables, layout = LAYOUT } end

return p