Module:Game/Teams: Difference between revisions

From TwogPedia
(Created page with "local Flags = require('Module:Flags') local p = {} local VariablesLua = mw.ext.VariablesLua local cargo = mw.ext.cargo local limit = 25 function p.main(frame) local game = mw.text.split(mw.title.getCurrentTitle().text, '/')[1] local tables = 'Teams' local fields = '_pageName, region' local cargoArgs = { where = '_pageName LIKE"' .. game .. '/%" AND inactive IS NULL', orderBy = 'region' } local results = cargo.query(tables, fields, cargoArgs) local contain...")
 
mNo edit summary
 
Line 8: Line 8:
local game = mw.text.split(mw.title.getCurrentTitle().text, '/')[1]
local game = mw.text.split(mw.title.getCurrentTitle().text, '/')[1]
local tables = 'Teams'
local tables = 'Teams'
local fields = '_pageName, region'
local fields = '_pageName, region, org'
local cargoArgs = {
local cargoArgs = {
where = '_pageName LIKE"' .. game .. '/%" AND inactive IS NULL',
where = '_pageName LIKE"' .. game .. '/%" AND inactive IS NULL',
Line 39: Line 39:
    tables = "Logos"
    tables = "Logos"
    fields = "logoAll, logoLight, logoDark, iconAll, iconLight, iconDark"
    fields = "logoAll, logoLight, logoDark, iconAll, iconLight, iconDark"
            local org = result.org or ''
    cargoArgs = {
    cargoArgs = {
    where = "_pageName='" .. result._pageName .. "' AND (start IS NULL OR Logos.start < '" .. currentDate .. "') AND (end IS NULL OR end > '" .. currentDate .. "')"
    where = '(_pageName="' .. result._pageName .. '" OR _pageName="' .. org .. '") AND (start IS NULL OR start < "' .. currentDate .. '") AND (end IS NULL OR end > "' .. currentDate .. '")'
    }
    }

Latest revision as of 22:21, 4 October 2023

Documentation for this module may be created at Module:Game/Teams/doc

local Flags = require('Module:Flags')
local p = {}
local VariablesLua = mw.ext.VariablesLua
local cargo = mw.ext.cargo

local limit = 25
function p.main(frame)
	local game = mw.text.split(mw.title.getCurrentTitle().text, '/')[1]
	local tables = 'Teams'
	local fields = '_pageName, region, org'
	local cargoArgs = {
		where = '_pageName LIKE"' .. game .. '/%" AND inactive IS NULL',
		orderBy = 'region'
	}
	
	local results = cargo.query(tables, fields, cargoArgs)
	
	local container = mw.html.create('div')
	if #results > 0 then
		local region = results[1].region
		local tableContainer = mw.html.create('table'):addClass('teams__table')
		local headerRow = mw.html.create('tr'):node(mw.html.create('th'):attr('colspan', 2):node(mw.html.create('div'):addClass('teams__region'):node(Flags.icon(region)):node(mw.html.create('div'):wikitext(Flags.CountryName(region)))))
		tableContainer:node(headerRow)
		
		for i = 1, #results do
			local result = results[i]
			local currentDate = os.date('%Y-%m-%d')
			local newRegion = results[i].region
			
			if region ~= newRegion then
				local clone = mw.clone(tableContainer)
				container:node(clone)
				region = newRegion
				tableContainer = mw.html.create('table'):addClass('teams__table')
				headerRow = mw.html.create('tr'):node(mw.html.create('th'):attr('colspan', 2):node(mw.html.create('div'):addClass('teams__region'):node(Flags.icon(region)):node(mw.html.create('div'):wikitext(Flags.CountryName(region)))))
				tableContainer:node(headerRow)
			end
			
		    tables = "Logos"
		    fields = "logoAll, logoLight, logoDark, iconAll, iconLight, iconDark"
            local org = result.org or ''
		    cargoArgs = {
		    	where = '(_pageName="' .. result._pageName .. '" OR _pageName="' .. org .. '") AND (start IS NULL OR start < "' .. currentDate .. '") AND (end IS NULL OR end > "' .. currentDate .. '")'
		    }
			
			-- Perform the join query
			local teamResults = cargo.query(tables, fields, cargoArgs)
			local team = mw.html.create('td')
			local teamName = result._pageName
			if #teamResults > 0 then
				local logoAll = teamResults[1].logoAll
				local logoLight = teamResults[1].logoLight
				local logoDark = teamResults[1].logoDark
				local iconAll = teamResults[1].iconAll
				local iconLight = teamResults[1].iconLight
				local iconDark = teamResults[1].iconDark
				
				if iconAll then
					team:node(p.createLogo(iconAll, teamName, nil, game, size))
				elseif iconLight and iconDark then
					team:node(mw.html.create('div'):node(p.createLogo(iconLight, teamName, 'light', game, size)):node(p.createLogo(iconDark, teamName, 'dark', game, size)))
				elseif logoAll then
					team:node(p.createLogo(logoAll, teamName, nil, game, size))
				elseif logoLight and logoDark then
					team:node(mw.html.create('div'):node(p.createLogo(logoLight, teamName, 'light', game, size)):node(p.createLogo(logoDark, teamName, 'dark', game, size)))
				else 
					local logo = iconLight or iconDark or logoLight or logoDark
					team:node(p.createLogo(logo, teamName, nil, game, size))
				end
			else
				team:node(mw.html.create('div'):node(p.createLogo(nil, teamName, 'light', game, size)):node(p.createLogo(nil, teamName, 'dark', game, size)))
			end
			
			local playerRow = mw.html.create('tr'):node(team):node(mw.html.create('td'):wikitext('[[' .. result._pageName .. ']]'))
			tableContainer:node(playerRow)
		end
		container:node(tableContainer)
	end
	
	return container
end

function p.createLogo(url, teamPage, class, game, size)
	size = size or '20px'
	local className = class and class .. ' h-100' or 'h-100'
	local logoURL = url and url or 'Team_placeholder_' .. class .. '.png'
	local logoContainer = mw.html.create('div'):addClass(className)
	local logo = mw.html.create('div')
		:addClass('team-list-logo')
		:node('[[File:' .. logoURL .. '|' .. size .. '|link=' .. teamPage .. '|' .. string.gsub(teamPage, game .. '/', '') .. ']]')

	logoContainer:node(logo)
	return logoContainer
end

return p