From c3b6751459ef61c127a52c71ed9f9d133f65acea Mon Sep 17 00:00:00 2001 From: hjpalpha Date: Thu, 28 Sep 2023 14:19:41 +0200 Subject: [PATCH 1/9] sideswipe --- .../match2/wikis/sideswipe/match_summary.lua | 155 +++++++----------- 1 file changed, 57 insertions(+), 98 deletions(-) diff --git a/components/match2/wikis/sideswipe/match_summary.lua b/components/match2/wikis/sideswipe/match_summary.lua index 409fc58c796..73ed44f19ce 100644 --- a/components/match2/wikis/sideswipe/match_summary.lua +++ b/components/match2/wikis/sideswipe/match_summary.lua @@ -13,84 +13,64 @@ local Logic = require('Module:Logic') local Lua = require('Module:Lua') local String = require('Module:StringUtils') local Table = require('Module:Table') -local VodLink = require('Module:VodLink') local DisplayHelper = Lua.import('Module:MatchGroup/Display/Helper', {requireDevIfEnabled = true}) -local MatchGroupUtil = Lua.import('Module:MatchGroup/Util', {requireDevIfEnabled = true}) -local MatchSummary = Lua.import('Module:MatchSummary/Base', {requireDevIfEnabled = true}) +local MatchSummary = Lua.import('Module:MatchSummary/Base/temp', {requireDevIfEnabled = true}) local OpponentDisplay = Lua.import('Module:OpponentDisplay', {requireDevIfEnabled = true}) -local _GREEN_CHECK = '[[File:GreenCheck.png|14x14px|link=]]' -local _NO_CHECK = '[[File:NoCheck.png|link=]]' -local _TIMEOUT = '[[File:Cooldown_Clock.png|14x14px|link=]]' +local GREEN_CHECK = '[[File:GreenCheck.png|14x14px|link=]]' +local NO_CHECK = '[[File:NoCheck.png|link=]]' +local TIMEOUT = '[[File:Cooldown_Clock.png|14x14px|link=]]' -local _TBD_ICON = mw.ext.TeamTemplate.teamicon('tbd') +local TBD_ICON = mw.ext.TeamTemplate.teamicon('tbd') -- Custom Header Class -local Header = Class.new( +---@class SideswipeMatchSummaryHeader: MatchSummaryHeader +local Header = Class.new(MatchSummary.Header, function(self) - self.root = mw.html.create('div') self.root:addClass('brkts-popup-header-dev') end ) +---@param content Html +---@return SideswipeMatchSummaryHeader function Header:leftOpponentTeam(content) self.leftElementAdditional = content return self end +---@param content Html +---@return SideswipeMatchSummaryHeader function Header:rightOpponentTeam(content) self.rightElementAdditional = content return self end +---@param content Html +---@return SideswipeMatchSummaryHeader function Header:scoreBoard(content) - self.scoreBoard = content - return self -end - -function Header:leftOpponent(content) - self.leftElement = content - return self -end - -function Header:rightOpponent(content) - self.rightElement = content + self.scoreBoardElement = content return self end +---@param opponent1 standardOpponent +---@param opponent2 standardOpponent +---@return Html function Header:createScoreDisplay(opponent1, opponent2) - local function getScore(opponent) - local scoreText - local isWinner = opponent.placement == 1 or opponent.advances - if opponent.placement2 then - -- Bracket Reset, show W/L - if opponent.placement2 == 1 then - isWinner = true - scoreText = 'W' - else - isWinner = false - scoreText = 'L' - end - else - scoreText = OpponentDisplay.InlineScore(opponent) - end - return OpponentDisplay.BlockScore{ - isWinner = isWinner, - scoreText = scoreText, - } - end - return mw.html.create('div') :addClass('brkts-popup-spaced') :node( - getScore(opponent1) + self:createScore(opponent1) :css('margin-right', 0) ) :node(' : ') - :node(getScore(opponent2)) + :node(self:createScore(opponent2)) end +---@param score number? +---@param bestof number? +---@param isNotFinished boolean? +---@return Html function Header:createScoreBoard(score, bestof, isNotFinished) local scoreBoardNode = mw.html.create('div') :addClass('brkts-popup-spaced') @@ -117,17 +97,23 @@ function Header:createScoreBoard(score, bestof, isNotFinished) return scoreBoardNode:node(score) end +---@param opponent standardOpponent +---@param date string +---@return Html? function Header:soloOpponentTeam(opponent, date) if opponent.type == 'solo' then local teamExists = mw.ext.TeamTemplate.teamexists(opponent.template or '') local display = teamExists and mw.ext.TeamTemplate.teamicon(opponent.template, date) - or _TBD_ICON + or TBD_ICON return mw.html.create('div'):wikitext(display) :addClass('brkts-popup-header-opponent-solo-team') end end +---@param opponent standardOpponent +---@param opponentIndex integer +---@return Html function Header:createOpponent(opponent, opponentIndex) return OpponentDisplay.BlockOpponent({ flip = opponentIndex == 1, @@ -140,69 +126,32 @@ function Header:createOpponent(opponent, opponentIndex) or 'brkts-popup-header-opponent-solo-with-team') end +---@return Html function Header:create() self.root:tag('div'):addClass('brkts-popup-header-opponent'):addClass('brkts-popup-header-opponent-left') :node(self.leftElementAdditional) :node(self.leftElement) - self.root:node(self.scoreBoard) + self.root:node(self.scoreBoardElement) self.root:tag('div'):addClass('brkts-popup-header-opponent'):addClass('brkts-popup-header-opponent-right') :node(self.rightElement) :node(self.rightElementAdditional) return self.root end - local CustomMatchSummary = {} +---@param args table +---@return Html function CustomMatchSummary.getByMatchId(args) - local match = MatchGroupUtil.fetchMatchForBracketDisplay(args.bracketId, args.matchId) - - local matchSummary = MatchSummary():init() - - matchSummary:header(CustomMatchSummary._createHeader(match)) - :body(CustomMatchSummary._createBody(match)) - - if match.comment then - local comment = MatchSummary.Comment():content(match.comment) - matchSummary:comment(comment) - end - - -- footer - local vods = {} - for index, game in ipairs(match.games) do - if game.vod then - vods[index] = game.vod - end - end - - if Table.isNotEmpty(vods) or String.isNotEmpty(match.vod) then - local footer = MatchSummary.Footer() - - -- Match Vod - if String.isNotEmpty(match.vod) then - footer:addElement(VodLink.display{ - vod = match.vod, - }) - end - - -- Game Vods - for index, vod in pairs(vods) do - footer:addElement(VodLink.display{ - gamenum = index, - vod = vod, - }) - end - - matchSummary:footer(footer) - end - - return matchSummary:create() + return MatchSummary.defaultGetByMatchId(CustomMatchSummary, args) end -function CustomMatchSummary._createHeader(match) +---@param match MatchGroupUtilMatch +---@return SideswipeMatchSummaryHeader +function CustomMatchSummary.createHeader(match) local header = Header() - header + return header :leftOpponentTeam(header:soloOpponentTeam(match.opponents[1], match.date)) :leftOpponent(header:createOpponent(match.opponents[1], 1)) :scoreBoard(header:createScoreBoard( @@ -215,11 +164,11 @@ function CustomMatchSummary._createHeader(match) )) :rightOpponent(header:createOpponent(match.opponents[2], 2)) :rightOpponentTeam(header:soloOpponentTeam(match.opponents[2], match.date)) - - return header end -function CustomMatchSummary._createBody(match) +---@param match MatchGroupUtilMatch +---@return MatchSummaryBody +function CustomMatchSummary.createBody(match) local body = MatchSummary.Body() body:addRow(MatchSummary.Row():addElement(DisplayHelper.MatchCountdownBlock(match))) @@ -235,6 +184,8 @@ function CustomMatchSummary._createBody(match) return body end +---@param game MatchGroupUtilGame +---@return MatchSummaryRow function CustomMatchSummary._createGame(game) local row = MatchSummary.Row() :addClass('brkts-popup-body-game') @@ -262,14 +213,14 @@ function CustomMatchSummary._createGame(game) end row:addElement(CustomMatchSummary._iconDisplay( - _GREEN_CHECK, + GREEN_CHECK, game.winner == 1, game.scores[1], 1 )) row:addElement(centerNode) row:addElement(CustomMatchSummary._iconDisplay( - _GREEN_CHECK, + GREEN_CHECK, game.winner == 2, game.scores[2], 2 @@ -279,7 +230,7 @@ function CustomMatchSummary._createGame(game) local timeouts = Json.parseIfString(extradata.timeout) row:addElement(MatchSummary.Break():create()) row:addElement(CustomMatchSummary._iconDisplay( - _TIMEOUT, + TIMEOUT, Table.includes(timeouts, 1) )) row:addElement(mw.html.create('div') @@ -287,7 +238,7 @@ function CustomMatchSummary._createGame(game) :node(mw.html.create('div'):node('Timeout')) ) row:addElement(CustomMatchSummary._iconDisplay( - _TIMEOUT, + TIMEOUT, Table.includes(timeouts, 2) )) end @@ -316,6 +267,9 @@ function CustomMatchSummary._createGame(game) return row end +---@param goalesValue string|number +---@param side 1|2 +---@return Html function CustomMatchSummary._goalDisaplay(goalesValue, side) local goalsDisplay = mw.html.create('div') :cssText(side == 2 and 'float:right; margin-right:10px;' or nil) @@ -330,12 +284,17 @@ function CustomMatchSummary._goalDisaplay(goalesValue, side) :node(goalsDisplay) end +---@param icon string +---@param shouldDisplay boolean? +---@param additionalElement number|string|Html|nil +---@param side integer? +---@return Html function CustomMatchSummary._iconDisplay(icon, shouldDisplay, additionalElement, side) local flip = side == 2 return mw.html.create('div') :addClass('brkts-popup-spaced') :node(additionalElement and flip and mw.html.create('div'):node(additionalElement) or nil) - :node(shouldDisplay and icon or _NO_CHECK) + :node(shouldDisplay and icon or NO_CHECK) :node(additionalElement and (not flip) and mw.html.create('div'):node(additionalElement) or nil) end From 74ebc0df3817598691d37130525eef7ecca62c2c Mon Sep 17 00:00:00 2001 From: hjpalpha Date: Thu, 28 Sep 2023 14:49:10 +0200 Subject: [PATCH 2/9] refine annos --- components/match2/wikis/sideswipe/match_summary.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/components/match2/wikis/sideswipe/match_summary.lua b/components/match2/wikis/sideswipe/match_summary.lua index 73ed44f19ce..1f8c19ed658 100644 --- a/components/match2/wikis/sideswipe/match_summary.lua +++ b/components/match2/wikis/sideswipe/match_summary.lua @@ -26,6 +26,9 @@ local TBD_ICON = mw.ext.TeamTemplate.teamicon('tbd') -- Custom Header Class ---@class SideswipeMatchSummaryHeader: MatchSummaryHeader +---@field leftElementAdditional Html +---@field rightElementAdditional Html +---@field scoreBoardElement Html local Header = Class.new(MatchSummary.Header, function(self) self.root:addClass('brkts-popup-header-dev') From 67e4dffc4501b16558d480d1f1515b622ebe9c9e Mon Sep 17 00:00:00 2001 From: hjpalpha Date: Thu, 28 Sep 2023 14:57:47 +0200 Subject: [PATCH 3/9] trackmania --- .../match2/wikis/sideswipe/match_summary.lua | 6 +- .../match2/wikis/trackmania/match_summary.lua | 142 ++++++++---------- 2 files changed, 63 insertions(+), 85 deletions(-) diff --git a/components/match2/wikis/sideswipe/match_summary.lua b/components/match2/wikis/sideswipe/match_summary.lua index 1f8c19ed658..63e12720009 100644 --- a/components/match2/wikis/sideswipe/match_summary.lua +++ b/components/match2/wikis/sideswipe/match_summary.lua @@ -29,11 +29,7 @@ local TBD_ICON = mw.ext.TeamTemplate.teamicon('tbd') ---@field leftElementAdditional Html ---@field rightElementAdditional Html ---@field scoreBoardElement Html -local Header = Class.new(MatchSummary.Header, - function(self) - self.root:addClass('brkts-popup-header-dev') - end -) +local Header = Class.new(MatchSummary.Header) ---@param content Html ---@return SideswipeMatchSummaryHeader diff --git a/components/match2/wikis/trackmania/match_summary.lua b/components/match2/wikis/trackmania/match_summary.lua index 661d67551eb..4fa0f83d048 100644 --- a/components/match2/wikis/trackmania/match_summary.lua +++ b/components/match2/wikis/trackmania/match_summary.lua @@ -26,12 +26,22 @@ local OVERTIME = '[[File:Cooldown_Clock.png|14x14px|link=]]' local HEADTOHEAD = '[[File:Match Info Stats.png|14x14px|link=%s|Head to Head history]]' -- Custom Header Class +---@class TrackmaniaMatchSummaryHeader: MatchSummaryHeader +---@field leftElementAdditional Html +---@field rightElementAdditional Html +---@field scoreBoardElement Html local Header = Class.new(MatchSummary.Header) +---@param content Html +---@return TrackmaniaMatchSummaryHeader function Header:scoreBoard(content) - self.scoreBoard = content + self.scoreBoardElement = content return self end + +---@param opponent1 standardOpponent +---@param opponent2 standardOpponent +---@return Html function Header:createScoreDisplay(opponent1, opponent2) local function getScore(opponent) local scoreText @@ -69,6 +79,10 @@ function Header:createScoreDisplay(opponent1, opponent2) :node(getScore(opponent2)) end +---@param score number? +---@param bestof number? +---@param isNotFinished boolean? +---@return Html function Header:createScoreBoard(score, bestof, isNotFinished) local scoreBoardNode = mw.html.create('div') :addClass('brkts-popup-spaced') @@ -94,20 +108,54 @@ function Header:createScoreBoard(score, bestof, isNotFinished) return scoreBoardNode:node(score) end + +---@return Html function Header:create() self.root:tag('div'):addClass('brkts-popup-header-opponent'):addClass('brkts-popup-header-opponent-left') :node(self.leftElementAdditional) :node(self.leftElement) - self.root:node(self.scoreBoard) + self.root:node(self.scoreBoardElement) self.root:tag('div'):addClass('brkts-popup-header-opponent'):addClass('brkts-popup-header-opponent-right') :node(self.rightElement) :node(self.rightElementAdditional) return self.root end - local CustomMatchSummary = {} +---@param args table +---@return Html +function CustomMatchSummary.getByMatchId(args) + return MatchSummary.defaultGetByMatchId(CustomMatchSummary, args) +end + +function CustomMatchSummary.createHeader(match) + local header = Header() + + return header + :leftOpponent(header:createOpponent(match.opponents[1], 'left')) + :scoreBoard(header:createScoreBoard( + header:createScoreDisplay( + match.opponents[1], + match.opponents[2] + ), + match.bestof, + not match.finished + )) + :rightOpponent(header:createOpponent(match.opponents[2], 'right')) +end + +---@param match MatchGroupUtilMatch +---@param footer MatchSummaryFooter +---@return MatchSummaryFooter +function CustomMatchSummary.addToFooter(match, footer) + footer = MatchSummary.addVodsToFooter(match, footer) + + return footer:addElement(match.extradata.showh2h and CustomMatchSummary._getHeadToHead(match) or nil) +end + +---@param match MatchGroupUtilMatch +---@return string function CustomMatchSummary._getHeadToHead(match) local opponents = match.opponents local team1, team2 = mw.uri.encode(opponents[1].name), mw.uri.encode(opponents[2].name) @@ -132,83 +180,9 @@ function CustomMatchSummary._getHeadToHead(match) return HEADTOHEAD:format(link) end -function CustomMatchSummary.getByMatchId(args) - local match = MatchGroupUtil.fetchMatchForBracketDisplay(args.bracketId, args.matchId) - - local matchSummary = MatchSummary():init() - - matchSummary:header(CustomMatchSummary._createHeader(match)) - :body(CustomMatchSummary._createBody(match)) - - if match.comment then - local comment = MatchSummary.Comment():content(match.comment) - matchSummary:comment(comment) - end - - -- footer - local vods = {} - for index, game in ipairs(match.games) do - if game.vod then - vods[index] = game.vod - end - end - - local headToHead = match.extradata.showh2h and - CustomMatchSummary._getHeadToHead(match) or nil - - if - Table.isNotEmpty(vods) or - String.isNotEmpty(match.vod) or - Table.isNotEmpty(match.links) or - headToHead - then - local footer = MatchSummary.Footer() - - -- Match Vod - if String.isNotEmpty(match.vod) then - footer:addElement(VodLink.display{ - vod = match.vod, - }) - end - - -- Game Vods - for index, vod in pairs(vods) do - footer:addElement(VodLink.display{ - gamenum = index, - vod = vod, - }) - end - - -- Head-to-head - if headToHead then - footer:addElement(headToHead) - end - - matchSummary:footer(footer) - end - - return matchSummary:create() -end - -function CustomMatchSummary._createHeader(match) - local header = Header() - - header - :leftOpponent(header:createOpponent(match.opponents[1], 'left')) - :scoreBoard(header:createScoreBoard( - header:createScoreDisplay( - match.opponents[1], - match.opponents[2] - ), - match.bestof, - not match.finished - )) - :rightOpponent(header:createOpponent(match.opponents[2], 'right')) - - return header -end - -function CustomMatchSummary._createBody(match) +---@param match MatchGroupUtilMatch +---@return MatchSummaryBody +function CustomMatchSummary.createBody(match) local body = MatchSummary.Body() body:addRow(MatchSummary.Row():addElement(DisplayHelper.MatchCountdownBlock(match))) @@ -234,6 +208,8 @@ function CustomMatchSummary._createBody(match) return body end +---@param game MatchGroupUtilGame +---@return MatchSummaryRow function CustomMatchSummary._createGame(game) local row = MatchSummary.Row() :addClass('brkts-popup-body-game') @@ -299,6 +275,12 @@ function CustomMatchSummary._createGame(game) return row end +---@param icon string +---@param shouldDisplay boolean? +---@param additionalElement number|string|Html|nil +---@param side integer? +---@param hoverText string|number|nil +---@return Html function CustomMatchSummary._iconDisplay(icon, shouldDisplay, additionalElement, side, hoverText) local flip = side == 2 return mw.html.create('div') From 419c2f5a4448f283034af4444501589a45a343c3 Mon Sep 17 00:00:00 2001 From: hjpalpha Date: Thu, 28 Sep 2023 15:03:24 +0200 Subject: [PATCH 4/9] remove unsued requires & order requires --- components/match2/wikis/trackmania/match_summary.lua | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/components/match2/wikis/trackmania/match_summary.lua b/components/match2/wikis/trackmania/match_summary.lua index 4fa0f83d048..b6f56bea662 100644 --- a/components/match2/wikis/trackmania/match_summary.lua +++ b/components/match2/wikis/trackmania/match_summary.lua @@ -6,16 +6,14 @@ -- Please see https://github.com/Liquipedia/Lua-Modules to contribute -- +local Abbreviation = require('Module:Abbreviation') local Class = require('Module:Class') -local Lua = require('Module:Lua') -local Table = require('Module:Table') -local VodLink = require('Module:VodLink') local Json = require('Module:Json') -local Abbreviation = require('Module:Abbreviation') +local Lua = require('Module:Lua') local String = require('Module:StringUtils') +local Table = require('Module:Table') local DisplayHelper = Lua.import('Module:MatchGroup/Display/Helper', {requireDevIfEnabled = true}) -local MatchGroupUtil = Lua.import('Module:MatchGroup/Util', {requireDevIfEnabled = true}) local MatchSummary = Lua.import('Module:MatchSummary/Base', {requireDevIfEnabled = true}) local OpponentDisplay = require('Module:OpponentLibraries').OpponentDisplay From a2528254c70aa7d80ed2a2dc715b875387fdb5d7 Mon Sep 17 00:00:00 2001 From: hjpalpha Date: Thu, 28 Sep 2023 15:07:42 +0200 Subject: [PATCH 5/9] require correct module --- components/match2/wikis/trackmania/match_summary.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/match2/wikis/trackmania/match_summary.lua b/components/match2/wikis/trackmania/match_summary.lua index b6f56bea662..071756f7354 100644 --- a/components/match2/wikis/trackmania/match_summary.lua +++ b/components/match2/wikis/trackmania/match_summary.lua @@ -14,7 +14,7 @@ local String = require('Module:StringUtils') local Table = require('Module:Table') local DisplayHelper = Lua.import('Module:MatchGroup/Display/Helper', {requireDevIfEnabled = true}) -local MatchSummary = Lua.import('Module:MatchSummary/Base', {requireDevIfEnabled = true}) +local MatchSummary = Lua.import('Module:MatchSummary/Base/temp', {requireDevIfEnabled = true}) local OpponentDisplay = require('Module:OpponentLibraries').OpponentDisplay local GREEN_CHECK = '[[File:GreenCheck.png|14x14px|link=]]' From 7de50826e85746dd65832bb7bda302888af47f4a Mon Sep 17 00:00:00 2001 From: hjpalpha Date: Thu, 28 Sep 2023 15:26:11 +0200 Subject: [PATCH 6/9] rl --- .../wikis/rocketleague/match_summary.lua | 215 ++++++++---------- .../match2/wikis/trackmania/match_summary.lua | 2 + 2 files changed, 98 insertions(+), 119 deletions(-) diff --git a/components/match2/wikis/rocketleague/match_summary.lua b/components/match2/wikis/rocketleague/match_summary.lua index 8283d71a3b9..1ae6195edae 100644 --- a/components/match2/wikis/rocketleague/match_summary.lua +++ b/components/match2/wikis/rocketleague/match_summary.lua @@ -6,66 +6,62 @@ -- Please see https://github.com/Liquipedia/Lua-Modules to contribute -- +local Abbreviation = require('Module:Abbreviation') local Class = require('Module:Class') +local Json = require('Module:Json') local Logic = require('Module:Logic') local Lua = require('Module:Lua') -local Table = require('Module:Table') -local VodLink = require('Module:VodLink') -local Json = require('Module:Json') -local Abbreviation = require('Module:Abbreviation') local String = require('Module:StringUtils') +local Table = require('Module:Table') local DisplayHelper = Lua.import('Module:MatchGroup/Display/Helper', {requireDevIfEnabled = true}) -local MatchGroupUtil = Lua.import('Module:MatchGroup/Util', {requireDevIfEnabled = true}) -local MatchSummary = Lua.import('Module:MatchSummary/Base', {requireDevIfEnabled = true}) +local MatchSummary = Lua.import('Module:MatchSummary/Base/temp', {requireDevIfEnabled = true}) local OpponentDisplay = Lua.import('Module:OpponentDisplay', {requireDevIfEnabled = true}) -local _GREEN_CHECK = '[[File:GreenCheck.png|14x14px|link=]]' -local _NO_CHECK = '[[File:NoCheck.png|link=]]' -local _TIMEOUT = '[[File:Cooldown_Clock.png|14x14px|link=]]' +local GREEN_CHECK = '[[File:GreenCheck.png|14x14px|link=]]' +local NO_CHECK = '[[File:NoCheck.png|link=]]' +local TIMEOUT = '[[File:Cooldown_Clock.png|14x14px|link=]]' -local _SHIFT_PREFIX = '[[File:ShiftRLE icon.png|14x14px|link=' -local _SHIFT_SUFFIX = '|ShiftRLE matchpage]]' -local _BALLCHASING_PREFIX = '[[File:Ballchasing icon.png|14x14px|link=' -local _BALLCHASING_SUFFIX = '|Ballchasing replays]]' -local _HEADTOHEAD_PREFIX = '[[File:Match Info Stats.png|14x14px|link=' -local _HEADTOHEAD_SUFFIX = '|Head to Head history]]' +local SHIFT_PREFIX = '[[File:ShiftRLE icon.png|14x14px|link=' +local SHIFT_SUFFIX = '|ShiftRLE matchpage]]' +local BALLCHASING_PREFIX = '[[File:Ballchasing icon.png|14x14px|link=' +local BALLCHASING_SUFFIX = '|Ballchasing replays]]' +local HEADTOHEAD_PREFIX = '[[File:Match Info Stats.png|14x14px|link=' +local HEADTOHEAD_SUFFIX = '|Head to Head history]]' -local _TBD_ICON = mw.ext.TeamTemplate.teamicon('tbd') +local TBD_ICON = mw.ext.TeamTemplate.teamicon('tbd') -- Custom Header Class -local Header = Class.new( - function(self) - self.root = mw.html.create('div') - self.root:addClass('brkts-popup-header-dev') - end -) - +---@class RocketleagueMatchSummaryHeader: MatchSummaryHeader +---@field leftElementAdditional Html +---@field rightElementAdditional Html +---@field scoreBoardElement Html +local Header = Class.new(MatchSummary.Header) + +---@param content Html +---@return RocketleagueMatchSummaryHeader function Header:leftOpponentTeam(content) self.leftElementAdditional = content return self end +---@param content Html +---@return RocketleagueMatchSummaryHeader function Header:rightOpponentTeam(content) self.rightElementAdditional = content return self end +---@param content Html +---@return RocketleagueMatchSummaryHeader function Header:scoreBoard(content) - self.scoreBoard = content - return self -end - -function Header:leftOpponent(content) - self.leftElement = content - return self -end - -function Header:rightOpponent(content) - self.rightElement = content + self.scoreBoardElement = content return self end +---@param opponent1 standardOpponent +---@param opponent2 standardOpponent +---@return Html function Header:createScoreDisplay(opponent1, opponent2) local function getScore(opponent) local scoreText @@ -103,6 +99,10 @@ function Header:createScoreDisplay(opponent1, opponent2) :node(getScore(opponent2)) end +---@param score number? +---@param bestof number? +---@param isNotFinished boolean? +---@return Html function Header:createScoreBoard(score, bestof, isNotFinished) local scoreBoardNode = mw.html.create('div') :addClass('brkts-popup-spaced') @@ -129,17 +129,23 @@ function Header:createScoreBoard(score, bestof, isNotFinished) return scoreBoardNode:node(score) end +---@param opponent standardOpponent +---@param date string +---@return Html? function Header:soloOpponentTeam(opponent, date) if opponent.type == 'solo' then local teamExists = mw.ext.TeamTemplate.teamexists(opponent.template or '') local display = teamExists and mw.ext.TeamTemplate.teamicon(opponent.template, date) - or _TBD_ICON + or TBD_ICON return mw.html.create('div'):wikitext(display) :addClass('brkts-popup-header-opponent-solo-team') end end +---@param opponent standardOpponent +---@param opponentIndex integer +---@return Html function Header:createOpponent(opponent, opponentIndex) return OpponentDisplay.BlockOpponent({ flip = opponentIndex == 1, @@ -152,100 +158,32 @@ function Header:createOpponent(opponent, opponentIndex) or 'brkts-popup-header-opponent-solo-with-team') end +---@return Html function Header:create() self.root:tag('div'):addClass('brkts-popup-header-opponent'):addClass('brkts-popup-header-opponent-left') :node(self.leftElementAdditional) :node(self.leftElement) - self.root:node(self.scoreBoard) + self.root:node(self.scoreBoardElement) self.root:tag('div'):addClass('brkts-popup-header-opponent'):addClass('brkts-popup-header-opponent-right') :node(self.rightElement) :node(self.rightElementAdditional) return self.root end - local CustomMatchSummary = {} -function CustomMatchSummary._getHeadToHead(opponents) - local team1, team2 = mw.uri.encode(opponents[1].name), mw.uri.encode(opponents[2].name) - local link = tostring(mw.uri.fullUrl('Special:RunQuery/Head2head')) - .. '?RunQuery=Run&pfRunQueryFormName=Head2head&Headtohead%5Bteam1%5D=' - .. team1 .. '&Headtohead%5Bteam2%5D=' .. team2 - return _HEADTOHEAD_PREFIX .. link .. _HEADTOHEAD_SUFFIX -end - +---@param args table +---@return Html function CustomMatchSummary.getByMatchId(args) - local match = MatchGroupUtil.fetchMatchForBracketDisplay(args.bracketId, args.matchId) - - local matchSummary = MatchSummary():init() - - matchSummary:header(CustomMatchSummary._createHeader(match)) - :body(CustomMatchSummary._createBody(match)) - - if match.comment then - local comment = MatchSummary.Comment():content(match.comment) - matchSummary:comment(comment) - end - - -- footer - local vods = {} - for index, game in ipairs(match.games) do - if game.vod then - vods[index] = game.vod - end - end - - local headToHead = match.extradata.showh2h and - CustomMatchSummary._getHeadToHead(match.opponents) or nil - - if - Table.isNotEmpty(vods) or - String.isNotEmpty(match.vod) or - Table.isNotEmpty(match.links) or - headToHead - then - local footer = MatchSummary.Footer() - - -- Shift - for _, shift in Table.iter.pairsByPrefix(match.links, 'shift', {requireIndex = false}) do - footer:addElement(_SHIFT_PREFIX .. shift .. _SHIFT_SUFFIX) - end - - -- Ballchasing - for _, ballchasing in Table.iter.pairsByPrefix(match.links, 'ballchasing', {requireIndex = false}) do - footer:addElement(_BALLCHASING_PREFIX .. ballchasing .. _BALLCHASING_SUFFIX) - end - - -- Match Vod - if String.isNotEmpty(match.vod) then - footer:addElement(VodLink.display{ - vod = match.vod, - }) - end - - -- Game Vods - for index, vod in pairs(vods) do - footer:addElement(VodLink.display{ - gamenum = index, - vod = vod, - }) - end - - -- Head-to-head - if headToHead then - footer:addElement(headToHead) - end - - matchSummary:footer(footer) - end - - return matchSummary:create() + return MatchSummary.defaultGetByMatchId(CustomMatchSummary, args) end -function CustomMatchSummary._createHeader(match) +---@param match MatchGroupUtilMatch +---@return RocketleagueMatchSummaryHeader +function CustomMatchSummary.createHeader(match) local header = Header() - header + return header :leftOpponentTeam(header:soloOpponentTeam(match.opponents[1], match.date)) :leftOpponent(header:createOpponent(match.opponents[1], 1)) :scoreBoard(header:createScoreBoard( @@ -258,11 +196,40 @@ function CustomMatchSummary._createHeader(match) )) :rightOpponent(header:createOpponent(match.opponents[2], 2)) :rightOpponentTeam(header:soloOpponentTeam(match.opponents[2], match.date)) +end - return header +---@param match MatchGroupUtilMatch +---@param footer MatchSummaryFooter +---@return MatchSummaryFooter +function CustomMatchSummary.addToFooter(match, footer) + -- Shift + for _, shift in Table.iter.pairsByPrefix(match.links, 'shift', {requireIndex = false}) do + footer:addElement(SHIFT_PREFIX .. shift .. SHIFT_SUFFIX) + end + + -- Ballchasing + for _, ballchasing in Table.iter.pairsByPrefix(match.links, 'ballchasing', {requireIndex = false}) do + footer:addElement(BALLCHASING_PREFIX .. ballchasing .. BALLCHASING_SUFFIX) + end + + footer = MatchSummary.addVodsToFooter(match, footer) + + return footer:addElement(match.extradata.showh2h and CustomMatchSummary._getHeadToHead(match) or nil) +end + +---@param opponents standardOpponent[] +---@return string +function CustomMatchSummary._getHeadToHead(opponents) + local team1, team2 = mw.uri.encode(opponents[1].name), mw.uri.encode(opponents[2].name) + local link = tostring(mw.uri.fullUrl('Special:RunQuery/Head2head')) + .. '?RunQuery=Run&pfRunQueryFormName=Head2head&Headtohead%5Bteam1%5D=' + .. team1 .. '&Headtohead%5Bteam2%5D=' .. team2 + return HEADTOHEAD_PREFIX .. link .. HEADTOHEAD_SUFFIX end -function CustomMatchSummary._createBody(match) +---@param match MatchGroupUtilMatch +---@return MatchSummaryBody +function CustomMatchSummary.createBody(match) local body = MatchSummary.Body() body:addRow(MatchSummary.Row():addElement(DisplayHelper.MatchCountdownBlock(match))) @@ -289,6 +256,8 @@ function CustomMatchSummary._createBody(match) return body end +---@param game MatchGroupUtilGame +---@return MatchSummaryRow function CustomMatchSummary._createGame(game) local row = MatchSummary.Row() :addClass('brkts-popup-body-game') @@ -316,14 +285,14 @@ function CustomMatchSummary._createGame(game) end row:addElement(CustomMatchSummary._iconDisplay( - _GREEN_CHECK, + GREEN_CHECK, game.winner == 1, game.scores[1], 1 )) row:addElement(centerNode) row:addElement(CustomMatchSummary._iconDisplay( - _GREEN_CHECK, + GREEN_CHECK, game.winner == 2, game.scores[2], 2 @@ -333,7 +302,7 @@ function CustomMatchSummary._createGame(game) local timeouts = Json.parseIfString(extradata.timeout) row:addElement(MatchSummary.Break():create()) row:addElement(CustomMatchSummary._iconDisplay( - _TIMEOUT, + TIMEOUT, Table.includes(timeouts, 1) )) row:addElement(mw.html.create('div') @@ -341,7 +310,7 @@ function CustomMatchSummary._createGame(game) :node(mw.html.create('div'):node('Timeout')) ) row:addElement(CustomMatchSummary._iconDisplay( - _TIMEOUT, + TIMEOUT, Table.includes(timeouts, 2) )) end @@ -370,6 +339,9 @@ function CustomMatchSummary._createGame(game) return row end +---@param goalesValue string|number +---@param side 1|2 +---@return Html function CustomMatchSummary._goalDisaplay(goalesValue, side) local goalsDisplay = mw.html.create('div') :cssText(side == 2 and 'float:right; margin-right:10px;' or nil) @@ -384,12 +356,17 @@ function CustomMatchSummary._goalDisaplay(goalesValue, side) :node(goalsDisplay) end +---@param icon string +---@param shouldDisplay boolean? +---@param additionalElement number|string|Html|nil +---@param side integer? +---@return Html function CustomMatchSummary._iconDisplay(icon, shouldDisplay, additionalElement, side) local flip = side == 2 return mw.html.create('div') :addClass('brkts-popup-spaced') :node(additionalElement and flip and mw.html.create('div'):node(additionalElement) or nil) - :node(shouldDisplay and icon or _NO_CHECK) + :node(shouldDisplay and icon or NO_CHECK) :node(additionalElement and (not flip) and mw.html.create('div'):node(additionalElement) or nil) end diff --git a/components/match2/wikis/trackmania/match_summary.lua b/components/match2/wikis/trackmania/match_summary.lua index 071756f7354..e20f4e5d95e 100644 --- a/components/match2/wikis/trackmania/match_summary.lua +++ b/components/match2/wikis/trackmania/match_summary.lua @@ -127,6 +127,8 @@ function CustomMatchSummary.getByMatchId(args) return MatchSummary.defaultGetByMatchId(CustomMatchSummary, args) end +---@param match MatchGroupUtilMatch +---@return TrackmaniaMatchSummaryHeader function CustomMatchSummary.createHeader(match) local header = Header() From 828b7b40bdd73de62115a9b7f568ca8cef2e71b8 Mon Sep 17 00:00:00 2001 From: hjpalpha Date: Thu, 28 Sep 2023 15:28:25 +0200 Subject: [PATCH 7/9] fix --- components/match2/wikis/rocketleague/match_summary.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/match2/wikis/rocketleague/match_summary.lua b/components/match2/wikis/rocketleague/match_summary.lua index 1ae6195edae..6f71bb71595 100644 --- a/components/match2/wikis/rocketleague/match_summary.lua +++ b/components/match2/wikis/rocketleague/match_summary.lua @@ -214,7 +214,7 @@ function CustomMatchSummary.addToFooter(match, footer) footer = MatchSummary.addVodsToFooter(match, footer) - return footer:addElement(match.extradata.showh2h and CustomMatchSummary._getHeadToHead(match) or nil) + return footer:addElement(match.extradata.showh2h and CustomMatchSummary._getHeadToHead(match.opponents) or nil) end ---@param opponents standardOpponent[] From 814f399d2cdf87f935fdb2222bbfe0dbc8129178 Mon Sep 17 00:00:00 2001 From: hjpalpha Date: Wed, 4 Oct 2023 08:44:30 +0200 Subject: [PATCH 8/9] adjust rl match icon building --- .../wikis/rocketleague/match_summary.lua | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/components/match2/wikis/rocketleague/match_summary.lua b/components/match2/wikis/rocketleague/match_summary.lua index 6f71bb71595..32e83a65d29 100644 --- a/components/match2/wikis/rocketleague/match_summary.lua +++ b/components/match2/wikis/rocketleague/match_summary.lua @@ -22,15 +22,14 @@ local GREEN_CHECK = '[[File:GreenCheck.png|14x14px|link=]]' local NO_CHECK = '[[File:NoCheck.png|link=]]' local TIMEOUT = '[[File:Cooldown_Clock.png|14x14px|link=]]' -local SHIFT_PREFIX = '[[File:ShiftRLE icon.png|14x14px|link=' -local SHIFT_SUFFIX = '|ShiftRLE matchpage]]' -local BALLCHASING_PREFIX = '[[File:Ballchasing icon.png|14x14px|link=' -local BALLCHASING_SUFFIX = '|Ballchasing replays]]' -local HEADTOHEAD_PREFIX = '[[File:Match Info Stats.png|14x14px|link=' -local HEADTOHEAD_SUFFIX = '|Head to Head history]]' - local TBD_ICON = mw.ext.TeamTemplate.teamicon('tbd') +local LINK_DATA = { + shift = {icon = 'File:ShiftRLE icon.png', text = 'ShiftRLE matchpage'}, + ballchasing = {icon = 'File:Ballchasing icon.png', text = 'Ballchasing replays'}, + headtohead = {icon = 'File:Match Info Stats.png', text = 'Head to Head history'}, +} + -- Custom Header Class ---@class RocketleagueMatchSummaryHeader: MatchSummaryHeader ---@field leftElementAdditional Html @@ -202,29 +201,30 @@ end ---@param footer MatchSummaryFooter ---@return MatchSummaryFooter function CustomMatchSummary.addToFooter(match, footer) - -- Shift - for _, shift in Table.iter.pairsByPrefix(match.links, 'shift', {requireIndex = false}) do - footer:addElement(SHIFT_PREFIX .. shift .. SHIFT_SUFFIX) - end - - -- Ballchasing - for _, ballchasing in Table.iter.pairsByPrefix(match.links, 'ballchasing', {requireIndex = false}) do - footer:addElement(BALLCHASING_PREFIX .. ballchasing .. BALLCHASING_SUFFIX) + for linkType, linkData in pairs(LINK_DATA) do + for _, link in Table.iter.pairsByPrefix(match.links, linkType, {requireIndex = false}) do + footer:addLink(link, linkData.icon, linkData.iconDark, linkData.text) + end end footer = MatchSummary.addVodsToFooter(match, footer) - return footer:addElement(match.extradata.showh2h and CustomMatchSummary._getHeadToHead(match.opponents) or nil) + if not match.extradata.showh2h then + return footer + end + + local h2hLinkData = LINK_DATA.headtohead + return footer:addLink(CustomMatchSummary._getHeadToHead(match.opponents), + h2hLinkData.icon, h2hLinkData.iconDark, h2hLinkData.text) end ---@param opponents standardOpponent[] ---@return string function CustomMatchSummary._getHeadToHead(opponents) local team1, team2 = mw.uri.encode(opponents[1].name), mw.uri.encode(opponents[2].name) - local link = tostring(mw.uri.fullUrl('Special:RunQuery/Head2head')) + return tostring(mw.uri.fullUrl('Special:RunQuery/Head2head')) .. '?RunQuery=Run&pfRunQueryFormName=Head2head&Headtohead%5Bteam1%5D=' .. team1 .. '&Headtohead%5Bteam2%5D=' .. team2 - return HEADTOHEAD_PREFIX .. link .. HEADTOHEAD_SUFFIX end ---@param match MatchGroupUtilMatch From 1403016e825cc095d898672606841089cf26dde5 Mon Sep 17 00:00:00 2001 From: hjpalpha Date: Wed, 4 Oct 2023 09:17:48 +0200 Subject: [PATCH 9/9] as per review in #3330 --- components/match2/wikis/rocketleague/match_summary.lua | 6 +++--- components/match2/wikis/sideswipe/match_summary.lua | 6 +++--- components/match2/wikis/trackmania/match_summary.lua | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/components/match2/wikis/rocketleague/match_summary.lua b/components/match2/wikis/rocketleague/match_summary.lua index 32e83a65d29..c2ea82132ac 100644 --- a/components/match2/wikis/rocketleague/match_summary.lua +++ b/components/match2/wikis/rocketleague/match_summary.lua @@ -38,21 +38,21 @@ local LINK_DATA = { local Header = Class.new(MatchSummary.Header) ---@param content Html ----@return RocketleagueMatchSummaryHeader +---@return self function Header:leftOpponentTeam(content) self.leftElementAdditional = content return self end ---@param content Html ----@return RocketleagueMatchSummaryHeader +---@return self function Header:rightOpponentTeam(content) self.rightElementAdditional = content return self end ---@param content Html ----@return RocketleagueMatchSummaryHeader +---@return self function Header:scoreBoard(content) self.scoreBoardElement = content return self diff --git a/components/match2/wikis/sideswipe/match_summary.lua b/components/match2/wikis/sideswipe/match_summary.lua index 63e12720009..66152e26531 100644 --- a/components/match2/wikis/sideswipe/match_summary.lua +++ b/components/match2/wikis/sideswipe/match_summary.lua @@ -32,21 +32,21 @@ local TBD_ICON = mw.ext.TeamTemplate.teamicon('tbd') local Header = Class.new(MatchSummary.Header) ---@param content Html ----@return SideswipeMatchSummaryHeader +---@return self function Header:leftOpponentTeam(content) self.leftElementAdditional = content return self end ---@param content Html ----@return SideswipeMatchSummaryHeader +---@return self function Header:rightOpponentTeam(content) self.rightElementAdditional = content return self end ---@param content Html ----@return SideswipeMatchSummaryHeader +---@return self function Header:scoreBoard(content) self.scoreBoardElement = content return self diff --git a/components/match2/wikis/trackmania/match_summary.lua b/components/match2/wikis/trackmania/match_summary.lua index e20f4e5d95e..98d3ee13383 100644 --- a/components/match2/wikis/trackmania/match_summary.lua +++ b/components/match2/wikis/trackmania/match_summary.lua @@ -31,7 +31,7 @@ local HEADTOHEAD = '[[File:Match Info Stats.png|14x14px|link=%s|Head to Head his local Header = Class.new(MatchSummary.Header) ---@param content Html ----@return TrackmaniaMatchSummaryHeader +---@return self function Header:scoreBoard(content) self.scoreBoardElement = content return self