Module:Infobox tournament: Difference between revisions

From TwogPedia
mNo edit summary
No edit summary
 
(2 intermediate revisions by one other user not shown)
Line 12: Line 12:


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


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