Module:Infobox tournament: Difference between revisions

From TwogPedia
(Created page with "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 SponsorsWidget = require('Module:Infobox/Widget/Sponsors') local Flags = require('Module:Flags') local Infobox = {} function Infobox.main(frame) local args = getArgs(frame) local currentTitleSplit =...")
 
No edit summary
 
(6 intermediate revisions by one other user not shown)
Line 4: Line 4:
local Subheader = require('Module:Infobox/Widget/Subheader')
local Subheader = require('Module:Infobox/Widget/Subheader')
local LinksWidget = require('Module:Infobox/Widget/Links')
local LinksWidget = require('Module:Infobox/Widget/Links')
local SponsorsWidget = require('Module:Infobox/Widget/Sponsors')
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 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)
local args = getArgs(frame)
    local args = getArgs(frame)
 
    local currentTitleSplit = mw.text.split(mw.title.getCurrentTitle().text, '/')
local currentTitleSplit = mw.text.split(mw.title.getCurrentTitle().text, '/')
    local headerNode = Header.make(
        args.title or currentTitleSplit[2],
local headerNode = Header.make(args.title or currentTitleSplit[2], args.image or '')
    args.logoLight,
    args.logoDark,
local container = mw.html.create('div')
    args.logoAll,
:addClass('ib')
    nil,
    nil,
container:node(headerNode):node(Subheader.make(args.variant .. ' Information'))
    nil,
    args.country,
if args.location then
    args.city,
local countryName = Flags.CountryName(args.location)
    args.start,  -- start date
local flag = Flags.icon(args.location, currentTitleSplit[1])
    args["end"]   -- end date
local location = mw.html.create('div')
    )
:addClass('ib-row')
    local container = mw.html.create('div'):addClass('ib grid-infobox'):attr('id', 'grid-infobox-tournaments')
local link = ':Category:' .. currentTitleSplit[1]  .. '/' .. countryName
    local titleContainer = mw.html.create('div')
local locationName = mw.html.create('span')
        :addClass('carousel-image-container')
:wikitext('[[' .. link .. '|' .. countryName .. ']]')
        :attr('id', 'image-container-small')
local name = mw.html.create('div')
        :node(headerNode)
:addClass('ib-rowName')
    container:node(titleContainer)
:wikitext('Location: ')
    local infoContainer = mw.html.create('div'):addClass('info-container grid')
local value = mw.html.create('div')
    if args.series then
:wikitext(flag)
        infoContainer:node(RowWidget.make('Series', args.series))
:node(locationName)
    end
    if args.organizer then  
if args.location2 then
        infoContainer:node(RowWidget.make('Organizer', ListWidget.make(args.organizer)))
countryName = Flags.CountryName(args.location2)
    end
flag = Flags.icon(args.location2, currentTitleSplit[1])
    if args.sponsors then
link = ':Category:' .. currentTitleSplit[1]  .. '/' .. countryName
        infoContainer:node(RowWidget.make('Sponsors', ListWidget.make(args.sponsors)))
local location2Name = mw.html.create('span')
    end
:wikitext('[[' .. link .. '|' .. countryName .. ']]')
    if args.type then
local location2 = mw.html.create('div')
        infoContainer:node(RowWidget.make('Type', args.type))
:wikitext(flag)
    end
:node(location2Name)
    if args.female_only == 'Yes' then
value:wikitext('<br>'):node(location2)
        infoContainer:node(RowWidget.make('Female only', 'Yes'))
end
    end
container:node(location:node(name):node(value))
    if args.educational then
end
        infoContainer:node(RowWidget.make('Educational', args.educational))
    end
if args.region then
    if args.venue then
local countryName = Flags.CountryName(args.region)
        infoContainer:node(RowWidget.make('Venue', ListWidget.make(args.venue)))
local flag = Flags.icon(args.region, currentTitleSplit[1])
    end
local region = mw.html.create('div')
    if args.format then
:addClass('ib-row')
        infoContainer:node(RowWidget.make('Format', ListWidget.make(args.format)))
local link = ':Category:' .. currentTitleSplit[1]  .. '/' .. countryName
    end
local regionName = mw.html.create('span')
    if args.prize then
:wikitext('[[' .. link .. '|' .. countryName .. ']]')
        local prize = prizeToString(tonumber(args.prize))
local name = mw.html.create('div')
        if args.currency then
:addClass('ib-rowName')
            prize = prizeToString(tonumber(args.localPrize)) .. ' ' .. args.currency
:wikitext('Region: ')
        else  
local value = mw.html.create('div')
            prize = '$' .. prize
:wikitext(flag)
        end
:node(regionName)
        infoContainer:node(RowWidget.make('Prize pool', prize))
container:node(region:node(name):node(value))
    end
end
    -- if args.start then
    --    VariablesLua.vardefine('startDate', args.start)
    --    infoContainer:node(RowWidget.make('Start date', args.start))
    -- end
if args.founded then
    -- if args['end'] then
local founded = mw.html.create('div')
    --    VariablesLua.vardefine('endDate', args['end'])
:addClass('ib-row')
    --    infoContainer:node(RowWidget.make('End date', args['end']))
local name = mw.html.create('div')
    -- end
:addClass('ib-rowName')
    if args.version or args.patch then
:wikitext('Founded: ')
        infoContainer:node(RowWidget.make('Patch', args.version or args.patch, frame))
local value = mw.html.create('div')
    end
:wikitext(args.founded)
    if args.participants then
container:node(founded:node(name):node(value))
        infoContainer:node(RowWidget.make('Participants', args.participants))
end
    end
    if args.points then
if args.org then
        infoContainer:node(RowWidget.make('Pro Circuit Points', args.points))
