mNo edit summary |
mNo edit summary |
||
(4 intermediate revisions by the same user not shown) | |||
Line 2: | Line 2: | ||
local VariablesLua = mw.ext.VariablesLua | local VariablesLua = mw.ext.VariablesLua | ||
local stringifyDate = require('Module:Functions').stringifyDate | local stringifyDate = require('Module:Functions').stringifyDate | ||
local getTeamLogo = require('Module:Functions').getTeamLogo | |||
local getTeamDisplaytitle = require('Module:Functions').getTeamDisplaytitle | |||
local makeFlag = require('Module:Person/Flag').makeFlag | local makeFlag = require('Module:Person/Flag').makeFlag | ||
function MatchHTML.team(name, score, rev) | |||
local teamName = name and | function MatchHTML.team(name, score, date, rev) | ||
local teamName = name and getTeamDisplaytitle(name, date) or '' | |||
local team = mw.html.create('div'):addClass('team') | local team = mw.html.create('div'):addClass('team') | ||
local nameNode = mw.html.create('div'):wikitext( | local nameNode = mw.html.create('div'):addClass('teamName') | ||
if | |||
team:addClass('reverse') | if not name then return team:node(nameNode):node(mw.html.create('div'):wikitext(0):addClass('score')) end | ||
local style = 'display: flex; gap: 0.5rem; font-size: 0.9rem;' | |||
local game = mw.text.split(mw.title.getCurrentTitle().text, '/')[1] | |||
local size = '20x20px' | |||
if VariablesLua.var( 'matchList') == '1' then | |||
if rev then | |||
style = style .. 'padding-left: 4px;' | |||
nameNode:node(getTeamLogo(name, game, size):attr('style', 'width: 20px;')):node(mw.html.create('div'):wikitext(teamName)) | |||
team:addClass('reverse') | |||
else | |||
style = style .. 'justify-content: end; padding-right: 4px;' | |||
nameNode:node(mw.html.create('div'):wikitext(teamName)):node(getTeamLogo(name, game, size):attr('style', 'width: 20px;')) | |||
end | |||
else | |||
nameNode:node(getTeamLogo(name, game, size):attr('style', 'width: 20px;')):node(mw.html.create('div'):wikitext(teamName)) | |||
style = style .. 'padding-left: 4px;' | |||
end | end | ||
nameNode:attr('style', style) | |||
return team:node(nameNode):node(mw.html.create('div'):wikitext(score):addClass('score')) | return team:node(nameNode):node(mw.html.create('div'):wikitext(score):addClass('score')) | ||
end | end | ||
function MatchHTML.teamHover(p1, p2, p1score, p2score, date, twitch, youtube, casters, observers) | function MatchHTML.teamHover(p1, p2, p1score, p2score, date, twitch, youtube, casters, observers, winner) | ||
local p1Link = p1 and '[[' .. p1 .. ']]' or 'TBD' | local p1Link = p1 and '[[' .. p1 .. '|' .. getTeamDisplaytitle(p1, date) .. ']]' or 'TBD' | ||
local p2Link = p2 and '[[' .. p2 .. ']]' or 'TBD' | local p2Link = p2 and '[[' .. p2 .. '|' .. getTeamDisplaytitle(p2, date) .. ']]' or 'TBD' | ||
local hover = mw.html.create('div'):addClass('match-details') | local hover = mw.html.create('div'):addClass('match-details') | ||
local header = mw.html.create('div'):addClass('details-header') | local header = mw.html.create('div'):addClass('details-header') | ||
Line 30: | Line 49: | ||
header:node(hover1):node(hover2) | header:node(hover1):node(hover2) | ||
local date = mw.html.create('div'):addClass('tc convert--date'):wikitext(stringifyDate(date)) | local date = mw.html.create('div'):addClass('tc convert--date'):attr('style', 'font-size: 0.9rem;'):wikitext(stringifyDate(date)) | ||
hover:node(header):node(date) | |||
if #casters > 0 then | |||
local castersDiv = mw.html.create('div'):attr('style', 'display: flex; gap: 0.5rem; font-size: 0.8rem; justify-content: center;'):wikitext('Casters:') | |||
for i = 1, #casters do | for i = 1, #casters do | ||
local personDiv = mw.html.create('div') | |||
personDiv:wikitext(makeFlag(nil, casters[i])) | |||
personDiv:wikitext('[[' .. casters[i] .. ']]') | |||
castersDiv:node(personDiv) | |||
end | end | ||
hover:node(castersDiv) | |||
end | end | ||
if #observers> 0 then | |||
local observersDiv = mw.html.create('div'):attr('style', 'display: flex; gap: 0.5rem; font-size: 0.8rem; justify-content: center;'):wikitext('Observers:') | |||
for i = 1, #observers do | for i = 1, #observers do | ||
local personDiv = mw.html.create('div') | |||
personDiv:wikitext(makeFlag(nil, observers[i])) | |||
personDiv:wikitext('[[' .. observers[i] .. ']]') | |||
observersDiv:node(personDiv) | |||
end | end | ||
hover:node(observersDiv) | |||
end | end | ||
if winner == 0 then | |||
local streams = mw.html.create('div') | |||
if twitch then streams:wikitext('[[File:Twitch.png|25px|link=https://twitch.tv/' .. twitch .. ']]') end | |||
if youtube then streams:wikitext('[[File:Youtube.png|25px|link=https://youtube.com/' .. youtube .. '/live]]') end | |||
hover:node(streams) | |||
return hover | end | ||
return hover | |||
end | end | ||
return MatchHTML | return MatchHTML |
Latest revision as of 20:13, 12 November 2023
Documentation for this module may be created at Module:MatchHTML/doc
local MatchHTML = {}
local VariablesLua = mw.ext.VariablesLua
local stringifyDate = require('Module:Functions').stringifyDate
local getTeamLogo = require('Module:Functions').getTeamLogo
local getTeamDisplaytitle = require('Module:Functions').getTeamDisplaytitle
local makeFlag = require('Module:Person/Flag').makeFlag
function MatchHTML.team(name, score, date, rev)
local teamName = name and getTeamDisplaytitle(name, date) or ''
local team = mw.html.create('div'):addClass('team')
local nameNode = mw.html.create('div'):addClass('teamName')
if not name then return team:node(nameNode):node(mw.html.create('div'):wikitext(0):addClass('score')) end
local style = 'display: flex; gap: 0.5rem; font-size: 0.9rem;'
local game = mw.text.split(mw.title.getCurrentTitle().text, '/')[1]
local size = '20x20px'
if VariablesLua.var( 'matchList') == '1' then
if rev then
style = style .. 'padding-left: 4px;'
nameNode:node(getTeamLogo(name, game, size):attr('style', 'width: 20px;')):node(mw.html.create('div'):wikitext(teamName))
team:addClass('reverse')
else
style = style .. 'justify-content: end; padding-right: 4px;'
nameNode:node(mw.html.create('div'):wikitext(teamName)):node(getTeamLogo(name, game, size):attr('style', 'width: 20px;'))
end
else
nameNode:node(getTeamLogo(name, game, size):attr('style', 'width: 20px;')):node(mw.html.create('div'):wikitext(teamName))
style = style .. 'padding-left: 4px;'
end
nameNode:attr('style', style)
return team:node(nameNode):node(mw.html.create('div'):wikitext(score):addClass('score'))
end
function MatchHTML.teamHover(p1, p2, p1score, p2score, date, twitch, youtube, casters, observers, winner)
local p1Link = p1 and '[[' .. p1 .. '|' .. getTeamDisplaytitle(p1, date) .. ']]' or 'TBD'
local p2Link = p2 and '[[' .. p2 .. '|' .. getTeamDisplaytitle(p2, date) .. ']]' or 'TBD'
local hover = mw.html.create('div'):addClass('match-details')
local header = mw.html.create('div'):addClass('details-header')
local hover1 = mw.html.create('div'):addClass('team')
:node(mw.html.create('div'):wikitext(p1Link):addClass('teamName'))
:node(mw.html.create('div'):wikitext(p1score):addClass('score'))
local hover2 = mw.html.create('div'):addClass('team reverse')
:node(mw.html.create('div'):wikitext(p2Link):addClass('teamName'))
:node(mw.html.create('div'):wikitext(p2score):addClass('score'))
header:node(hover1):node(hover2)
local date = mw.html.create('div'):addClass('tc convert--date'):attr('style', 'font-size: 0.9rem;'):wikitext(stringifyDate(date))
hover:node(header):node(date)
if #casters > 0 then
local castersDiv = mw.html.create('div'):attr('style', 'display: flex; gap: 0.5rem; font-size: 0.8rem; justify-content: center;'):wikitext('Casters:')
for i = 1, #casters do
local personDiv = mw.html.create('div')
personDiv:wikitext(makeFlag(nil, casters[i]))
personDiv:wikitext('[[' .. casters[i] .. ']]')
castersDiv:node(personDiv)
end
hover:node(castersDiv)
end
if #observers> 0 then
local observersDiv = mw.html.create('div'):attr('style', 'display: flex; gap: 0.5rem; font-size: 0.8rem; justify-content: center;'):wikitext('Observers:')
for i = 1, #observers do
local personDiv = mw.html.create('div')
personDiv:wikitext(makeFlag(nil, observers[i]))
personDiv:wikitext('[[' .. observers[i] .. ']]')
observersDiv:node(personDiv)
end
hover:node(observersDiv)
end
if winner == 0 then
local streams = mw.html.create('div')
if twitch then streams:wikitext('[[File:Twitch.png|25px|link=https://twitch.tv/' .. twitch .. ']]') end
if youtube then streams:wikitext('[[File:Youtube.png|25px|link=https://youtube.com/' .. youtube .. '/live]]') end
hover:node(streams)
end
return hover
end
return MatchHTML