Leaguepedia | League of Legends Esports Wiki
Advertisement
Leaguepedia | League of Legends Esports Wiki

To edit the documentation or categories for this module, click here. This module has an i18n file. Click here to edit it.


local util_args = require('Module:ArgsUtil')
local util_cargo = require("Module:CargoUtil")
local util_esports = require("Module:EsportsUtil")
local util_html = require("Module:HtmlUtil")
local util_map = require('Module:MapUtil')
local util_news = require("Module:NewsUtil")
local util_sentence = require("Module:SentenceUtil")
local util_table = require("Module:TableUtil")
local util_title = require("Module:TitleUtil")
local util_text = require("Module:TextUtil")
local util_vars = require("Module:VarsUtil")
local i18n = require("Module:I18nUtil")
local COLUMNS = util_news.COLUMNS

local m_team = require('Module:Team')
local RoleList = require('Module:RoleList')

local SentencePrinterAbstract = require('Module:RosterChangeSentencePrinterAbstract')
local SP = SentencePrinterAbstract:finalExtends()

local h = {}

local p = {}
function p.main(frame)
	local args = util_args.merge()
	util_cargo.setStoreNamespace('Data')
	i18n.init('Retirement')
	h.validateArgs(args)
	h.castArgs(args)
	util_news.setId()
	local newsSentencePrinter = SP(args)
	args.Sentence = newsSentencePrinter:run(args, { "player1", player1 = args}).Sentence
	h.storeRetireCargo(args)
	local newsCargo = h.getNewsCargo(args)
	util_cargo.store(newsCargo)
	h.storeRosterChangeCargo(args)
	return util_news.makeSentenceOutput(args, newsCargo)
end

function h.validateArgs(args)
	if args.team and args.team:lower() == 'free agent' then
		error(i18n.print('error_FreeAgentAsTeam'))
	end
end

function h.castArgs(args)
	for _, v in ipairs({ 'unretires', 'sub', 'trainee', 'with_coaching', 'as_player', 'wildrift' }) do
		args[v] = util_args.castAsBool(args[v])
	end
	args.playerData = util_news.getPlayerFromArg(args.player)
	args.player = args.playerData.Player
	args.newPlayerData = util_news.getPlayerFromArg(args.new_player) -- this may be {}
	args.team = args.team and m_team.teamlinkname(args.team)
	args.Role = args.playerData.Role
	args.Roles = args.playerData.Roles
	args.role = args.playerData.Roles -- for Module:EsportsUtil
	args.NewRole = args.newPlayerData.Role -- this may be nil, which is kinda yikes
	args.NewRoles = args.newPlayerData.Roles -- this may be nil, which is kinda yikes
	args.NewOrOldRole = args.NewRole or args.Role
	args.NewOrOldRoles = args.NewRoles or args.Roles
	args.role_display = args.Roles:names{len='name', sep='/'}
	args.new_role_display = args.NewRoles and args.NewRoles:names{len='name', sep='/'}
	args.new_or_old_role_display = args.NewOrOldRoles:names{len='name', sep='/'}
	if args.unretires then args.class = 'join' end
end

function SP:groupPlayersByPreload(listOfPlayers)
	return listOfPlayers
end

function SP:getTextForReplacements(row, args)
	if args.unretires then return i18n.default('unretire') end
	return i18n.default('retire')
end

function SP:getReplacements(players, args)
	-- currently this only supports 1 player but that could be changed later
	-- write it in the most general way possible
	-- ofc, the rest of the code doesn't remotely support having more than 1 player listed but shh
	local replacements = {
		PLAYERS = util_esports.playerWithRole(args),
		RETIRE = util_sentence.getConjugation('retire', 1),
		COME = util_sentence.getConjugation('come', 1),
		ARE = util_sentence.getConjugation('are', 1),
		NEW_ROLE = h.getnew_roleSentence(args),
		ROLE = args.NewRoles and args.NewRoles:names{len='sentence'},
		NEW_JOIN = h.getUnretireNewTeam(args),
		NEW_TEAM = m_team.rightmediumlinked(args.team),
		WITH_COACHING = args.with_coaching and i18n.default('with_coaching') or '',
		AS_PLAYER = args.as_player and i18n.default('as_player') or '',
		WILDRIFT = args.wildrift and i18n.default('wildrift') or '',
		WILDRIFT_LINK = args.wildrift and util_text.intLinkOrText('wildrift:' .. args.player, i18n.default('wildriftLinkText')),
	}
	return replacements