local org = mw.html.create('div')
    end
:addClass('ib-row')
    if args.links then
local name = mw.html.create('div')
        local splitLinks = mw.text.split(args.links, ',')
:addClass('ib-rowName')
        for i = 1, #splitLinks do
:wikitext('Organization: ')
            local split = mw.text.split(splitLinks[i], '=')
            args[split[1]] = split[2]
local value = mw.html.create('div')
        end
local pageExists = frame:callParserFunction('#ifexist', args.org, 'yes', 'no' )
    end
if ( pageExists == 'yes' ) then  
    local linksContainer = mw.html.create('div'):addClass('ib-links-container')
value:wikitext('<span>[[' .. args.org .. '|' .. args.org .. ']]</span>')
    local transformedLinks = Links.transform(args)
else
    local fullLinks = LinksWidget.make(transformedLinks, 'team')
value:wikitext(args.org)
    linksContainer:node(fullLinks)
end
    container:node(infoContainer)
container:node(org:node(name):node(value))
    container:node(linksContainer)
end
    return container
if args.sponsors then
local sponsors = mw.html.create('div')
:addClass('ib-row')
local name = mw.html.create('div')
:addClass('ib-rowName')
:wikitext('Sponsors: ')
local value = SponsorsWidget.make(args.sponsors)
container:node(sponsors:node(name):node(value))
end
if args.coach then
local coach = mw.html.create('div')
:addClass('ib-row')
local name = mw.html.create('div')
:addClass('ib-rowName')
:wikitext('Coach: ')
local value = mw.html.create('div')
local pageExists = frame:callParserFunction('#ifexist', args.coach, 'yes', 'no' )
if ( pageExists == 'yes' ) then
value:wikitext('<span>[[' .. args.coach .. '|' .. args.coach .. ']]</span>')
else  
value:wikitext(args.coach)
end
container:node(coach:node(name):node(value))
end
if args.manager then
local manager = mw.html.create('div')
:addClass('ib-row')
local name = mw.html.create('div')
:addClass('ib-rowName')
:wikitext('Manager: ')
local value = mw.html.create('div')
local pageExists = frame:callParserFunction('#ifexist', args.manager, 'yes', 'no' )
if ( pageExists == 'yes' ) then  
value:wikitext('<span>[[' .. args.manager .. '|' .. args.manager .. ']]</span>')
else
value:wikitext(args.manager)
end
container:node(manager:node(name):node(value))
end
if args.captain then
local captain = mw.html.create('div')
:addClass('ib-row')
local name = mw.html.create('div')
:addClass('ib-rowName')
:wikitext('Manager: ')
local value = mw.html.create('div')
local pageExists = frame:callParserFunction('#ifexist', args.captain, 'yes', 'no' )
if ( pageExists == 'yes' ) then
value:wikitext('<span>[[' .. args.captain .. '|' .. args.captain .. ']]</span>')
else
value:wikitext(args.captain)
end
container:node(captain:node(name):node(value))
end
container:node(Subheader.make('Links'))
local transformedLinks = Links.transform(args)
local fullLinks = LinksWidget.make(transformedLinks, 'team')
container:node(fullLinks)
return container
 
end
end


return Infobox
return Infobox

Latest revision as of 00:35, 26 April 2025

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,
	    nil,
	    nil,
	    nil,
	    args.country,
	    args.city,
	    args.start,   -- start date
	    args["end"]   -- end date
    )
    local container = mw.html.create('div'):addClass('ib grid-infobox'):attr('id', 'grid-infobox-tournaments')
    local titleContainer = mw.html.create('div')
        :addClass('carousel-image-container')
        :attr('id', 'image-container-small')
        :node(headerNode)
    container:node(titleContainer)
    local infoContainer = mw.html.create('div'):addClass('info-container grid')
    if args.series then
        infoContainer:node(RowWidget.make('Series', args.series))
    end
    if args.organizer then 
        infoContainer:node(RowWidget.make('Organizer', ListWidget.make(args.organizer)))
    end
    if args.sponsors then
        infoContainer:node(RowWidget.make('Sponsors', ListWidget.make(args.sponsors)))
    end
    if args.type then
        infoContainer:node(RowWidget.make('Type', args.type))
    end
    if args.female_only == 'Yes' then
        infoContainer:node(RowWidget.make('Female only', 'Yes'))
    end
    if args.educational then
        infoContainer:node(RowWidget.make('Educational', args.educational))
    end
    if args.venue then
        infoContainer:node(RowWidget.make('Venue', ListWidget.make(args.venue)))
    end
    if args.format then
        infoContainer: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
        infoContainer:node(RowWidget.make('Prize pool', prize))
    end
    -- if args.start then
    --     VariablesLua.vardefine('startDate', args.start)
    --     infoContainer:node(RowWidget.make('Start date', args.start))
    -- end
    -- if args['end'] then
    --     VariablesLua.vardefine('endDate', args['end'])
    --     infoContainer:node(RowWidget.make('End date', args['end']))
    -- end
    if args.version or args.patch then
        infoContainer:node(RowWidget.make('Patch', args.version or args.patch, frame))
    end
    if args.participants then
        infoContainer:node(RowWidget.make('Participants', args.participants))
    end
    if args.points then
        infoContainer:node(RowWidget.make('Pro Circuit Points', args.points))
    end
    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 linksContainer = mw.html.create('div'):addClass('ib-links-container')
    local transformedLinks = Links.transform(args)
    local fullLinks = LinksWidget.make(transformedLinks, 'team')
    linksContainer:node(fullLinks)
    container:node(infoContainer)
    container:node(linksContainer)
    return container
end

return Infobox