diff --git a/components/match2/wikis/dota2/match_summary.lua b/components/match2/wikis/dota2/match_summary.lua index 8156cae37c1..4530109016e 100644 --- a/components/match2/wikis/dota2/match_summary.lua +++ b/components/match2/wikis/dota2/match_summary.lua @@ -54,7 +54,7 @@ function CustomMatchSummary.createBody(match) return MatchSummaryWidgets.Body{children = WidgetUtil.collect( showCountdown and MatchSummaryWidgets.Row{children = DisplayHelper.MatchCountdownBlock(match)} or nil, showMatchPage and MatchSummaryWidgets.MatchPageLink{matchId = matchId} or nil, - unpack(Array.map(match.games, CustomMatchSummary._createGame)), + Array.map(match.games, CustomMatchSummary._createGame), MatchSummaryWidgets.Mvp(match.extradata.mvp), MatchSummaryWidgets.CharacterBanTable{bans = characterBansData, date = match.date}, casterRow and casterRow:create() or nil diff --git a/components/match2/wikis/honorofkings/match_summary.lua b/components/match2/wikis/honorofkings/match_summary.lua index 72877c8fb7b..1e4c1e735a7 100644 --- a/components/match2/wikis/honorofkings/match_summary.lua +++ b/components/match2/wikis/honorofkings/match_summary.lua @@ -8,23 +8,23 @@ local CustomMatchSummary = {} +local Array = require('Module:Array') local DateExt = require('Module:Date/Ext') local DisplayHelper = require('Module:MatchGroup/Display/Helper') local ExternalLinks = require('Module:ExternalLinks') -local Icon = require('Module:Icon') +local FnUtil = require('Module:FnUtil') local Logic = require('Module:Logic') local Lua = require('Module:Lua') local Table = require('Module:Table') local MatchSummary = Lua.import('Module:MatchSummary/Base') local MatchSummaryWidgets = Lua.import('Module:Widget/Match/Summary/All') +local HtmlWidgets = Lua.import('Module:Widget/Html/All') +local WidgetUtil = Lua.import('Module:Widget/Util') local MAX_NUM_BANS = 5 local NUM_CHAMPIONS_PICK = 5 -local GREEN_CHECK = Icon.makeIcon{iconName = 'winner', color = 'forest-green-text', size = '110%'} -local NO_CHECK = '[[File:NoCheck.png|link=]]' - ---@param args table ---@return Html function CustomMatchSummary.getByMatchId(args) @@ -47,48 +47,22 @@ end ---@param match MatchGroupUtilMatch ---@return MatchSummaryBody function CustomMatchSummary.createBody(match) - local body = MatchSummary.Body() - - if match.dateIsExact or match.timestamp ~= DateExt.defaultTimestamp then - -- dateIsExact means we have both date and time. Show countdown - -- if match is not default date, we have a date, so display the date - body:addRow(MatchSummary.Row():addElement( - DisplayHelper.MatchCountdownBlock(match) - )) - end - - -- Iterate each map - for gameIndex, game in ipairs(match.games) do - local rowDisplay = CustomMatchSummary._createGame(game, gameIndex, match.date) - if rowDisplay then - body:addRow(rowDisplay) - end - end - - -- Add Match MVP(s) - if Table.isNotEmpty(match.extradata.mvp) then - body.root:node(MatchSummaryWidgets.Mvp{ - players = match.extradata.mvp.players, - points = match.extradata.mvp.points, - }) - end - - -- Add the Character Bans + local showCountdown = match.timestamp ~= DateExt.defaultTimestamp local characterBansData = MatchSummary.buildCharacterBanData(match.games, MAX_NUM_BANS) - body.root:node(MatchSummaryWidgets.CharacterBanTable{ - bans = characterBansData, - date = match.date, - }) - return body + return MatchSummaryWidgets.Body{children = WidgetUtil.collect( + showCountdown and MatchSummaryWidgets.Row{children = DisplayHelper.MatchCountdownBlock(match)} or nil, + Array.map(match.games, FnUtil.curry(CustomMatchSummary._createGame, match.date)), + MatchSummaryWidgets.Mvp(match.extradata.mvp), + MatchSummaryWidgets.CharacterBanTable{bans = characterBansData, date = match.date} + )} end +---@param date string ---@param game MatchGroupUtilGame ---@param gameIndex integer ----@param date string ---@return MatchSummaryRow? -function CustomMatchSummary._createGame(game, gameIndex, date) - local row = MatchSummary.Row() +function CustomMatchSummary._createGame(date, game, gameIndex) local extradata = game.extradata or {} -- TODO: Change to use participant data @@ -101,67 +75,37 @@ function CustomMatchSummary._createGame(game, gameIndex, date) return nil end - row :addClass('brkts-popup-body-game') - :css('font-size', '85%') - :css('overflow', 'hidden') - - row:addElement(MatchSummaryWidgets.Characters{ - flipped = false, - date = date, - characters = characterData[1], - bg = 'brkts-popup-side-color-' .. (extradata.team1side or ''), - }) - row:addElement(CustomMatchSummary._createCheckMark(game.winner == 1)) - row:addElement(mw.html.create('div') - :addClass('brkts-popup-body-element-vertical-centered') - :wikitext(CustomMatchSummary._createAbbreviation{ - title = Logic.isEmpty(game.length) and ('Game ' .. gameIndex .. ' picks') or 'Match Length', - text = Logic.isEmpty(game.length) and ('Game ' .. gameIndex) or game.length, - }) - ) - row:addElement(CustomMatchSummary._createCheckMark(game.winner == 2)) - row:addElement(MatchSummaryWidgets.Characters{ - flipped = true, - date = date, - characters = characterData[2], - bg = 'brkts-popup-side-color-' .. (extradata.team2side or ''), - }) - - -- Add Comment - if not Logic.isEmpty(game.comment) then - row:addElement(MatchSummary.Break():create()) - local comment = mw.html.create('div') - comment :wikitext(game.comment) - :css('margin', 'auto') - :css('width', '100%') - row:addElement(comment) - end - - return row -end - ----@param isWinner boolean? ----@return Html -function CustomMatchSummary._createCheckMark(isWinner) - local container = mw.html.create('div') - :addClass('brkts-popup-spaced') - :css('line-height', '27px') - :css('margin-left', '3%') - :css('margin-right', '3%') - - if isWinner then - container:node(GREEN_CHECK) - else - container:node(NO_CHECK) - end - - return container -end - ----@param args table ----@return string -function CustomMatchSummary._createAbbreviation(args) - return '' .. args.text .. '' + -- Map Comment + local comment = Logic.isNotEmpty(game.comment) and { + MatchSummaryWidgets.Break{}, + HtmlWidgets.Div{css = {margin = 'auto'}, children = game.comment}, + } or {} + + return MatchSummaryWidgets.Row{ + classes = {'brkts-popup-body-game'}, + css = {['font-size'] = '80%', padding = '4px'}, + children = { + MatchSummaryWidgets.Characters{ + flipped = false, + characters = characterData[1], + bg = 'brkts-popup-side-color-' .. (extradata.team1side or ''), + date = date, + }, + MatchSummaryWidgets.GameWinLossIndicator{winner = game.winner, opponentIndex = 1}, + HtmlWidgets.Div{ + classes = {'brkts-popup-body-element-vertical-centered'}, + children = {Logic.isNotEmpty(game.length) and game.length or ('Game ' .. gameIndex)}, + }, + MatchSummaryWidgets.GameWinLossIndicator{winner = game.winner, opponentIndex = 2}, + MatchSummaryWidgets.Characters{ + flipped = true, + characters = characterData[2], + bg = 'brkts-popup-side-color-' .. (extradata.team2side or ''), + date = date, + }, + unpack(comment) + } + } end return CustomMatchSummary diff --git a/components/match2/wikis/leagueoflegends/match_summary.lua b/components/match2/wikis/leagueoflegends/match_summary.lua index 2aa88b95cf7..3be8d54fb21 100644 --- a/components/match2/wikis/leagueoflegends/match_summary.lua +++ b/components/match2/wikis/leagueoflegends/match_summary.lua @@ -8,22 +8,22 @@ local CustomMatchSummary = {} +local Array = require('Module:Array') local DateExt = require('Module:Date/Ext') -local Icon = require('Module:Icon') +local FnUtil = require('Module:FnUtil') local Logic = require('Module:Logic') local Lua = require('Module:Lua') local MatchLinks = mw.loadData('Module:MatchLinks') -local Table = require('Module:Table') -local MatchPage = Lua.import('Module:MatchPage') local DisplayHelper = Lua.import('Module:MatchGroup/Display/Helper') +local MatchPage = Lua.import('Module:MatchPage') local MatchSummary = Lua.import('Module:MatchSummary/Base') local MatchSummaryWidgets = Lua.import('Module:Widget/Match/Summary/All') +local WidgetUtil = Lua.import('Module:Widget/Util') +local HtmlWidgets = Lua.import('Module:Widget/Html/All') local MAX_NUM_BANS = 5 local NUM_HEROES_PICK = 5 -local GREEN_CHECK = Icon.makeIcon{iconName = 'winner', color = 'forest-green-text', size = '110%'} -local NO_CHECK = '[[File:NoCheck.png|link=]]' ---@param args table ---@return Html @@ -43,50 +43,28 @@ end ---@param match MatchGroupUtilMatch ---@return MatchSummaryBody function CustomMatchSummary.createBody(match) - local body = MatchSummary.Body() - - if match.dateIsExact or match.timestamp ~= DateExt.defaultTimestamp 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( - DisplayHelper.MatchCountdownBlock(match) - )) - end - - if MatchPage.isEnabledFor(match) then - body.root:node(MatchSummaryWidgets.MatchPageLink{matchId = match.extradata.originalmatchid or match.matchId}) - end - - -- Iterate each map - for gameIndex, game in ipairs(match.games) do - local rowDisplay = CustomMatchSummary._createGame(game, gameIndex, match.date) - body:addRow(rowDisplay) - end + -- Original Match Id must be used to match page links if it exists. + -- It can be different from the matchId when shortened brackets are used. + local matchId = match.extradata.originalmatchid or match.matchId - -- Add Match MVP(s) - if Table.isNotEmpty(match.extradata.mvp) then - body.root:node(MatchSummaryWidgets.Mvp{ - players = match.extradata.mvp.players, - points = match.extradata.mvp.points, - }) - end - - -- Add the Character Bans + local showCountdown = match.timestamp ~= DateExt.defaultTimestamp + local showMatchPage = MatchPage.isEnabledFor(match) local characterBansData = MatchSummary.buildCharacterBanData(match.games, MAX_NUM_BANS) - body.root:node(MatchSummaryWidgets.CharacterBanTable{ - bans = characterBansData, - date = match.date, - }) - return body + return MatchSummaryWidgets.Body{children = WidgetUtil.collect( + showCountdown and MatchSummaryWidgets.Row{children = DisplayHelper.MatchCountdownBlock(match)} or nil, + showMatchPage and MatchSummaryWidgets.MatchPageLink{matchId = matchId} or nil, + Array.map(match.games, FnUtil.curry(CustomMatchSummary._createGame, match.date)), + MatchSummaryWidgets.Mvp(match.extradata.mvp), + MatchSummaryWidgets.CharacterBanTable{bans = characterBansData, date = match.date} + )} end +---@param date string ---@param game MatchGroupUtilGame ---@param gameIndex integer ----@param date string ---@return MatchSummaryRow -function CustomMatchSummary._createGame(game, gameIndex, date) - local row = MatchSummary.Row() +function CustomMatchSummary._createGame(date, game, gameIndex) local extradata = game.extradata or {} -- TODO: Change to use participant data @@ -95,67 +73,37 @@ function CustomMatchSummary._createGame(game, gameIndex, date) MatchSummary.buildCharacterList(extradata, 'team2champion', NUM_HEROES_PICK), } - row:addClass('brkts-popup-body-game') - :css('font-size', '80%') - :css('padding', '4px') - :css('min-height', '32px') - - row:addElement(MatchSummaryWidgets.Characters{ - flipped = false, - date = date, - characters = characterData[1], - bg = 'brkts-popup-side-color-' .. (extradata.team1side or ''), - }) - row:addElement(CustomMatchSummary._createCheckMark(game.winner == 1)) - row:addElement(mw.html.create('div') - :addClass('brkts-popup-body-element-vertical-centered') - :wikitext(CustomMatchSummary._createAbbreviation{ - title = Logic.isEmpty(game.length) and ('Game ' .. gameIndex .. ' picks') or 'Match Length', - text = Logic.isEmpty(game.length) and ('Game ' .. gameIndex) or game.length, - }) - ) - row:addElement(CustomMatchSummary._createCheckMark(game.winner == 2)) - row:addElement(MatchSummaryWidgets.Characters{ - flipped = true, - date = date, - characters = characterData[2], - bg = 'brkts-popup-side-color-' .. (extradata.team2side or ''), - }) - - -- Add Comment - if not Logic.isEmpty(game.comment) then - row:addElement(MatchSummary.Break():create()) - local comment = mw.html.create('div') - comment:wikitext(game.comment) - :css('margin', 'auto') - row:addElement(comment) - end - - return row -end - ----@param isWinner boolean? ----@return Html -function CustomMatchSummary._createCheckMark(isWinner) - local container = mw.html.create('div') - :addClass('brkts-popup-body-element-vertical-centered') - :css('line-height', '17px') - :css('margin-left', '1%') - :css('margin-right', '1%') - - if Logic.readBool(isWinner) then - container:node(GREEN_CHECK) - else - container:node(NO_CHECK) - end - - return container -end - ----@param args table ----@return string -function CustomMatchSummary._createAbbreviation(args) - return '' .. args.text .. '' + -- Map Comment + local comment = Logic.isNotEmpty(game.comment) and { + MatchSummaryWidgets.Break{}, + HtmlWidgets.Div{css = {margin = 'auto'}, children = game.comment}, + } or {} + + return MatchSummaryWidgets.Row{ + classes = {'brkts-popup-body-game'}, + css = {['font-size'] = '80%', padding = '4px', ['min-height'] = '32px'}, + children = { + MatchSummaryWidgets.Characters{ + flipped = false, + characters = characterData[1], + bg = 'brkts-popup-side-color-' .. (extradata.team1side or ''), + date = date, + }, + MatchSummaryWidgets.GameWinLossIndicator{winner = game.winner, opponentIndex = 1}, + HtmlWidgets.Div{ + classes = {'brkts-popup-body-element-vertical-centered'}, + children = {Logic.isNotEmpty(game.length) and game.length or ('Game ' .. gameIndex)}, + }, + MatchSummaryWidgets.GameWinLossIndicator{winner = game.winner, opponentIndex = 2}, + MatchSummaryWidgets.Characters{ + flipped = true, + characters = characterData[2], + bg = 'brkts-popup-side-color-' .. (extradata.team2side or ''), + date = date, + }, + unpack(comment) + } + } end return CustomMatchSummary diff --git a/components/match2/wikis/mobilelegends/match_summary.lua b/components/match2/wikis/mobilelegends/match_summary.lua index 76d9af9c772..a69d48a202f 100644 --- a/components/match2/wikis/mobilelegends/match_summary.lua +++ b/components/match2/wikis/mobilelegends/match_summary.lua @@ -8,23 +8,23 @@ local CustomMatchSummary = {} +local Array = require('Module:Array') local DateExt = require('Module:Date/Ext') local DisplayHelper = require('Module:MatchGroup/Display/Helper') -local Icon = require('Module:Icon') +local ExternalLinks = require('Module:ExternalLinks') +local FnUtil = require('Module:FnUtil') local Logic = require('Module:Logic') local Lua = require('Module:Lua') local Table = require('Module:Table') -local ExternalLinks = require('Module:ExternalLinks') local MatchSummary = Lua.import('Module:MatchSummary/Base') local MatchSummaryWidgets = Lua.import('Module:Widget/Match/Summary/All') +local HtmlWidgets = Lua.import('Module:Widget/Html/All') +local WidgetUtil = Lua.import('Module:Widget/Util') local MAX_NUM_BANS = 5 local NUM_CHAMPIONS_PICK = 5 -local GREEN_CHECK = Icon.makeIcon{iconName = 'winner', color = 'forest-green-text', size = '110%'} -local NO_CHECK = '[[File:NoCheck.png|link=]]' - ---@param args table ---@return Html function CustomMatchSummary.getByMatchId(args) @@ -47,51 +47,24 @@ end ---@param match MatchGroupUtilMatch ---@return MatchSummaryBody function CustomMatchSummary.createBody(match) - local body = MatchSummary.Body() - - if match.dateIsExact or match.timestamp ~= DateExt.defaultTimestamp then - -- dateIsExact means we have both date and time. Show countdown - -- if match is not default date, we have a date, so display the date - body:addRow(MatchSummary.Row():addElement( - DisplayHelper.MatchCountdownBlock(match) - )) - end - - -- Iterate each map - for gameIndex, game in ipairs(match.games) do - local rowDisplay = CustomMatchSummary._createGame(game, gameIndex, match.date) - if rowDisplay then - body:addRow(rowDisplay) - end - end - - -- Add Match MVP(s) - if Table.isNotEmpty(match.extradata.mvp) then - body.root:node(MatchSummaryWidgets.Mvp{ - players = match.extradata.mvp.players, - points = match.extradata.mvp.points, - }) - end - - -- casters - body:addRow(MatchSummary.makeCastersRow(match.extradata.casters)) - - -- Add the Character Bans + local showCountdown = match.timestamp ~= DateExt.defaultTimestamp local characterBansData = MatchSummary.buildCharacterBanData(match.games, MAX_NUM_BANS) - body.root:node(MatchSummaryWidgets.CharacterBanTable{ - bans = characterBansData, - date = match.date, - }) - - return body + local casterRow = MatchSummary.makeCastersRow(match.extradata.casters) + + return MatchSummaryWidgets.Body{children = WidgetUtil.collect( + showCountdown and MatchSummaryWidgets.Row{children = DisplayHelper.MatchCountdownBlock(match)} or nil, + Array.map(match.games, FnUtil.curry(CustomMatchSummary._createGame, match.date)), + MatchSummaryWidgets.Mvp(match.extradata.mvp), + MatchSummaryWidgets.CharacterBanTable{bans = characterBansData, date = match.date}, + casterRow and casterRow:create() or nil + )} end +---@param date string ---@param game MatchGroupUtilGame ---@param gameIndex integer ----@param date string ---@return MatchSummaryRow? -function CustomMatchSummary._createGame(game, gameIndex, date) - local row = MatchSummary.Row() +function CustomMatchSummary._createGame(date, game, gameIndex) local extradata = game.extradata or {} -- TODO: Change to use participant data @@ -104,66 +77,37 @@ function CustomMatchSummary._createGame(game, gameIndex, date) return nil end - row :addClass('brkts-popup-body-game') - :css('font-size', '85%') - :css('overflow', 'hidden') - - row:addElement(MatchSummaryWidgets.Characters{ - flipped = false, - date = date, - characters = characterData[1], - bg = 'brkts-popup-side-color-' .. (extradata.team1side or ''), - }) - row:addElement(CustomMatchSummary._createCheckMark(game.winner == 1)) - row:addElement(mw.html.create('div') - :addClass('brkts-popup-body-element-vertical-centered') - :wikitext(CustomMatchSummary._createAbbreviation{ - title = Logic.isEmpty(game.length) and ('Game ' .. gameIndex .. ' picks') or 'Match Length', - text = Logic.isEmpty(game.length) and ('Game ' .. gameIndex) or game.length, - }) - ) - row:addElement(CustomMatchSummary._createCheckMark(game.winner == 2)) - row:addElement(MatchSummaryWidgets.Characters{ - flipped = true, - date = date, - characters = characterData[2], - bg = 'brkts-popup-side-color-' .. (extradata.team2side or ''), - }) - - -- Add Comment - if not Logic.isEmpty(game.comment) then - row:addElement(MatchSummary.Break():create()) - local comment = mw.html.create('div') - comment :wikitext(game.comment) - :css('margin', 'auto') - row:addElement(comment) - end - - return row -end - ----@param isWinner boolean? ----@return Html -function CustomMatchSummary._createCheckMark(isWinner) - local container = mw.html.create('div') - :addClass('brkts-popup-spaced') - :css('line-height', '27px') - :css('margin-left', '3%') - :css('margin-right', '3%') - - if isWinner then - container:node(GREEN_CHECK) - else - container:node(NO_CHECK) - end - - return container -end - ----@param args table ----@return string -function CustomMatchSummary._createAbbreviation(args) - return '' .. args.text .. '' + -- Map Comment + local comment = Logic.isNotEmpty(game.comment) and { + MatchSummaryWidgets.Break{}, + HtmlWidgets.Div{css = {margin = 'auto'}, children = game.comment}, + } or {} + + return MatchSummaryWidgets.Row{ + classes = {'brkts-popup-body-game'}, + css = {['font-size'] = '80%', padding = '4px'}, + children = { + MatchSummaryWidgets.Characters{ + flipped = false, + characters = characterData[1], + bg = 'brkts-popup-side-color-' .. (extradata.team1side or ''), + date = date, + }, + MatchSummaryWidgets.GameWinLossIndicator{winner = game.winner, opponentIndex = 1}, + HtmlWidgets.Div{ + classes = {'brkts-popup-body-element-vertical-centered'}, + children = {Logic.isNotEmpty(game.length) and game.length or ('Game ' .. gameIndex)}, + }, + MatchSummaryWidgets.GameWinLossIndicator{winner = game.winner, opponentIndex = 2}, + MatchSummaryWidgets.Characters{ + flipped = true, + characters = characterData[2], + bg = 'brkts-popup-side-color-' .. (extradata.team2side or ''), + date = date, + }, + unpack(comment) + } + } end return CustomMatchSummary diff --git a/components/match2/wikis/smite/match_summary.lua b/components/match2/wikis/smite/match_summary.lua index c06a6009a8c..6cb03fa76d5 100644 --- a/components/match2/wikis/smite/match_summary.lua +++ b/components/match2/wikis/smite/match_summary.lua @@ -8,20 +8,20 @@ local CustomMatchSummary = {} -local Abbreviation = require('Module:Abbreviation') +local Array = require('Module:Array') local DateExt = require('Module:Date/Ext') -local Icon = require('Module:Icon') +local FnUtil = require('Module:FnUtil') local Logic = require('Module:Logic') local Lua = require('Module:Lua') local DisplayHelper = Lua.import('Module:MatchGroup/Display/Helper') local MatchSummary = Lua.import('Module:MatchSummary/Base') local MatchSummaryWidgets = Lua.import('Module:Widget/Match/Summary/All') +local HtmlWidgets = Lua.import('Module:Widget/Html/All') +local WidgetUtil = Lua.import('Module:Widget/Util') local MAX_NUM_BANS = 5 local NUM_GODS_PICK = 5 -local GREEN_CHECK = Icon.makeIcon{iconName = 'winner', color = 'forest-green-text', size = '110%'} -local NO_CHECK = '[[File:NoCheck.png|link=]]' local LINK_DATA = { smiteesports = { @@ -38,42 +38,34 @@ function CustomMatchSummary.getByMatchId(args) return MatchSummary.defaultGetByMatchId(CustomMatchSummary, args, {width = '400px', teamStyle = 'bracket'}) end +---@param match MatchGroupUtilMatch +---@param footer MatchSummaryFooter +---@return MatchSummaryFooter +function CustomMatchSummary.addToFooter(match, footer) + footer = MatchSummary.addVodsToFooter(match, footer) + return footer:addLinks(LINK_DATA, match.links) +end + ---@param match MatchGroupUtilMatch ---@return MatchSummaryBody function CustomMatchSummary.createBody(match) - local body = MatchSummary.Body() - - if match.dateIsExact or match.timestamp ~= DateExt.defaultTimestamp then - body:addRow(MatchSummary.Row():addElement( - DisplayHelper.MatchCountdownBlock(match) - )) - end - - -- Iterate each map - for gameIndex, game in ipairs(match.games) do - local rowDisplay = CustomMatchSummary._createGame(game, gameIndex, match.date) - body:addRow(rowDisplay) - end - - -- casters - body:addRow(MatchSummary.makeCastersRow(match.extradata.casters)) - - -- Add the Character Bans + local showCountdown = match.timestamp ~= DateExt.defaultTimestamp local characterBansData = MatchSummary.buildCharacterBanData(match.games, MAX_NUM_BANS) - body.root:node(MatchSummaryWidgets.CharacterBanTable{ - bans = characterBansData, - date = match.date, - }) - - return body + local casterRow = MatchSummary.makeCastersRow(match.extradata.casters) + + return MatchSummaryWidgets.Body{children = WidgetUtil.collect( + showCountdown and MatchSummaryWidgets.Row{children = DisplayHelper.MatchCountdownBlock(match)} or nil, + Array.map(match.games, FnUtil.curry(CustomMatchSummary._createGame, match.date)), + MatchSummaryWidgets.CharacterBanTable{bans = characterBansData, date = match.date}, + casterRow and casterRow:create() or nil + )} end +---@param date string ---@param game MatchGroupUtilGame ---@param gameIndex integer ----@param date string ---@return MatchSummaryRow -function CustomMatchSummary._createGame(game, gameIndex, date) - local row = MatchSummary.Row() +function CustomMatchSummary._createGame(date, game, gameIndex) local extradata = game.extradata or {} -- TODO: Change to use participant data @@ -82,68 +74,36 @@ function CustomMatchSummary._createGame(game, gameIndex, date) MatchSummary.buildCharacterList(extradata, 'team2god', NUM_GODS_PICK), } - row:addClass('brkts-popup-body-game') - :css('font-size', '80%') - :css('padding', '4px') - :css('min-height', '32px') - - row:addElement(MatchSummaryWidgets.Characters{ - flipped = false, - characters = characterData[1], - date = date, - bg = 'brkts-popup-side-color-' .. (extradata.team1side or ''), - }) - row:addElement(CustomMatchSummary._createCheckMark(game.winner == 1)) - row:addElement(mw.html.create('div') - :addClass('brkts-popup-body-element-vertical-centered') - :wikitext(Abbreviation.make( - Logic.isEmpty(game.length) and ('Game ' .. gameIndex) or game.length, - Logic.isEmpty(game.length) and ('Game ' .. gameIndex .. ' picks') or 'Match Length' - )) - ) - row:addElement(CustomMatchSummary._createCheckMark(game.winner == 2)) - row:addElement(MatchSummaryWidgets.Characters{ - flipped = true, - characters = characterData[2], - date = date, - bg = 'brkts-popup-side-color-' .. (extradata.team2side or ''), - }) - - -- Add Comment - if not Logic.isEmpty(game.comment) then - row:addElement(MatchSummary.Break():create()) - local comment = mw.html.create('div') - comment:wikitext(game.comment):css('margin', 'auto') - row:addElement(comment) - end - - return row -end - ----@param isWinner boolean? ----@return Html -function CustomMatchSummary._createCheckMark(isWinner) - local container = mw.html.create('div') - :addClass('brkts-popup-body-element-vertical-centered') - :css('line-height', '17px') - :css('margin-left', '1%') - :css('margin-right', '1%') - - if Logic.readBool(isWinner) then - container:node(GREEN_CHECK) - else - container:node(NO_CHECK) - end - - return container -end - ----@param match MatchGroupUtilMatch ----@param footer MatchSummaryFooter ----@return MatchSummaryFooter -function CustomMatchSummary.addToFooter(match, footer) - footer = MatchSummary.addVodsToFooter(match, footer) - return footer:addLinks(LINK_DATA, match.links) + local comment = Logic.isNotEmpty(game.comment) and { + MatchSummaryWidgets.Break{}, + HtmlWidgets.Div{css = {margin = 'auto'}, children = game.comment}, + } or {} + + return MatchSummaryWidgets.Row{ + classes = {'brkts-popup-body-game'}, + css = {['font-size'] = '80%', padding = '4px'}, + children = { + MatchSummaryWidgets.Characters{ + flipped = false, + characters = characterData[1], + bg = 'brkts-popup-side-color-' .. (extradata.team1side or ''), + date = date, + }, + MatchSummaryWidgets.GameWinLossIndicator{winner = game.winner, opponentIndex = 1}, + HtmlWidgets.Div{ + classes = {'brkts-popup-body-element-vertical-centered'}, + children = {Logic.isNotEmpty(game.length) and game.length or ('Game ' .. gameIndex)}, + }, + MatchSummaryWidgets.GameWinLossIndicator{winner = game.winner, opponentIndex = 2}, + MatchSummaryWidgets.Characters{ + flipped = true, + characters = characterData[2], + bg = 'brkts-popup-side-color-' .. (extradata.team2side or ''), + date = date, + }, + unpack(comment) + } + } end return CustomMatchSummary diff --git a/components/match2/wikis/wildrift/match_summary.lua b/components/match2/wikis/wildrift/match_summary.lua index 676e1144051..3735df9fb21 100644 --- a/components/match2/wikis/wildrift/match_summary.lua +++ b/components/match2/wikis/wildrift/match_summary.lua @@ -8,8 +8,8 @@ local CustomMatchSummary = {} +local Array = require('Module:Array') local DateExt = require('Module:Date/Ext') -local Icon = require('Module:Icon') local Logic = require('Module:Logic') local Lua = require('Module:Lua') local Table = require('Module:Table') @@ -18,13 +18,12 @@ local ExternalLinks = require('Module:ExternalLinks') local DisplayHelper = Lua.import('Module:MatchGroup/Display/Helper') local MatchSummary = Lua.import('Module:MatchSummary/Base') local MatchSummaryWidgets = Lua.import('Module:Widget/Match/Summary/All') +local HtmlWidgets = Lua.import('Module:Widget/Html/All') +local WidgetUtil = Lua.import('Module:Widget/Util') local MAX_NUM_BANS = 5 local NUM_CHAMPIONS_PICK = 5 -local GREEN_CHECK = Icon.makeIcon{iconName = 'winner', color = 'forest-green-text', size = '110%'} -local NO_CHECK = '[[File:NoCheck.png|link=]]' - ---@param args table ---@return Html function CustomMatchSummary.getByMatchId(args) @@ -47,47 +46,21 @@ end ---@param match MatchGroupUtilMatch ---@return MatchSummaryBody function CustomMatchSummary.createBody(match) - local body = MatchSummary.Body() - - if match.dateIsExact or match.timestamp ~= DateExt.defaultTimestamp then - -- dateIsExact means we have both date and time. Show countdown - -- if match is not default date, we have a date, so display the date - body:addRow(MatchSummary.Row():addElement( - DisplayHelper.MatchCountdownBlock(match) - )) - end - - -- Iterate each map - for gameIndex, game in ipairs(match.games) do - local rowDisplay = CustomMatchSummary._createGame(game, gameIndex) - if rowDisplay then - body:addRow(rowDisplay) - end - end - - -- Add Match MVP(s) - if Table.isNotEmpty(match.extradata.mvp) then - body.root:node(MatchSummaryWidgets.Mvp{ - players = match.extradata.mvp.players, - points = match.extradata.mvp.points, - }) - end - - -- Add the Character Bans + local showCountdown = match.timestamp ~= DateExt.defaultTimestamp local characterBansData = MatchSummary.buildCharacterBanData(match.games, MAX_NUM_BANS) - body.root:node(MatchSummaryWidgets.CharacterBanTable{ - bans = characterBansData, - date = match.date, - }) - return body + return MatchSummaryWidgets.Body{children = WidgetUtil.collect( + showCountdown and MatchSummaryWidgets.Row{children = DisplayHelper.MatchCountdownBlock(match)} or nil, + Array.map(match.games, CustomMatchSummary._createGame), + MatchSummaryWidgets.Mvp(match.extradata.mvp), + MatchSummaryWidgets.CharacterBanTable{bans = characterBansData, date = match.date} + )} end ---@param game MatchGroupUtilGame ---@param gameIndex integer ---@return MatchSummaryRow? function CustomMatchSummary._createGame(game, gameIndex) - local row = MatchSummary.Row() local extradata = game.extradata or {} -- TODO: Change to use participant data @@ -100,64 +73,35 @@ function CustomMatchSummary._createGame(game, gameIndex) return nil end - row :addClass('brkts-popup-body-game') - :css('font-size', '85%') - :css('overflow', 'hidden') - - row:addElement(MatchSummaryWidgets.Characters{ - flipped = false, - characters = characterData[1], - bg = 'brkts-popup-side-color-' .. (extradata.team1side or ''), - }) - row:addElement(CustomMatchSummary._createCheckMark(game.winner == 1)) - row:addElement(mw.html.create('div') - :addClass('brkts-popup-body-element-vertical-centered') - :wikitext(CustomMatchSummary._createAbbreviation{ - title = Logic.isEmpty(game.length) and ('Game ' .. gameIndex .. ' picks') or 'Match Length', - text = Logic.isEmpty(game.length) and ('Game ' .. gameIndex) or game.length, - }) - ) - row:addElement(CustomMatchSummary._createCheckMark(game.winner == 2)) - row:addElement(MatchSummaryWidgets.Characters{ - flipped = true, - characters = characterData[2], - bg = 'brkts-popup-side-color-' .. (extradata.team2side or ''), - }) - - -- Add Comment - if not Logic.isEmpty(game.comment) then - row:addElement(MatchSummary.Break():create()) - local comment = mw.html.create('div') - comment :wikitext(game.comment) - :css('margin', 'auto') - row:addElement(comment) - end - - return row -end - ----@param isWinner boolean? ----@return Html -function CustomMatchSummary._createCheckMark(isWinner) - local container = mw.html.create('div') - :addClass('brkts-popup-spaced') - :css('line-height', '27px') - :css('margin-left', '3%') - :css('margin-right', '3%') - - if isWinner then - container:node(GREEN_CHECK) - else - container:node(NO_CHECK) - end - - return container -end - ----@param args table ----@return string -function CustomMatchSummary._createAbbreviation(args) - return '' .. args.text .. '' + -- Map Comment + local comment = Logic.isNotEmpty(game.comment) and { + MatchSummaryWidgets.Break{}, + HtmlWidgets.Div{css = {margin = 'auto'}, children = game.comment}, + } or {} + + return MatchSummaryWidgets.Row{ + classes = {'brkts-popup-body-game'}, + css = {['font-size'] = '80%', padding = '4px'}, + children = { + MatchSummaryWidgets.Characters{ + flipped = false, + characters = characterData[1], + bg = 'brkts-popup-side-color-' .. (extradata.team1side or ''), + }, + MatchSummaryWidgets.GameWinLossIndicator{winner = game.winner, opponentIndex = 1}, + HtmlWidgets.Div{ + classes = {'brkts-popup-body-element-vertical-centered'}, + children = {Logic.isNotEmpty(game.length) and game.length or ('Game ' .. gameIndex)}, + }, + MatchSummaryWidgets.GameWinLossIndicator{winner = game.winner, opponentIndex = 2}, + MatchSummaryWidgets.Characters{ + flipped = true, + characters = characterData[2], + bg = 'brkts-popup-side-color-' .. (extradata.team2side or ''), + }, + unpack(comment) + } + } end return CustomMatchSummary diff --git a/components/widget/match/summary/widget_match_summary_game_winloss_indicator.lua b/components/widget/match/summary/widget_match_summary_game_winloss_indicator.lua index 2e19a5b6264..2e846ad4ded 100644 --- a/components/widget/match/summary/widget_match_summary_game_winloss_indicator.lua +++ b/components/widget/match/summary/widget_match_summary_game_winloss_indicator.lua @@ -44,6 +44,7 @@ function MatchSummaryGameWinLossIndicator:render() return Div{ classes = {'brkts-popup-spaced'}, css = { + ['width'] = '16px', ['line-height'] = '17px', ['margin-left'] = '1%', ['margin-right'] = '1%',