From e6a104e2cc222ac61d906df516f8ac419d458822 Mon Sep 17 00:00:00 2001 From: Rikard Blixt Date: Wed, 23 Oct 2024 16:17:50 +0200 Subject: [PATCH] refactor(match2): standardize match comments (#4956) * refactor(match2): match comments * Update components/widget/match/summary/widget_match_summary_all.lua Co-authored-by: hjpalpha <75081997+hjpalpha@users.noreply.github.com> * spelling is good * style typo * update smokes, order of inline-css can change when transitining to widget --------- Co-authored-by: hjpalpha <75081997+hjpalpha@users.noreply.github.com> --- .../match2/commons/match_summary_base.lua | 56 ++++--------------- .../wikis/counterstrike/match_summary.lua | 32 ++--------- .../criticalops/match_group_input_custom.lua | 1 - .../wikis/criticalops/match_summary.lua | 32 ----------- .../wikis/zula/match_group_input_custom.lua | 1 - .../match2/wikis/zula/match_summary.lua | 32 ----------- .../summary/widget_match_summary_all.lua | 1 + ...match_summary_game_win_loss_indicator.lua} | 0 .../widget_match_summary_match_comment.lua | 37 ++++++++++++ .../match2_matchlist_smoke_counterstrike.txt | 2 +- .../match2_matchlist_smoke_dota2.txt | 2 +- ...match2_matchlist_smoke_leagueoflegends.txt | 2 +- .../match2_matchlist_smoke_mobilelegends.txt | 2 +- .../match2_matchlist_smoke_overwatch.txt | 2 +- .../match2_matchlist_smoke_rainbowsix.txt | 2 +- .../match2_matchlist_smoke_rocketleague.txt | 2 +- .../match2_matchlist_smoke_starcraft2.txt | 2 +- .../match2_matchlist_smoke_valorant.txt | 2 +- 18 files changed, 63 insertions(+), 147 deletions(-) rename components/widget/match/summary/{widget_match_summary_game_winloss_indicator.lua => widget_match_summary_game_win_loss_indicator.lua} (100%) create mode 100644 components/widget/match/summary/widget_match_summary_match_comment.lua diff --git a/components/match2/commons/match_summary_base.lua b/components/match2/commons/match_summary_base.lua index 8363a66e29d..fe4e98117d5 100644 --- a/components/match2/commons/match_summary_base.lua +++ b/components/match2/commons/match_summary_base.lua @@ -19,6 +19,8 @@ local VodLink = require('Module:VodLink') local MatchGroupUtil = Lua.import('Module:MatchGroup/Util') local Links = Lua.import('Module:Links') +local MatchSummaryWidgets = Lua.import('Module:Widget/Match/Summary/All') +local WidgetUtil = Lua.import('Module:Widget/Util') local OpponentLibraries = require('Module:OpponentLibraries') local Opponent = OpponentLibraries.Opponent @@ -230,31 +232,6 @@ function Body:create() return self.root end ----@class MatchSummaryComment ----@operator call: MatchSummaryComment ----@field root Html -local Comment = Class.new( - function(self) - self.root = mw.html.create('div') - :addClass('brkts-popup-comment') - :css('white-space', 'normal') - :css('font-size', '85%') - end -) - ----@param content Html|string|number|nil ----@return MatchSummaryComment -function Comment:content(content) - if Logic.isEmpty(content) then return self end - self.root:node(content):node(Break():create()) - return self -end - ----@return Html -function Comment:create() - return self.root -end - ---@class MatchSummaryFooter ---@operator call: MatchSummaryFooter ---@field root Html @@ -333,7 +310,7 @@ end ---@field root Html ---@field headerElement Html? ---@field bodyElement Widget|Html? ----@field commentElement Html? +---@field commentElement Widget? ---@field footerElement Html? local Match = Class.new( function(self) @@ -361,10 +338,10 @@ function Match:body(body) return self end ----@param comment MatchSummaryComment +---@param comment Widget ---@return MatchSummaryMatch function Match:comment(comment) - self.commentElement = comment:create() + self.commentElement = comment return self end @@ -382,16 +359,9 @@ function Match:create() :node(Break():create()) :node(self.bodyElement) :node(Break():create()) - - if self.commentElement ~= nil then - self.root - :node(self.commentElement) - :node(Break():create()) - end - - if self.footerElement ~= nil then - self.root:node(self.footerElement) - end + :node(self.commentElement) + :node(Break():create()) + :node(self.footerElement) return self.root end @@ -535,7 +505,6 @@ end ---@operator call(string?):MatchSummary ---@field Header MatchSummaryHeader ---@field Body MatchSummaryBody ----@field Comment MatchSummaryComment ---@field Row MatchSummaryRow ---@field Footer MatchSummaryFooter ---@field Break MatchSummaryBreak @@ -548,7 +517,6 @@ end local MatchSummary = Class.new() MatchSummary.Header = Header MatchSummary.Body = Body -MatchSummary.Comment = Comment MatchSummary.Row = Row MatchSummary.Footer = Footer MatchSummary.Break = Break @@ -725,10 +693,10 @@ function MatchSummary.createMatch(matchData, CustomMatchSummary, options) local substituteComment = MatchSummary.createSubstitutesComment(matchData) - if matchData.comment or substituteComment then - local comment = MatchSummary.Comment():content(matchData.comment):content(substituteComment) - match:comment(comment) - end + match:comment(MatchSummaryWidgets.MatchComment{ + children = WidgetUtil.collect(matchData.comment, substituteComment) + }) + local createFooter = CustomMatchSummary.addToFooter or MatchSummary.createDefaultFooter match:footer(createFooter(matchData, MatchSummary.Footer())) diff --git a/components/match2/wikis/counterstrike/match_summary.lua b/components/match2/wikis/counterstrike/match_summary.lua index c6bd5e22267..4e0189fa5c0 100644 --- a/components/match2/wikis/counterstrike/match_summary.lua +++ b/components/match2/wikis/counterstrike/match_summary.lua @@ -18,6 +18,7 @@ local VodLink = require('Module:VodLink') 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 GREEN_CHECK = Icon.makeIcon{iconName = 'winner', color = 'forest-green-text', size = '110%'} local NO_CHECK = '[[File:NoCheck.png|link=]]' @@ -118,31 +119,6 @@ function MapVeto:displayMap(map) return Logic.nilIfEmpty(CustomMatchSummary._createMapLink(map, self.game)) or TBD end ----@class CounterstrikeMatchStatus: MatchSummaryRowInterface ----@operator call: CounterstrikeMatchStatus ----@field root Html -local MatchStatus = Class.new( - function(self) - self.root = mw.html.create('div') - self.root - :addClass('brkts-popup-comment') - :css('white-space', 'normal') - :css('font-size', '85%') - end -) - ----@param content string|number|Html|nil ----@return self -function MatchStatus:content(content) - self.root:node(content):node(MatchSummary.Break():create()) - return self -end - ----@return Html -function MatchStatus:create() - return self.root -end - ---@param args table ---@return Html function CustomMatchSummary.getByMatchId(args) @@ -201,9 +177,9 @@ function CustomMatchSummary.createBody(match) -- Match Status (postponed/ cancel(l)ed) if match.extradata.status then - local matchStatus = MatchStatus() - matchStatus:content('Match ' .. mw.getContentLanguage():ucfirst(match.extradata.status) .. '') - body:addRow(matchStatus) + body.root:node(MatchSummaryWidgets.MatchComment{ + children = 'Match ' .. mw.getContentLanguage():ucfirst(match.extradata.status) .. '' + }) end return body diff --git a/components/match2/wikis/criticalops/match_group_input_custom.lua b/components/match2/wikis/criticalops/match_group_input_custom.lua index 2166274e046..3f6af9bab10 100644 --- a/components/match2/wikis/criticalops/match_group_input_custom.lua +++ b/components/match2/wikis/criticalops/match_group_input_custom.lua @@ -148,7 +148,6 @@ end function MatchFunctions.getExtraData(match) return { mapveto = MatchGroupInputUtil.getMapVeto(match), - status = match.resulttype == MatchGroupInputUtil.RESULT_TYPE.NOT_PLAYED and match.status or nil, } end diff --git a/components/match2/wikis/criticalops/match_summary.lua b/components/match2/wikis/criticalops/match_summary.lua index 1a49c17ef0f..92fdd912f3b 100644 --- a/components/match2/wikis/criticalops/match_summary.lua +++ b/components/match2/wikis/criticalops/match_summary.lua @@ -98,31 +98,6 @@ function Score:create() return self.root end ----@class CriticalopsMatchStatus: MatchSummaryRowInterface ----@operator call: CriticalopsMatchStatus ----@field root Html -local MatchStatus = Class.new( - function(self) - self.root = mw.html.create('div') - self.root - :addClass('brkts-popup-comment') - :css('white-space', 'normal') - :css('font-size', '85%') - end -) - ----@param content Html|string|number|nil ----@return CriticalopsMatchStatus -function MatchStatus:content(content) - self.root:node(content):node(MatchSummary.Break():create()) - return self -end - ----@return Html -function MatchStatus:create() - return self.root -end - local CustomMatchSummary = {} ---@param args table @@ -155,13 +130,6 @@ function CustomMatchSummary.createBody(match) -- Add the Map Vetoes body:addRow(MatchSummary.defaultMapVetoDisplay(match)) - -- Match Status (postponed/ cancel(l)ed) - if match.extradata.status then - local matchStatus = MatchStatus() - matchStatus:content('Match ' .. mw.getContentLanguage():ucfirst(match.extradata.status) .. '') - body:addRow(matchStatus) - end - return body end diff --git a/components/match2/wikis/zula/match_group_input_custom.lua b/components/match2/wikis/zula/match_group_input_custom.lua index 340a8b109b4..f4301402dad 100644 --- a/components/match2/wikis/zula/match_group_input_custom.lua +++ b/components/match2/wikis/zula/match_group_input_custom.lua @@ -142,7 +142,6 @@ end ---@return table function MatchFunctions.getExtraData(match) return { - status = match.resulttype == MatchGroupInputUtil.RESULT_TYPE.NOT_PLAYED and match.status or nil, mapveto = MatchGroupInputUtil.getMapVeto(match), } end diff --git a/components/match2/wikis/zula/match_summary.lua b/components/match2/wikis/zula/match_summary.lua index 2dd3a4fdd45..fdfc9f41a98 100644 --- a/components/match2/wikis/zula/match_summary.lua +++ b/components/match2/wikis/zula/match_summary.lua @@ -98,31 +98,6 @@ function Score:create() return self.root end ----@class ZulaMatchStatus: MatchSummaryRowInterface ----@operator call: ZulaMatchStatus ----@field root Html -local MatchStatus = Class.new( - function(self) - self.root = mw.html.create('div') - self.root - :addClass('brkts-popup-comment') - :css('white-space', 'normal') - :css('font-size', '85%') - end -) - ----@param content Html|string|number|nil ----@return ZulaMatchStatus -function MatchStatus:content(content) - self.root:node(content):node(MatchSummary.Break():create()) - return self -end - ----@return Html -function MatchStatus:create() - return self.root -end - local CustomMatchSummary = {} ---@param args table @@ -155,13 +130,6 @@ function CustomMatchSummary.createBody(match) -- Add the Map Vetoes body:addRow(MatchSummary.defaultMapVetoDisplay(match)) - -- Match Status (postponed/ cancel(l)ed) - if match.extradata.status then - local matchStatus = MatchStatus() - matchStatus:content('Match ' .. mw.getContentLanguage():ucfirst(match.extradata.status) .. '') - body:addRow(matchStatus) - end - return body end diff --git a/components/widget/match/summary/widget_match_summary_all.lua b/components/widget/match/summary/widget_match_summary_all.lua index 082b8c4dd6c..f6008801092 100644 --- a/components/widget/match/summary/widget_match_summary_all.lua +++ b/components/widget/match/summary/widget_match_summary_all.lua @@ -19,6 +19,7 @@ Widgets.Character = Lua.import('Module:Widget/Match/Summary/Character') Widgets.GameCenter = Lua.import('Module:Widget/Match/Summary/GameCenter') Widgets.GameComment = Lua.import('Module:Widget/Match/Summary/GameComment') Widgets.GameWinLossIndicator = Lua.import('Module:Widget/Match/Summary/GameWinLossIndicator') +Widgets.MatchComment = Lua.import('Module:Widget/Match/Summary/MatchComment') Widgets.MatchPageLink = Lua.import('Module:Widget/Match/Summary/MatchPageLink') Widgets.Mvp = Lua.import('Module:Widget/Match/Summary/Mvp') Widgets.Row = Lua.import('Module:Widget/Match/Summary/Row') diff --git a/components/widget/match/summary/widget_match_summary_game_winloss_indicator.lua b/components/widget/match/summary/widget_match_summary_game_win_loss_indicator.lua similarity index 100% rename from components/widget/match/summary/widget_match_summary_game_winloss_indicator.lua rename to components/widget/match/summary/widget_match_summary_game_win_loss_indicator.lua diff --git a/components/widget/match/summary/widget_match_summary_match_comment.lua b/components/widget/match/summary/widget_match_summary_match_comment.lua new file mode 100644 index 00000000000..1c8b58c3e21 --- /dev/null +++ b/components/widget/match/summary/widget_match_summary_match_comment.lua @@ -0,0 +1,37 @@ +--- +-- @Liquipedia +-- wiki=commons +-- page=Module:Widget/Match/Summary/MatchComment +-- +-- Please see https://github.com/Liquipedia/Lua-Modules to contribute +-- + +local Array = require('Module:Array') +local Class = require('Module:Class') +local Logic = require('Module:Logic') +local Lua = require('Module:Lua') + +local Widget = Lua.import('Module:Widget') +local HtmlWidgets = Lua.import('Module:Widget/Html/All') +local Break = Lua.import('Module:Widget/Match/Summary/Break') + +---@class MatchSummaryMatchMatchComment: Widget +---@operator call(table): MatchSummaryMatchMatchComment +local MatchSummaryMatchMatchComment = Class.new(Widget) + +---@return Widget? +function MatchSummaryMatchMatchComment:render() + if Logic.isEmpty(self.props.children) then + return + end + + return HtmlWidgets.Div{ + classes = {'brkts-popup-comment'}, + css = {['font-size'] = '85%', ['white-space'] = 'normal'}, + children = Array.flatMap(self.props.children, function (child) + return {child, Break{}} + end) + } +end + +return MatchSummaryMatchMatchComment diff --git a/spec/golden_masters/match2_matchlist_smoke_counterstrike.txt b/spec/golden_masters/match2_matchlist_smoke_counterstrike.txt index 5f5d4ee0c96..27050d068ed 100644 --- a/spec/golden_masters/match2_matchlist_smoke_counterstrike.txt +++ b/spec/golden_masters/match2_matchlist_smoke_counterstrike.txt @@ -1 +1 @@ -
Match List
A
3
2
B
[[abc|A]]
3
2
[[B|B]]
A Match Comment
\ No newline at end of file +
Match List
A
3
2
B
[[abc|A]]
3
2
[[B|B]]
A Match Comment
\ No newline at end of file diff --git a/spec/golden_masters/match2_matchlist_smoke_dota2.txt b/spec/golden_masters/match2_matchlist_smoke_dota2.txt index 79ec22c3708..daba4ee09f1 100644 --- a/spec/golden_masters/match2_matchlist_smoke_dota2.txt +++ b/spec/golden_masters/match2_matchlist_smoke_dota2.txt @@ -1 +1 @@ -
Match List
A
3
2
B
[[abc|A]]
3
2
[[B|B]]
A Match Comment
\ No newline at end of file +
Match List
A
3
2
B
[[abc|A]]
3
2
[[B|B]]
A Match Comment
\ No newline at end of file diff --git a/spec/golden_masters/match2_matchlist_smoke_leagueoflegends.txt b/spec/golden_masters/match2_matchlist_smoke_leagueoflegends.txt index f0806e71879..c1714a8ed41 100644 --- a/spec/golden_masters/match2_matchlist_smoke_leagueoflegends.txt +++ b/spec/golden_masters/match2_matchlist_smoke_leagueoflegends.txt @@ -1 +1 @@ -
Match List
A
3
2
B
[[abc|A]]
3
2
[[B|B]]
[[Match:ID_leagueofle_0001|Match Page]]
A Match Comment
\ No newline at end of file +
Match List
A
3
2
B
[[abc|A]]
3
2
[[B|B]]
[[Match:ID_leagueofle_0001|Match Page]]
A Match Comment
\ No newline at end of file diff --git a/spec/golden_masters/match2_matchlist_smoke_mobilelegends.txt b/spec/golden_masters/match2_matchlist_smoke_mobilelegends.txt index 35ccb48e159..5a8ba5b9294 100644 --- a/spec/golden_masters/match2_matchlist_smoke_mobilelegends.txt +++ b/spec/golden_masters/match2_matchlist_smoke_mobilelegends.txt @@ -1 +1 @@ -
Match List
A
3
2
B
[[abc|A]]
3
2
[[B|B]]
A Match Comment
\ No newline at end of file +
Match List
A
3
2
B
[[abc|A]]
3
2
[[B|B]]
A Match Comment
\ No newline at end of file diff --git a/spec/golden_masters/match2_matchlist_smoke_overwatch.txt b/spec/golden_masters/match2_matchlist_smoke_overwatch.txt index 5f5d4ee0c96..27050d068ed 100644 --- a/spec/golden_masters/match2_matchlist_smoke_overwatch.txt +++ b/spec/golden_masters/match2_matchlist_smoke_overwatch.txt @@ -1 +1 @@ -
Match List
A
3
2
B
[[abc|A]]
3
2
[[B|B]]
A Match Comment
\ No newline at end of file +
Match List
A
3
2
B
[[abc|A]]
3
2
[[B|B]]
A Match Comment
\ No newline at end of file diff --git a/spec/golden_masters/match2_matchlist_smoke_rainbowsix.txt b/spec/golden_masters/match2_matchlist_smoke_rainbowsix.txt index 5f5d4ee0c96..27050d068ed 100644 --- a/spec/golden_masters/match2_matchlist_smoke_rainbowsix.txt +++ b/spec/golden_masters/match2_matchlist_smoke_rainbowsix.txt @@ -1 +1 @@ -
Match List
A
3
2
B
[[abc|A]]
3
2
[[B|B]]
A Match Comment
\ No newline at end of file +
Match List
A
3
2
B
[[abc|A]]
3
2
[[B|B]]
A Match Comment
\ No newline at end of file diff --git a/spec/golden_masters/match2_matchlist_smoke_rocketleague.txt b/spec/golden_masters/match2_matchlist_smoke_rocketleague.txt index 12421b538b5..a79ea578b67 100644 --- a/spec/golden_masters/match2_matchlist_smoke_rocketleague.txt +++ b/spec/golden_masters/match2_matchlist_smoke_rocketleague.txt @@ -1 +1 @@ -
Match List
A
3
2
B
[[abc|A]]
3
:
2
[[B|B]]
A Match Comment
\ No newline at end of file +
Match List
A
3
2
B
[[abc|A]]
3
:
2
[[B|B]]
A Match Comment
\ No newline at end of file diff --git a/spec/golden_masters/match2_matchlist_smoke_starcraft2.txt b/spec/golden_masters/match2_matchlist_smoke_starcraft2.txt index 13fd772c9c1..938a11ce137 100644 --- a/spec/golden_masters/match2_matchlist_smoke_starcraft2.txt +++ b/spec/golden_masters/match2_matchlist_smoke_starcraft2.txt @@ -1 +1 @@ -
Match List
A
3
2
B
[[abc|A]]
3
2
[[B|B]]
A Match Comment
\ No newline at end of file +
Match List
A
3
2
B
[[abc|A]]
3
2
[[B|B]]
A Match Comment
\ No newline at end of file diff --git a/spec/golden_masters/match2_matchlist_smoke_valorant.txt b/spec/golden_masters/match2_matchlist_smoke_valorant.txt index 4513ac23041..984925b1cdb 100644 --- a/spec/golden_masters/match2_matchlist_smoke_valorant.txt +++ b/spec/golden_masters/match2_matchlist_smoke_valorant.txt @@ -1 +1 @@ -
Match List
A
3
2
B
[[abc|A]]
3
2
[[B|B]]
A Match Comment
\ No newline at end of file +
Match List
A
3
2
B
[[abc|A]]
3
2
[[B|B]]
A Match Comment
\ No newline at end of file