diff --git a/components/match2/wikis/arenaofvalor/match_summary.lua b/components/match2/wikis/arenaofvalor/match_summary.lua index 408c9112565..d5425a6c1a0 100644 --- a/components/match2/wikis/arenaofvalor/match_summary.lua +++ b/components/match2/wikis/arenaofvalor/match_summary.lua @@ -8,29 +8,32 @@ local CustomMatchSummary = {} +local Array = require('Module:Array') +local ChampionIcon = require('Module:HeroIcon') local Class = require('Module:Class') local DisplayHelper = require('Module:MatchGroup/Display/Helper') +local ExternalLinks = require('Module:ExternalLinks') local Logic = require('Module:Logic') local Lua = require('Module:Lua') -local ChampionIcon = require('Module:HeroIcon') -local Table = require('Module:Table') -local ExternalLinks = require('Module:ExternalLinks') local String = require('Module:StringUtils') -local Array = require('Module:Array') +local Table = require('Module:Table') -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 _MAX_NUM_BANS = 5 -local _NUM_CHAMPIONS_PICK = 5 +local MAX_NUM_BANS = 5 +local NUM_CHAMPIONS_PICK = 5 -local _GREEN_CHECK = '[[File:GreenCheck.png|14x14px|link=]]' -local _NO_CHECK = '[[File:NoCheck.png|link=]]' +local GREEN_CHECK = '[[File:GreenCheck.png|14x14px|link=]]' +local NO_CHECK = '[[File:NoCheck.png|link=]]' -local _EPOCH_TIME = '1970-01-01 00:00:00' -local _EPOCH_TIME_EXTENDED = '1970-01-01T00:00:00+00:00' +local EPOCH_TIME = '1970-01-01 00:00:00' +local EPOCH_TIME_EXTENDED = '1970-01-01T00:00:00+00:00' -- Champion Ban Class +---@class AovChampionBan: MatchSummaryRowInterface +---@operator call: AovChampionBan +---@field root Html +---@field table Html local ChampionBan = Class.new( function(self) self.root = mw.html.create('div'):addClass('brkts-popup-mapveto') @@ -40,6 +43,7 @@ local ChampionBan = Class.new( end ) +---@return self function ChampionBan:createHeader() self.table:tag('tr') :tag('th'):css('width','40%'):wikitext(''):done() @@ -48,6 +52,11 @@ function ChampionBan:createHeader() return self end +---@param banData {numberOfBans: integer, [1]: table, [2]: table} +---@param gameNumber integer +---@param numberOfBans integer +---@param date string +---@return self function ChampionBan:banRow(banData, gameNumber, numberOfBans, date) self.table:tag('tr') :tag('td') @@ -64,66 +73,36 @@ function ChampionBan:banRow(banData, gameNumber, numberOfBans, date) return self end +---@return Html function ChampionBan:create() return self.root end - +---@param args table +---@return Html function CustomMatchSummary.getByMatchId(args) - local match = MatchGroupUtil.fetchMatchForBracketDisplay(args.bracketId, args.matchId) - - local matchSummary = MatchSummary():init('420px') - - matchSummary:header(CustomMatchSummary._createHeader(match)) - :body(CustomMatchSummary._createBody(match)) - - if match.comment then - local comment = MatchSummary.Comment():content(match.comment) - matchSummary:comment(comment) - end - - local vods = {} - for index, game in ipairs(match.games) do - if game.vod then - vods[index] = game.vod - end - end - - match.links.lrthread = match.lrthread - match.links.vod = match.vod - if not Table.isEmpty(vods) or not Table.isEmpty(match.links) then - local footer = MatchSummary.Footer() - - -- Game Vods - for index, vod in pairs(vods) do - match.links['vodgame' .. index] = vod - end - - footer.inner = mw.html.create('div') - :addClass('bracket-popup-footer plainlinks vodlink') - :node(ExternalLinks.print(match.links)) - - matchSummary:footer(footer) - end - - return matchSummary:create() + return MatchSummary.defaultGetByMatchId(CustomMatchSummary, args, {width = '420px'}) end -function CustomMatchSummary._createHeader(match) - local header = MatchSummary.Header() +---@param match MatchGroupUtilMatch +---@param footer MatchSummaryFooter +---@return MatchSummaryFooter +function CustomMatchSummary.addToFooter(match, footer) + footer = MatchSummary.addVodsToFooter(match, footer) - header:leftOpponent(header:createOpponent(match.opponents[1], 'left', 'bracket')) - :leftScore(header:createScore(match.opponents[1])) - :rightScore(header:createScore(match.opponents[2])) - :rightOpponent(header:createOpponent(match.opponents[2], 'right', 'bracket')) + if Table.isNotEmpty(match.links) then + footer:addElement(ExternalLinks.print(match.links)) + end - return header + return footer end -function CustomMatchSummary._createBody(match) +---@param match MatchGroupUtilMatch +---@return MatchSummaryBody +function CustomMatchSummary.createBody(match) local body = MatchSummary.Body() - if match.dateIsExact or (match.date ~= _EPOCH_TIME_EXTENDED and match.date ~= _EPOCH_TIME) then + if match.dateIsExact or (match.date ~= EPOCH_TIME_EXTENDED and match.date ~= EPOCH_TIME) then -- dateIsExact means we have both date and time. Show countdown -- if match is not epoch=0, we have a date, so display the date body:addRow(MatchSummary.Row():addElement( @@ -157,10 +136,10 @@ function CustomMatchSummary._createBody(match) -- Pre-Process Champion Ban Data local championBanData = {} for gameIndex, game in ipairs(match.games) do - local extradata = game.extradata + local extradata = game.extradata or {} local banData = {{}, {}} local numberOfBans = 0 - for index = 1, _MAX_NUM_BANS do + for index = 1, MAX_NUM_BANS do if String.isNotEmpty(extradata['team1ban' .. index]) then numberOfBans = index banData[1][index] = extradata['team1ban' .. index] @@ -193,13 +172,17 @@ function CustomMatchSummary._createBody(match) return body end +---@param game MatchGroupUtilGame +---@param gameIndex integer +---@param date string +---@return MatchSummaryRow? function CustomMatchSummary._createGame(game, gameIndex, date) local row = MatchSummary.Row() local extradata = game.extradata or {} local championsData = {{}, {}} local championsDataIsEmpty = true - for champIndex = 1, _NUM_CHAMPIONS_PICK do + for champIndex = 1, NUM_CHAMPIONS_PICK do if String.isNotEmpty(extradata['team1champion' .. champIndex]) then championsData[1][champIndex] = extradata['team1champion' .. champIndex] championsDataIsEmpty = false @@ -224,7 +207,7 @@ function CustomMatchSummary._createGame(game, gameIndex, date) :css('font-size', '85%') :css('overflow', 'hidden') - row:addElement(CustomMatchSummary._opponentChampionsDisplay(championsData[1], _NUM_CHAMPIONS_PICK, date, false)) + row:addElement(CustomMatchSummary._opponentChampionsDisplay(championsData[1], NUM_CHAMPIONS_PICK, date, false)) row:addElement(CustomMatchSummary._createCheckMark(game.winner == 1)) row:addElement(mw.html.create('div') :addClass('brkts-popup-body-element-vertical-centered') @@ -234,7 +217,7 @@ function CustomMatchSummary._createGame(game, gameIndex, date) }) ) row:addElement(CustomMatchSummary._createCheckMark(game.winner == 2)) - row:addElement(CustomMatchSummary._opponentChampionsDisplay(championsData[2], _NUM_CHAMPIONS_PICK, date, true)) + row:addElement(CustomMatchSummary._opponentChampionsDisplay(championsData[2], NUM_CHAMPIONS_PICK, date, true)) -- Add Comment if not Logic.isEmpty(game.comment) then @@ -248,6 +231,8 @@ function CustomMatchSummary._createGame(game, gameIndex, date) return row end +---@param isWinner boolean? +---@return Html function CustomMatchSummary._createCheckMark(isWinner) local container = mw.html.create('div') :addClass('brkts-popup-spaced') @@ -256,18 +241,26 @@ function CustomMatchSummary._createCheckMark(isWinner) :css('margin-right', '3%') if isWinner then - container:node(_GREEN_CHECK) + container:node(GREEN_CHECK) else - container:node(_NO_CHECK) + container:node(NO_CHECK) end return container end +---@param args table +---@return string function CustomMatchSummary._createAbbreviation(args) return '' .. args.text .. '' end +---@param opponentChampionsData table +---@param numberOfChampions integer +---@param date string +---@param flip boolean? +---@param isBan boolean? +---@return Html function CustomMatchSummary._opponentChampionsDisplay(opponentChampionsData, numberOfChampions, date, flip, isBan) local opponentChampionsDisplay = {} local color = opponentChampionsData.color or '' diff --git a/components/match2/wikis/brawlstars/match_summary.lua b/components/match2/wikis/brawlstars/match_summary.lua index 837c53ec9cb..2da53baa7a5 100644 --- a/components/match2/wikis/brawlstars/match_summary.lua +++ b/components/match2/wikis/brawlstars/match_summary.lua @@ -59,7 +59,7 @@ local Brawler = Class.new( end ) ----@return BrawlstarsMatchSummaryBrawler +---@return self function Brawler:createHeader() self.table:tag('tr') :tag('th'):css('width','35%'):wikitext(''):done() @@ -75,7 +75,7 @@ end ---@param numberBrawlers integer ---@param date string ---@param firstPick integer? ----@return BrawlstarsMatchSummaryBrawler +---@return self function Brawler:row(brawlerData, gameNumber, numberBrawlers, date, firstPick) if numberBrawlers > 0 then self.table:tag('tr') @@ -162,7 +162,7 @@ function CustomMatchSummary.getByMatchId(args) return MatchSummary.defaultGetByMatchId(CustomMatchSummary, args) end ----@param match table +---@param match MatchGroupUtilMatch ---@param footer MatchSummaryFooter ---@return MatchSummaryFooter function CustomMatchSummary.addToFooter(match, footer) @@ -172,7 +172,7 @@ function CustomMatchSummary.addToFooter(match, footer) return footer:addLinks(LINK_DATA, match.links) end ----@param match table +---@param match MatchGroupUtilMatch ---@return MatchSummaryBody function CustomMatchSummary.createBody(match) local body = MatchSummary.Body() @@ -242,7 +242,7 @@ function CustomMatchSummary.createBody(match) -- Pre-Process Brawler bans local showGameBans = {} for gameIndex, game in ipairs(match.games) do - local extradata = game.extradata + local extradata = game.extradata or {} local bans = Json.parseIfString(extradata.bans or '{}') if not Table.isEmpty(bans) then bans.numberOfBans = math.max(#bans.team1, #bans.team2) @@ -268,7 +268,7 @@ function CustomMatchSummary.createBody(match) return body end ----@param game table +---@param game MatchGroupUtilGame ---@param opponentIndex integer ---@return Html function CustomMatchSummary._gameScore(game, opponentIndex) @@ -276,7 +276,7 @@ function CustomMatchSummary._gameScore(game, opponentIndex) return htmlCreate('div'):wikitext(score) end ----@param game table +---@param game MatchGroupUtilGame ---@return MatchSummaryRow function CustomMatchSummary._createMapRow(game) local row = MatchSummary.Row() @@ -330,7 +330,7 @@ function CustomMatchSummary._createMapRow(game) return row end ----@param game table +---@param game MatchGroupUtilGame ---@return string function CustomMatchSummary._getMapDisplay(game) local mapDisplay = '[[' .. game.map .. ']]' diff --git a/components/match2/wikis/callofduty/match_summary.lua b/components/match2/wikis/callofduty/match_summary.lua index f5516efb7c4..b8fec226f5f 100644 --- a/components/match2/wikis/callofduty/match_summary.lua +++ b/components/match2/wikis/callofduty/match_summary.lua @@ -8,14 +8,12 @@ local Logic = require('Module:Logic') local Lua = require('Module:Lua') -local Table = require('Module:Table') -local VodLink = require('Module:VodLink') -local String = require('Module:StringUtils') local MapModes = require('Module:MapModes') +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 MatchGroupUtil = Lua.import('Module:MatchGroup/Util', {requireDevIfEnabled = true}) +local MatchSummary = Lua.import('Module:MatchSummary/Base/temp', {requireDevIfEnabled = true}) local EPOCH_TIME = '1970-01-01 00:00:00' local EPOCH_TIME_EXTENDED = '1970-01-01T00:00:00+00:00' @@ -24,69 +22,30 @@ local GREEN_CHECK = '' -local _NO_CHECK = '[[File:NoCheck.png|link=]]' +local EPOCH_TIME = '1970-01-01 00:00:00' +local EPOCH_TIME_EXTENDED = '1970-01-01T00:00:00+00:00' -local _LINK_DATA = { - vod = {icon = 'File:VOD Icon.png', text = 'Watch VOD'}, +local GREEN_CHECK = '' +local NO_CHECK = '[[File:NoCheck.png|link=]]' + +local LINK_DATA = { preview = {icon = 'File:Preview Icon32.png', text = 'Preview'}, lrthread = {icon = 'File:LiveReport32.png', text = 'LiveReport.png'}, esl = { @@ -46,30 +44,18 @@ local _LINK_DATA = { 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)) - - -- comment - if match.comment then - local comment = MatchSummary.Comment():content(match.comment) - matchSummary:comment(comment) - end + return MatchSummary.defaultGetByMatchId(CustomMatchSummary, args) +end - -- footer - local vods = {} - for index, game in ipairs(match.games) do - if game.vod then - vods[index] = game.vod - end - end +---@param match MatchGroupUtilMatch +---@param footer MatchSummaryFooter +---@return MatchSummaryFooter +function CustomMatchSummary.addToFooter(match, footer) + footer = MatchSummary.addVodsToFooter(match, footer) - match.links.lrthread = match.lrthread - match.links.vod = match.vod if match.opponents[1].type == Opponent.team and match.opponents[2].type == Opponent.team @@ -95,41 +81,15 @@ function CustomMatchSummary.getByMatchId(args) match.links.headtohead = buildQueryFormLink('Head2head', 'Headtohead', headtoheadArgs) end - if Table.isNotEmpty(vods) or Table.isNotEmpty(match.links) then - local footer = MatchSummary.Footer() - - -- Game Vods - for index, vod in pairs(vods) do - footer:addElement(VodLink.display{ - gamenum = index, - vod = vod, - source = vod.url - }) - end - - footer:addLinks(_LINK_DATA, match.links) - - matchSummary:footer(footer) - end - - return matchSummary:create() -end - -function CustomMatchSummary._createHeader(match) - local header = MatchSummary.Header() - - header:leftOpponent(header:createOpponent(match.opponents[1], 'left')) - :leftScore(header:createScore(match.opponents[1])) - :rightScore(header:createScore(match.opponents[2])) - :rightOpponent(header:createOpponent(match.opponents[2], 'right')) - - return header + return footer:addLinks(LINK_DATA, match.links) end -function CustomMatchSummary._createBody(match) +---@param match MatchGroupUtilMatch +---@return MatchSummaryBody +function CustomMatchSummary.createBody(match) local body = MatchSummary.Body() - if match.dateIsExact or (match.date ~= _EPOCH_TIME_EXTENDED and match.date ~= _EPOCH_TIME) then + if match.dateIsExact or (match.date ~= EPOCH_TIME_EXTENDED and match.date ~= EPOCH_TIME) then -- dateIsExact means we have both date and time. Show countdown -- if match is not epoch=0, we have a date, so display the date body:addRow(MatchSummary.Row():addElement( @@ -173,11 +133,16 @@ function CustomMatchSummary._createBody(match) return body end +---@param game MatchGroupUtilGame +---@param opponentIndex integer +---@return Html function CustomMatchSummary._gameScore(game, opponentIndex) local score = game.scores[opponentIndex] or '' return mw.html.create('div'):wikitext(score) end +---@param game MatchGroupUtilGame +---@return MatchSummaryRow function CustomMatchSummary._createMapRow(game) local row = MatchSummary.Row() @@ -230,6 +195,8 @@ function CustomMatchSummary._createMapRow(game) return row end +---@param game MatchGroupUtilGame +---@return string function CustomMatchSummary._getMapDisplay(game) local mapDisplay = '[[' .. game.map .. ']]' if String.isNotEmpty(game.mode) then @@ -238,14 +205,16 @@ function CustomMatchSummary._getMapDisplay(game) return mapDisplay end +---@param isWinner boolean? +---@return Html function CustomMatchSummary._addCheckmark(isWinner) local container = mw.html.create('div') container:addClass('brkts-popup-spaced'):css('line-height', '27px') if isWinner then - container:node(_GREEN_CHECK) + container:node(GREEN_CHECK) else - container:node(_NO_CHECK) + container:node(NO_CHECK) end return container