end

function h.getnew_roleSentence(args)
	if not args.NewRoles then return '' end
	return i18n.default('new_role')
end

function h.getUnretireNewTeam(args)
	if not args.team then return '' end
	return i18n.default('newteam')
end

function h.storeRetireCargo(args)
	local tbl = {
		_table = 'Retirements',
		Player = args.playerData.Player,
		NewsId = util_news.getId(),
		Unretires = args.unretires,
	}
	util_cargo.store(tbl)
end

function h.getNewsCargo(args)
	local tbl = {
		Players = args.playerData.Player,
	}
	util_table.mergeDontOverwrite(
		tbl,
		h.getTeamNewsCargo(args),
		util_news.getNewsCargoFieldsFromArgs(args)
	)
	return tbl
end

function h.getTeamNewsCargo(args)
	if not args.team then return {} end
	local ret = {
		SubjectType = 'Team',
		Subject = args.team,
		Teams = args.team,
	}
	return ret
end

function h.storeRosterChangeCargo(args)
	if not args.team then return end
	h.storeRosterChangeCargoLeave(args)
	h.storeRosterChangeCargoJoin(args)
end

function h.storeRosterChangeCargoLeave(args)
	local tbl = util_news.getRCFieldsFromPlayerAndArgs(args.playerData, args)
	util_table.merge(
		tbl,
		h.getOldRoleCargo(args),
		h.getAdditionalRosterChangeCargo(args)
	)
	util_news.storeRosterChangesRow(tbl)
end

function h.storeRosterChangeCargoJoin(args)
	if not args.NewRoles then return end
	local tbl = util_news.getRCFieldsFromPlayerAndArgs(args.playerData, args)
	util_table.merge(
		tbl,
		h.getnew_roleCargo(args),
		h.getAdditionalRosterChangeCargo(args)
	)
	util_news.storeRosterChangesRow(tbl)
end

function h.getPlayerFromArgs(args)
	local ret = {
		Player = args.playerData.Player,
		Role = args.Role,
		Roles = args.Roles,
	}
	return ret
end

function h.getOldRoleCargo(args)
	local ret = {
		Direction = 'Leave',
		Status = args.status,
		RoleDisplay = args.Roles,
		RolesIngame = args.Roles:ingame(),
		RolesStaff = args.Roles:staff(),
	}
	if args.unretires then ret.Direction = 'Join' end
	return ret
end

function h.getnew_roleCargo(args)
	if args.unretires then return h.getnew_roleUnretiresCargo(args) end
	local ret = {
		Role = args.NewRole,
		Roles = args.NewRoles,
		RolesIngame = args.NewRoles:ingame(),
		RolesStaff = args.NewRoles:staff(),
		RoleDisplay = args.NewRoles,
		Direction = 'Join',
		
		-- we need to overwrite this from NewsUtil even if it's nil here
		RoleModifier = args.NewRoles.modifier or '',
	}
	return ret
end

function h.getnew_roleUnretiresCargo(args)
	-- this could be input via |player= or |new_player=
	local ret = {
		Role = args.NewOrOldRole,
		RolesIngame = args.NewOrOldRoles:ingame():names(),
		RolesStaff = args.NewOrOldRoles:staff():names(),
		RoleDisplay = args.NewOrOldRoles,
	}
	return ret
end

function h.getAdditionalRosterChangeCargo(args)
	local ret = {
		Preload = h.getPreload(args.team),
	}
	return ret
end

function h.getPreload(team)
	if not team or team:lower() == 'tbd' or team:lower() == 'free agent' then
		return 'retirement_no_team'
	end
	return 'retirement'
end

return p
Advertisement