Module:Infobox/Player

From Leaguepedia | League of Legends Esports Wiki
Jump to: navigation, search

To edit the documentation or categories for this module, click here.


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 util_vars = require('Module:VarsUtil')

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

local LAYOUT = {
	tabs = 'PlayerTabsHeader',
	sections = { 'Background Information', 'Competitive', 'Social Media & Links', 'Team History' },
	contents = {
		{ 'Name', 'Country', 'Nationality', 'Birthday', 'Residency', 'ResidencyPrev' },
		{ 'Team', 'Role', 'PreviousRole', 'Champions', 'CompIDs', 'SoloIDs' },
		{ 'social', social = 'wide' },
		{ 'teamhist', teamhist = 'wide' },
	},
	i18nFile = 'Infobox/Player'
}

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 processed = {
		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,
		role = args.role and m_role.rolename(args.role),
	}
	processed.redirects = util_dpl.whatRedirectsHere(
		processed.pagename,
		{ notuses = 'Template:NoDPL/PlayerRedirects' }
	)
	return processed
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 = util_args.castAsBool(args.isretired) 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),
		Nationality = args.nationality and util_args.splitMapConcat(args.nationality, nil, m_country.rightlong, '<br>'),
		Birthday = processed.bday.displayandage,
		Residency = args.residency and m_region.rightmedium(args.residency),
		ResidencyPrev = util_table.concatFromArgs(args, 'residency-prev', '<br>', m_region.rightmedium),
		
		-- competitive
		Team = args.team and util_table.concatFromArgs(args, 'team', '<br>', m_team.rightmediumlinked),
		Role = processed.role,
		PreviousRole = args.prev1 and util_table.concatFromArgs(args, 'prev', '<br>', 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 = 'InfoboxPlayer',
			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,
			Nationality = args.nationality,
			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,
			UniqueLine = processed.pagename .. '_1',
		}
	}
	h.addUnprocessedArgs(cargo[1], args, directstore)
	for k, v in ipairs(processed.redirects) do
		cargo[#cargo+1] = h.saveRedirectCargo(v, k, processed.pagename)
	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, i, title)
	return {
		_table = 'PlayerRedirects',
		AllName = name,
		OtherName = name,
		UniqueLine = ('%s_%s'):format(title, i + 1)
	}
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 not util_args.castAsBool(args.isretired) and 'Free Agents',
		util_args.castAsBool(args.isretired) and 'Retired Players',
		args.birth_date_year and 'Players Born In ' .. args.birth_date_year,
		processed.role == 'Coach' and 'Coaches'
	}
	
	if args.country then
		if util_args.castAsBool(args.checkboxIsPersonality) then
			tbl[#tbl+1] = ('%s Personalities'):format(m_country.localization(args.country))
		else
			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