모듈:Infobox/Tournament

EDWARD201126 (토론 | 기여)님의 2022년 5월 11일 (수) 21:37 판 (새 문서: local util_args = require('Module:ArgsUtil') local util_cargo = require('Module:CargoUtil') local util_form = require('Module:FormUtil') local util_html = require('Module:HtmlUtil') l...)
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

이 모듈에 대한 설명문서는 모듈:Infobox/Tournament/설명문서에서 만들 수 있습니다

local util_args = require('Module:ArgsUtil')
local util_cargo = require('Module:CargoUtil')
local util_form = require('Module:FormUtil')
local util_html = require('Module:HtmlUtil')
local util_infobox = require('Module:InfoboxUtil')
local util_map = require("Module:MapUtil")
local util_table = require('Module:TableUtil')
local util_text = require('Module:TextUtil')
local util_time = require('Module:TimeUtil')
local util_title = require("Module:TitleUtil")
local util_vars = require("Module:VarsUtil")
local i18n = require('Module:i18nUtil')

local Country = require('Module:Country')
local Currency = require('Module:Currency')
local League = require('Module:League')
local Region = require('Module:Region')

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

local Infobox = require('Module:Infobox'):extends()

Infobox.LAYOUT = {
	sections = { 'Tournament Information', 'Location & Dates', 'Broadcast', 'Social Media & Links', 'Results' },
	contents = {
		{ 'Organizer', 'Rulebook', 'Sponsor',  'Format', 'PrizePool', 'Links' },
		{ 'Region', 'EventType', 'Country', 'Address', 'Venue', 'StartDate', 'EndDate', 'Date', },
		{ 'Casters', 'Streams', 'Schedule' },
		{ 'social', social = 'wide' },
		{ 'Winner', 'Second', 'Third', 'Fourth', 'Qualified',  },
	},
}
Infobox.type = 'Tournament'

local FORM_INFO = {
	SFS = { form = 'SpoilerFreeSchedule', template = 'SFS' },
	MCE = { form = 'MatchCalendarExport', template = 'MCE' }
}

local CCMT_PARAMS = { 'StandardName', 'TournamentLevel', 'IsQualifier', 'IsPlayoffs', 'IsOfficial', 'Year', 'LeagueIconKey' }

local ALLOWED_TIMEZONES = { 'PST', 'KST', 'CET' }

local h = {}
local p = {}

function p.main(frame)
	local args = util_args.merge()
	return Infobox(args):run()
end

function Infobox:validateArgs(args)
	if args.closest_timezone and not util_table.keyOf(ALLOWED_TIMEZONES, args.closest_timezone) then
		-- error(i18n.print('error_invalidTimezone'))
	end
end

function Infobox:castArgs(args)
	args.league = League(args.CM_StandardLeague or args.league)
	args.region = Region(args.region)
	args.country = Country(args.country)
	args.currency = Currency(args.currency)
	args.name = args.CM_StandardName or args.storedname or args.name
	args.type = util_text.ucfirst(args.type)
	args._display = args.name
	args.scripts_to_skip = util_text.split(args.scripts_to_skip)
end

function Infobox:getDisplay(args)
	local display = self:super('getDisplay', args, {})
	local tbl = {
		title = args.name,
		image = util_infobox.getFile(args.image, NOIMAGE),
		notice = args.rednotice,
		
		Organizer = args.organizer and util_table.concatFromArgs(args, 'organizer', '<br>'),
		Rulebook = args.rulebook and util_text.link(args.rulebook, 'Rulebook'),
		Sponsor = args.sponsor,
		Region = args.region:flair(),
		EventType = args.type,
		Country = args.country:flair(),
		Address = args.address,
		Venue = args.venue,
		Format = args.format,
		PrizePool = h.getPrizePool(args),
		Date = args.date,
		StartDate = args.sdate,
		EndDate = args.edate,
		Links = args.web and ('[%s Website]'):format(args.web),
		Casters = args.caster or args.casters,
		Streams = args.streams and (args.streams .. (args.linkstreams and '<br>[[#Streams|Full List]]' or '')),
		Schedule = h.makeSchedule(args),
	}
	return Infobox.mergeDisplay(display, tbl)
end

