Module:Infobox tournament: Difference between revisions

From TwogPedia
No edit summary
mNo edit summary
Line 7: Line 7:
local LocationWidget = require('Module:Infobox/Widget/Location')
local LocationWidget = require('Module:Infobox/Widget/Location')
local RowWidget = require('Module:Infobox/Widget/Row')
local RowWidget = require('Module:Infobox/Widget/Row')
VariablesLua = mw.ext.VariablesLua


local Flags = require('Module:Flags')
local Infobox = {}
local Infobox = {}
local function prizeToString(nr)
if nr == nil then return 'TBD' end
local prize = ''
    local reversed = string.reverse(tostring(nr))
    for k = 1, #reversed do
    prize = reversed:sub(k, k) .. prize
    if k % 3 == 0 and k < #reversed then prize =  ',' .. prize end
    k = k + 1
    end
    return prize
end


function Infobox.main(frame)
function Infobox.main(frame)
Line 16: Line 28:
local currentTitleSplit = mw.text.split(mw.title.getCurrentTitle().text, '/')
local currentTitleSplit = mw.text.split(mw.title.getCurrentTitle().text, '/')
local headerNode
local headerNode = Header.make(args.title or currentTitleSplit[2], args.logoLight, args.logoDark, args.logoAll)
if args.logoAll or args.logoLight or args.logoDark then
headerNode = Header.make(args.title or currentTitleSplit[2], args.logoLight, args.logoDark, args.logoAll)
end
local container = mw.html.create('div')
local container = mw.html.create('div')
Line 40: Line 49:
if args.type then
if args.type then
container:node(RowWidget.make('Type', args.type))
container:node(RowWidget.make('Type', args.type))
end
if args.female_only == 'Yes' then
container:node(RowWidget.make('Female only', 'Yes'))
end
if args.educational then
container:node(RowWidget.make('Educational', args.educational))
end
end
Line 55: Line 72:
if args.prize then
if args.prize then
container:node(RowWidget.make('Prize pool', args.prize))
local prize = prizeToString(tonumber(args.prize))
if args.currency then prize = prizeToString(tonumber(args.localPrize)) .. ' ' .. args.currency else prize = '$' .. prize end
container:node(RowWidget.make('Prize pool', prize))
end
end
if args.start then
if args.start then
VariablesLua.vardefine( 'startDate', args.start )
container:node(RowWidget.make('Start date', args.start))
container:node(RowWidget.make('Start date', args.start))
end
end
if args['end'] then
if args['end'] then
VariablesLua.vardefine( 'endDate', args['end'] )
container:node(RowWidget.make('End date', args['end']))
container:node(RowWidget.make('End date', args['end']))
end
end
Line 70: Line 91:
end
end
if args.teams then
if args.participants then
container:node(RowWidget.make('Teams', args.teams))
container:node(RowWidget.make('Participants', args.participants))
end
end
Line 79: Line 100:
container:node(Subheader.make('Links'))
container:node(Subheader.make('Links'))
-- Check if there is a "links" argument and then do magic to add them all to arguments
if args.links then
local splitLinks = mw.text.split(args.links, ',')
for i = 1, #splitLinks do
local split = mw.text.split(splitLinks[i], '=')
args[split[1]] = split[2]
end
end
local transformedLinks = Links.transform(args)
local transformedLinks = Links.transform(args)

Revision as of 11:15, 29 September 2023

Documentation for this module may be created at Module:Infobox tournament/doc

local getArgs = require('Module:Arguments').getArgs
local Links = require('Module:Links')
local Header = require('Module:Infobox/Widget/Header')
local Subheader = require('Module:Infobox/Widget/Subheader')
local LinksWidget = require('Module:Infobox/Widget/Links')
local ListWidget = require('Module:Infobox/Widget/List')
local LocationWidget = require('Module:Infobox/Widget/Location')
local RowWidget = require('Module:Infobox/Widget/Row')
VariablesLua = mw.ext.VariablesLua

local Infobox = {}

local function prizeToString(nr)
	if nr == nil then return 'TBD' end
	local prize = ''
    local reversed = string.reverse(tostring(nr))
    for k = 1, #reversed do
    	prize = reversed:sub(k, k) .. prize
    	if k % 3 == 0 and k < #reversed then prize =  ',' .. prize end
    	k = k + 1
    end
    return prize
end

function Infobox.main(frame)
	local args = getArgs(frame)

	local currentTitleSplit = mw.text.split(mw.title.getCurrentTitle().text, '/')
	
	local headerNode = Header.make(args.title or currentTitleSplit[2], args.logoLight, args.logoDark, args.logoAll)
	
	local container = mw.html.create('div')
		:addClass('ib')
		
	container:node(headerNode):node(Subheader.make('Tournament Information'))
	
	if args.series then
		container:node(RowWidget.make('Series', args.series))
	end
	
	if args.organizer then 
		container:node(RowWidget.make('Organizer', ListWidget.make(args.organizer)))
	end
	
	if args.sponsors then
		container:node(RowWidget.make('Sponsors', ListWidget.make(args.sponsors)))
	end
	
	if args.type then
		container:node(RowWidget.make('Type', args.type))
	end
	
	if args.female_only == 'Yes' then
		container:node(RowWidget.make('Female only', 'Yes'))
	end
	
	if args.educational then
		container:node(RowWidget.make('Educational', args.educational))
	end
	
	if args.country then
		container:node(RowWidget.make('Location', LocationWidget.make(args.country, args.city, currentTitleSplit[1] .. '/Tournaments')))
	end
	
	if args.venue then
		container:node(RowWidget.make('Venue', ListWidget.make(args.venue)))
	end
	
	if args.format then
		container:node(RowWidget.make('Format', ListWidget.make(args.format)))
	end
	
	if args.prize then
		local prize = prizeToString(tonumber(args.prize))
		if args.currency then prize = prizeToString(tonumber(args.localPrize)) .. ' ' .. args.currency else prize = '$' .. prize end
		container:node(RowWidget.make('Prize pool', prize))
	end
	
	if args.start then
		VariablesLua.vardefine( 'startDate', args.start )
		container:node(RowWidget.make('Start date', args.start))
	end
	
	if args['end'] then
		VariablesLua.vardefine( 'endDate', args['end'] )
		container:node(RowWidget.make('End date', args['end']))
	end
	
	if args.version or args.patch then
		container:node(RowWidget.make('Patch', args.version or args.patch, frame))
	end
	
	if args.participants then
		container:node(RowWidget.make('Participants', args.participants))
	end
	
	if args.points then
		container:node(RowWidget.make('Pro Circuit Points', args.points))
	end
	
	container:node(Subheader.make('Links'))
	
	-- Check if there is a "links" argument and then do magic to add them all to arguments
	if args.links then
		local splitLinks = mw.text.split(args.links, ',')
		for i = 1, #splitLinks do
			local split = mw.text.split(splitLinks[i], '=')
			args[split[1]] = split[2]
		end
	end
	
	local transformedLinks = Links.transform(args)
	local fullLinks = LinksWidget.make(transformedLinks, 'team')
	
	container:node(fullLinks)
	return container

end

return Infobox