Module:Retirement

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

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 m_role = require('Module:Role')

local h = {}

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

function h.castArgs(args)
	for _, v in ipairs({ 'unretires', 'sub', 'trainee', }) do
		args[v] = util_args.castAsBool(args[v])
	end
	args.team = args.team and m_team.teamlinkname(args.team)
	args.role = m_role.storename(args.role) or args.role
	args.newrole = m_role.storename(args.newrole) or args.newrole
	args.role_display = m_role.medium(args.role) or args.role
	args.newrole_display = m_role.medium(args.newrole) or args.newrole
end

function h.writeSentence(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.getNewRoleSentence(args),
		ROLE = args.newrole,
		NEW_JOIN = h.getUnretireNewTeam(args),
		NEW_TEAM = m_team.rightmediumlinked(args.team),
	}
	return util_sentence.makeReplacements(h.getSentencePreload(args), replacements)
end

function h.getNewRoleSentence(args)
	if not args.newrole then return '' end
	return i18n.default('newrole')
end

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

function h.getSentencePreload(args)
	if args.unretires then return i18n.default('unretire') end
	return i18n.default('retire')
end

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

function h.getNewsCargo(args)
	local tbl = {
		Players = args.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
	local tbl = util_news.getRCFieldsFromPlayerAndArgs(h.getPlayerFromArgs(args), args)
	util_table.merge(
		tbl,
		h.getOldRoleSpecificCargo(args),
		h.getNewRoleCargo(args),
		h.getAdditionalRosterChangeCargo(args)
	)
	tbl.RoleDisplay = args.role_display
	util_news.storeRosterChangesRow(tbl)
end

function h.getPlayerFromArgs(args)
	local ret = {
		Player = args.player,
		Sub = args.sub,
		Trainee = args.trainee,
		Role = args.role,
	}
	return ret
end

function h.getOldRoleSpecificCargo(args)
	if args.newrole then return {} end
	local ret = {
		Direction = 'Leave',
		Status = args.status,
	}
	return ret
end

function h.getNewRoleCargo(args)
	if args.unretires then return h.getNewRoleUnretiresCargo(args) end
	local ret = {
		Role = args.newrole,
		RoleDisplay = args.newrole_display,
		Direction = 'Leave',
	}
	return ret
end

function h.getNewRoleUnretiresCargo(args)
	local ret = {
		Role = args.newrole or args.role,
		Direction = 'Join',
	}
	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