function h.getPrizePool(args)
	if not args.currency then
		return args.prizepool
	end
	return args.currency:short(args.prizepool)
end

function h.makeSchedule(args)
	local pagename = args.pagename or mw.title.getCurrentTitle().text
	if util_cargo.getOneResult({ tables = 'MatchSchedule', fields = 'OverviewPage', where = ('OverviewPage="%s"'):format(pagename) }) then
		local links = {
			('[%s Spoiler-Free Schedule]'):format(util_form.fullURL(FORM_INFO.SFS, { pagename })),
			('[%s Export to Google Calendar]'):format(util_form.fullURL(FORM_INFO.MCE, { pagename })),
		}
		return util_table.concat(links, '<br>')
	end
	return nil
end

function Infobox:getCargo(args)
	local cargo = self:super('getCargo', args, {})
	if util_args.castAsBool(args.nocargo) then return cargo end
	local tbl = {
		{
			_table = 'Tournaments',
			Name = args.name,
			DateStart = util_time.strToDateStr(args.sdate or args.date or '') or '',
			DateStartFuzzy = util_time.strToDateStrAllowYearOnly(args.sdate or args.date or '') or '',
			Date = util_time.strToDateStr(args.edate or args.date or '') or '',
			ClosestTimezone = args.closest_timezone,
			League = args.league,
			StandardLeague = args.league,
			Region = args.region,
			Prizepool = args.prizepool,
			Currency = args.currency,
			Country = args.country,
			Rulebook = args.rulebook,
			EventType = args.type,
			Links = args.web or args.website,
			Sponsors = args.sponsors,
			Organizer = args.organizer,
			OverviewPage = mw.title.getCurrentTitle().text,
			Split = args.split,
			SplitNumber = args.split_number,
			StandardName_Redirect = args.CM_StandardName and args.CM_StandardName:gsub('%#',''),
			SuppressTopSchedule = util_args.castAsBool(args.no_topschedule),
			ScrapeLink = args.scrape_link,
			AlternativeNames = h.getAlternativeNames(args),
			BasePage = util_title.target(args.basepage),
		}
	}
	for _, param in ipairs(CCMT_PARAMS) do
		tbl[1][param] = args['CM_' .. param]
	end
	util_table.mergeArrays(tbl, util_map.safe(args.scripts_to_skip, h.getTournamentScriptsToSkip))
	return util_table.mergeArrays(cargo, tbl)
end

function h.getAlternativeNames(args)
	if not args.league:exists() then return end
	local nameVars = {
		league = args.league:get('short'),
		split = args.split,
		year = args.CM_Year,
		playoffs = h.getPlayoffsName(args),
	}
	local orderCheck = { 'league', 'year', 'split', 'playoffs' }
	local orderOutput = { 'league', 'split', 'year', 'playoffs' }
	util_vars.log(h.concatAlternativeName(nameVars, orderOutput))
	if h.concatAlternativeName(nameVars, orderCheck) ~= args.name then return end
	return h.concatAlternativeName(nameVars, orderOutput)
end

function h.getPlayoffsName(args)
	if util_args.castAsBool(args.CM_IsPlayoffs) then return 'Playoffs' end
	return nil
end

function h.concatAlternativeName(nameVars, order)
	local tbl = {}
	for _, param in ipairs(order) do
		tbl[#tbl+1] = nameVars[param]
	end
	return table.concat(tbl, ' ')
end

function h.getTournamentScriptsToSkip(scriptToSkip)
	local ret = {
		_table = 'TournamentScriptsToSkip',
		OverviewPage = mw.title.getCurrentTitle().text,
		Script = scriptToSkip,
	}
	return ret
end

function Infobox:getCategories(args)
	local tbl = {
		args.country:exists() and ('%s Tournaments'):format(args.country:get('adjective')),
		not args.region:exists() and 'Tournaments Without Region',
		'Competitions',
		args.name:find('<br>') and 'Tournaments with br In Stored Name',
	}
	return tbl
end

function Infobox:getVariables(args)
	local variables = self:super('getVariables', args, {})
	local tbl = {
		['Event Date'] = args.edate or args.date,
		['Event Tier'] = args.type,
		['Event Name'] = args.name,
		['Event Region'] = args.region:get(),
	}
	return util_table.merge(variables, tbl)
end

return p