From b13fb7b5329cbcb5ced988216cf5b12a6c3da3aa Mon Sep 17 00:00:00 2001 From: Rikard Blixt Date: Mon, 21 Oct 2024 16:23:37 +0200 Subject: [PATCH 1/5] refactor(match2): MatchSummary on some mobas --- .../wikis/honorofkings/match_summary.lua | 144 +++++------------ .../wikis/leagueoflegends/match_summary.lua | 152 ++++++------------ .../wikis/mobilelegends/match_summary.lua | 149 ++++++----------- .../match2/wikis/smite/match_summary.lua | 143 ++++++---------- .../match2/wikis/wildrift/match_summary.lua | 134 +++++---------- 5 files changed, 230 insertions(+), 492 deletions(-) diff --git a/components/match2/wikis/honorofkings/match_summary.lua b/components/match2/wikis/honorofkings/match_summary.lua index 72877c8fb7b..16d37aac0e7 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, + unpack(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..faec56ca595 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, + unpack(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'}, + 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..e1098302c73 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,23 @@ 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 + return MatchSummaryWidgets.Body{children = WidgetUtil.collect( + showCountdown and MatchSummaryWidgets.Row{children = DisplayHelper.MatchCountdownBlock(match)} or nil, + unpack(Array.map(match.games, FnUtil.curry(CustomMatchSummary._createGame, match.date))), + MatchSummaryWidgets.Mvp(match.extradata.mvp), + MatchSummaryWidgets.CharacterBanTable{bans = characterBansData, date = match.date}, + MatchSummary.makeCastersRow(match.extradata.casters) + )} 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 +76,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..b685ad2bac0 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,33 @@ 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 + return MatchSummaryWidgets.Body{children = WidgetUtil.collect( + showCountdown and MatchSummaryWidgets.Row{children = DisplayHelper.MatchCountdownBlock(match)} or nil, + unpack(Array.map(match.games, FnUtil.curry(CustomMatchSummary._createGame, match.date))), + MatchSummaryWidgets.CharacterBanTable{bans = characterBansData, date = match.date}, + MatchSummary.makeCastersRow(match.extradata.casters) + )} 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 +73,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..e78573ac9bf 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, + unpack(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 From 9c2d2abe09c11cacaf60eea91c5e5f871f618edf Mon Sep 17 00:00:00 2001 From: Rikard Blixt Date: Mon, 21 Oct 2024 16:24:49 +0200 Subject: [PATCH 2/5] fix --- components/match2/wikis/mobilelegends/match_summary.lua | 2 +- components/match2/wikis/smite/match_summary.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/components/match2/wikis/mobilelegends/match_summary.lua b/components/match2/wikis/mobilelegends/match_summary.lua index e1098302c73..0026b297e27 100644 --- a/components/match2/wikis/mobilelegends/match_summary.lua +++ b/components/match2/wikis/mobilelegends/match_summary.lua @@ -55,7 +55,7 @@ function CustomMatchSummary.createBody(match) unpack(Array.map(match.games, FnUtil.curry(CustomMatchSummary._createGame, match.date))), MatchSummaryWidgets.Mvp(match.extradata.mvp), MatchSummaryWidgets.CharacterBanTable{bans = characterBansData, date = match.date}, - MatchSummary.makeCastersRow(match.extradata.casters) + MatchSummary.makeCastersRow(match.extradata.casters):create() )} end diff --git a/components/match2/wikis/smite/match_summary.lua b/components/match2/wikis/smite/match_summary.lua index b685ad2bac0..97dc6ec19d6 100644 --- a/components/match2/wikis/smite/match_summary.lua +++ b/components/match2/wikis/smite/match_summary.lua @@ -56,7 +56,7 @@ function CustomMatchSummary.createBody(match) showCountdown and MatchSummaryWidgets.Row{children = DisplayHelper.MatchCountdownBlock(match)} or nil, unpack(Array.map(match.games, FnUtil.curry(CustomMatchSummary._createGame, match.date))), MatchSummaryWidgets.CharacterBanTable{bans = characterBansData, date = match.date}, - MatchSummary.makeCastersRow(match.extradata.casters) + MatchSummary.makeCastersRow(match.extradata.casters):create() )} end From 4cbf7a32d4330233fa2bccc4cb6cc127d9ef4af7 Mon Sep 17 00:00:00 2001 From: Rikard Blixt Date: Mon, 21 Oct 2024 16:32:33 +0200 Subject: [PATCH 3/5] fix --- components/match2/wikis/mobilelegends/match_summary.lua | 3 ++- components/match2/wikis/smite/match_summary.lua | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/components/match2/wikis/mobilelegends/match_summary.lua b/components/match2/wikis/mobilelegends/match_summary.lua index 0026b297e27..65995c1cd91 100644 --- a/components/match2/wikis/mobilelegends/match_summary.lua +++ b/components/match2/wikis/mobilelegends/match_summary.lua @@ -49,13 +49,14 @@ end function CustomMatchSummary.createBody(match) local showCountdown = match.timestamp ~= DateExt.defaultTimestamp local characterBansData = MatchSummary.buildCharacterBanData(match.games, MAX_NUM_BANS) + local casterRow = MatchSummary.makeCastersRow(match.extradata.casters) return MatchSummaryWidgets.Body{children = WidgetUtil.collect( showCountdown and MatchSummaryWidgets.Row{children = DisplayHelper.MatchCountdownBlock(match)} or nil, unpack(Array.map(match.games, FnUtil.curry(CustomMatchSummary._createGame, match.date))), MatchSummaryWidgets.Mvp(match.extradata.mvp), MatchSummaryWidgets.CharacterBanTable{bans = characterBansData, date = match.date}, - MatchSummary.makeCastersRow(match.extradata.casters):create() + casterRow and casterRow:create() or nil )} end diff --git a/components/match2/wikis/smite/match_summary.lua b/components/match2/wikis/smite/match_summary.lua index 97dc6ec19d6..1c3f01d8593 100644 --- a/components/match2/wikis/smite/match_summary.lua +++ b/components/match2/wikis/smite/match_summary.lua @@ -51,12 +51,13 @@ end function CustomMatchSummary.createBody(match) local showCountdown = match.timestamp ~= DateExt.defaultTimestamp local characterBansData = MatchSummary.buildCharacterBanData(match.games, MAX_NUM_BANS) + local casterRow = MatchSummary.makeCastersRow(match.extradata.casters) return MatchSummaryWidgets.Body{children = WidgetUtil.collect( showCountdown and MatchSummaryWidgets.Row{children = DisplayHelper.MatchCountdownBlock(match)} or nil, unpack(Array.map(match.games, FnUtil.curry(CustomMatchSummary._createGame, match.date))), MatchSummaryWidgets.CharacterBanTable{bans = characterBansData, date = match.date}, - MatchSummary.makeCastersRow(match.extradata.casters):create() + casterRow and casterRow:create() or nil )} end From feea8a8fa3e2b61809191fbc8c9a5c6f33a30263 Mon Sep 17 00:00:00 2001 From: Rikard Blixt Date: Tue, 22 Oct 2024 11:20:07 +0200 Subject: [PATCH 4/5] remove unneeded unpack --- components/match2/wikis/dota2/match_summary.lua | 2 +- components/match2/wikis/honorofkings/match_summary.lua | 2 +- components/match2/wikis/leagueoflegends/match_summary.lua | 4 ++-- components/match2/wikis/mobilelegends/match_summary.lua | 2 +- components/match2/wikis/smite/match_summary.lua | 2 +- components/match2/wikis/wildrift/match_summary.lua | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) 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 16d37aac0e7..1e4c1e735a7 100644 --- a/components/match2/wikis/honorofkings/match_summary.lua +++ b/components/match2/wikis/honorofkings/match_summary.lua @@ -52,7 +52,7 @@ function CustomMatchSummary.createBody(match) return MatchSummaryWidgets.Body{children = WidgetUtil.collect( showCountdown and MatchSummaryWidgets.Row{children = DisplayHelper.MatchCountdownBlock(match)} or nil, - unpack(Array.map(match.games, FnUtil.curry(CustomMatchSummary._createGame, match.date))), + Array.map(match.games, FnUtil.curry(CustomMatchSummary._createGame, match.date)), MatchSummaryWidgets.Mvp(match.extradata.mvp), MatchSummaryWidgets.CharacterBanTable{bans = characterBansData, date = match.date} )} diff --git a/components/match2/wikis/leagueoflegends/match_summary.lua b/components/match2/wikis/leagueoflegends/match_summary.lua index faec56ca595..3be8d54fb21 100644 --- a/components/match2/wikis/leagueoflegends/match_summary.lua +++ b/components/match2/wikis/leagueoflegends/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, FnUtil.curry(CustomMatchSummary._createGame, match.date))), + Array.map(match.games, FnUtil.curry(CustomMatchSummary._createGame, match.date)), MatchSummaryWidgets.Mvp(match.extradata.mvp), MatchSummaryWidgets.CharacterBanTable{bans = characterBansData, date = match.date} )} @@ -81,7 +81,7 @@ function CustomMatchSummary._createGame(date, game, gameIndex) return MatchSummaryWidgets.Row{ classes = {'brkts-popup-body-game'}, - css = {['font-size'] = '80%', padding = '4px'}, + css = {['font-size'] = '80%', padding = '4px', ['min-height'] = '32px'}, children = { MatchSummaryWidgets.Characters{ flipped = false, diff --git a/components/match2/wikis/mobilelegends/match_summary.lua b/components/match2/wikis/mobilelegends/match_summary.lua index 65995c1cd91..a69d48a202f 100644 --- a/components/match2/wikis/mobilelegends/match_summary.lua +++ b/components/match2/wikis/mobilelegends/match_summary.lua @@ -53,7 +53,7 @@ function CustomMatchSummary.createBody(match) return MatchSummaryWidgets.Body{children = WidgetUtil.collect( showCountdown and MatchSummaryWidgets.Row{children = DisplayHelper.MatchCountdownBlock(match)} or nil, - unpack(Array.map(match.games, FnUtil.curry(CustomMatchSummary._createGame, match.date))), + 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 diff --git a/components/match2/wikis/smite/match_summary.lua b/components/match2/wikis/smite/match_summary.lua index 1c3f01d8593..6cb03fa76d5 100644 --- a/components/match2/wikis/smite/match_summary.lua +++ b/components/match2/wikis/smite/match_summary.lua @@ -55,7 +55,7 @@ function CustomMatchSummary.createBody(match) return MatchSummaryWidgets.Body{children = WidgetUtil.collect( showCountdown and MatchSummaryWidgets.Row{children = DisplayHelper.MatchCountdownBlock(match)} or nil, - unpack(Array.map(match.games, FnUtil.curry(CustomMatchSummary._createGame, match.date))), + Array.map(match.games, FnUtil.curry(CustomMatchSummary._createGame, match.date)), MatchSummaryWidgets.CharacterBanTable{bans = characterBansData, date = match.date}, casterRow and casterRow:create() or nil )} diff --git a/components/match2/wikis/wildrift/match_summary.lua b/components/match2/wikis/wildrift/match_summary.lua index e78573ac9bf..3735df9fb21 100644 --- a/components/match2/wikis/wildrift/match_summary.lua +++ b/components/match2/wikis/wildrift/match_summary.lua @@ -51,7 +51,7 @@ function CustomMatchSummary.createBody(match) return MatchSummaryWidgets.Body{children = WidgetUtil.collect( showCountdown and MatchSummaryWidgets.Row{children = DisplayHelper.MatchCountdownBlock(match)} 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} )} From 5306efab148e6cdd7d0ce73b3206f4ba27d3c9e9 Mon Sep 17 00:00:00 2001 From: Rikard Blixt Date: Tue, 22 Oct 2024 11:21:53 +0200 Subject: [PATCH 5/5] fix misalignment due to different icons having different widths --- .../summary/widget_match_summary_game_winloss_indicator.lua | 1 + 1 file changed, 1 insertion(+) 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%',