Module:Participants list team: Difference between revisions

From TwogPedia
No edit summary
No edit summary
Line 144: Line 144:
container:node(participant)
container:node(participant)
 
local wrapper = mw.html.create('div')
if args.showtoggle then
local toggle = mw.html.create('button')
:attr('id', 'team-toggle')
:wikitext('Show Players')
wrapper:node(toggle):node(container)
else
wrapper:node(container)
end
end
end
return container
return wrapper
end
end


return Participants
return Participants

Revision as of 20:19, 11 September 2022

Documentation for this module may be created at Module:Participants list team/doc

local cargo = mw.ext.cargo

local getArgs = require('Module:Arguments').getArgs
local makeFlag = require('Module:Player/Flag').makeFlag
local Links = require('Module:Links')

local Participants = {}



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

	local currentTitleSplit = mw.text.split(mw.title.getCurrentTitle().text, '/')
	
	local container = mw.html.create('div')
		:addClass('p-team-container')
	
	local teamsize = args.teamsize

	local currentTitle = mw.title.getCurrentTitle().text
	local gameCategory = mw.text.split(currentTitle, '/')[1]
	
	for key, value in ipairs (args) do
		local pValues = mw.text.jsonDecode(value)

		local participant = mw.html.create('div')
		
		if pValues.team then
			local teamName = mw.html.create('div')
				:addClass('tc fw-600')
				:wikitext('[['.. gameCategory .. '/' .. pValues.team ..']]')
			if pValues.notes then
				local notesList = mw.text.split(pValues.notes, ',')
				for i, v in ipairs (notesList) do
					v = mw.text.trim(v)
					teamName:node(mw.html.create('sup'):attr('title', 'Note ' .. v):wikitext(v))
				end
			end
			participant:node(teamName)
		end
		
		-- Create list of players
		local playerList = mw.html.create('table')
			:addClass('table-bordered players')
		
		local players = {}
		for i = 1, teamsize, 1 do
			if pValues['p'.. i] then
				local playerId = pValues['p'.. i]
				if pValues['p'.. i .. 'link'] then
					playerId = pValues['p'.. i .. 'link'] .. '|' .. pValues['p'.. i]
				end
				
				local flag = makeFlag(pValues['p'.. i .. 'flag'], pValues['p'.. i .. 'link'] or pValues['p'.. i], gameCategory)

				players['p'.. i] = mw.html.create('tr')
					:node(mw.html.create('th'):wikitext(i))
				
				local td = mw.html.create('td')

				if flag then
					td:wikitext(flag)
				end
				
				td:wikitext('[['.. playerId ..']]')
				players['p'.. i]:node(td)
				playerList:node(players['p'.. i])
			end
		end
		
		if pValues.s then
			local playerId = pValues.s
			if pValues['slink'] then
				playerId = pValues['slink'] .. '|' .. pValues.s
			end
			local flag = makeFlag(pValues['sflag'], pValues['slink'] or pValues.s, gameCategory)
			
			local sub = mw.html.create('tr')
				:node(mw.html.create('th'):node(mw.html.create('abbr'):attr('title', 'Substitute'):wikitext('S')))
				:node(mw.html.create('td'):wikitext(flag):wikitext('[['.. playerId ..']]'))
			playerList:node(sub)
		end
		
		if pValues.c then
			local playerId = pValues.c
			if pValues['clink'] then
				playerId = pValues['clink'] .. '|' .. pValues.c
			end
			local flag = makeFlag(pValues['cflag'], pValues['clink'] or pValues.c, gameCategory)

			local coach = mw.html.create('tr')
				:node(mw.html.create('th'):node(mw.html.create('abbr'):attr('title', 'Coach'):wikitext('C')))
				:node(mw.html.create('td'):wikitext(flag):wikitext('[['.. playerId ..']]'))
			playerList:node(coach)
		end
		
		local relativeParent = mw.html.create('div')
			:addClass('team-list')
			
		
		-- Look up Cargo table for team images
		local tables = 'Teams'
		local fields = '_pageName, image, imagedark'
	
		local cargoArgs = {
			where = '_pageName = "' .. gameCategory .. '/' .. pValues.team.. '"'
		}
		local results = cargo.query(tables, fields, cargoArgs)
		local image = ''
		local imagedark = ''

		if #results > 0 then
			image = results[1].image
			imagedark = results[1].imagedark
		end

		imagedark = imagedark or pValues.imagedark or image or 'Team_placeholder_dark.png'
		image = image or pValues.image or 'Team_placeholder_light.png'
		local logoContainer = mw.html.create('div')
			:addClass('light h-100')
		local logoLight = mw.html.create('div')
			:addClass('team-list-logo')
			:node('[[File:' .. image .. '|190px]]')
		logoContainer:node(logoLight)
		
		local logoContainerDark = mw.html.create('div')
			:addClass('dark h-100')
		local logoDark = mw.html.create('div')
			:addClass('team-list-logo')
			:node('[[File:' .. imagedark .. '|190px]]')
		logoContainerDark:node(logoDark)
		

		relativeParent:node(playerList):node(logoContainer):node(logoContainerDark)
		participant:node(relativeParent)
		
		if pValues.qualifier then
			local qualifier = mw.html.create('div')
				:addClass('team-list-qualifier')
				:wikitext(pValues.qualifier)
			participant:node(qualifier)
		end
		
		container:node(participant)
		
		local wrapper = mw.html.create('div')
		if args.showtoggle then
			local toggle = mw.html.create('button')
				:attr('id', 'team-toggle')
				:wikitext('Show Players')
			wrapper:node(toggle):node(container)
		else
			wrapper:node(container)	
		end
	end
	
	return wrapper
end

return Participants