diff --git a/components/match2/wikis/dota2/match_group_input_custom.lua b/components/match2/wikis/dota2/match_group_input_custom.lua index f4f2053e25d..2ffd115c346 100644 --- a/components/match2/wikis/dota2/match_group_input_custom.lua +++ b/components/match2/wikis/dota2/match_group_input_custom.lua @@ -20,6 +20,9 @@ local Variables = require('Module:Variables') local MatchGroupInputUtil = Lua.import('Module:MatchGroup/Input/Util') local MatchGroupUtil = Lua.import('Module:MatchGroup/Util') +local OpponentLibraries = Lua.import('Module:OpponentLibraries') +local Opponent = OpponentLibraries.Opponent + local OPPONENT_CONFIG = { resolveRedirect = true, pagifyTeamNames = false, @@ -110,12 +113,12 @@ function CustomMatchGroupInput.processMatchWithoutStandalone(MatchParser, match) Table.mergeInto(match, MatchGroupInputUtil.getTournamentContext(match)) match.stream = Streams.processStreams(match) - match.links = MatchFunctions.getLinks(match, games) + match.links = MatchFunctions.getLinks(match, games, opponents) match.games = games match.opponents = opponents - match.extradata = MatchFunctions.getExtraData(match) + match.extradata = MatchFunctions.getExtraData(match, opponents) return match end @@ -176,8 +179,9 @@ end ---@param match table ---@param games table[] +---@param opponents table[] ---@return table -function MatchFunctions.getLinks(match, games) +function MatchFunctions.getLinks(match, games, opponents) local links = { preview = match.preview, lrthread = match.lrthread, @@ -195,15 +199,26 @@ function MatchFunctions.getLinks(match, games) links.datdota[mapIndex] = 'https://www.datdota.com/matches/' .. map.publisherid end ) + + local isTeamGame = Array.all(opponents, function(opponent) + return opponent.type == Opponent.team + end) + if Logic.readBool(Logic.emptyOr(match.headtohead, Variables.varDefault('headtohead'))) and isTeamGame then + local team1, team2 = string.gsub(match.opponents[1].name, ' ', '_'), string.gsub(match.opponents[2].name, ' ', '_') + links.headtohead = tostring(mw.uri.fullUrl('Special:RunQuery/Match_history')) .. + '?pfRunQueryFormName=Match+history&Head_to_head_query%5Bplayer%5D=' .. team1 .. + '&Head_to_head_query%5Bopponent%5D=' .. team2 .. '&wpRunQuery=Run+query' + end + return links end ---@param match table +---@param opponents table[] ---@return table -function MatchFunctions.getExtraData(match) +function MatchFunctions.getExtraData(match, opponents) return { mvp = MatchGroupInputUtil.readMvp(match), - headtohead = Logic.emptyOr(match.headtohead, Variables.varDefault('headtohead')), casters = MatchGroupInputUtil.readCasters(match, {noSort = true}), } end diff --git a/components/match2/wikis/dota2/match_summary.lua b/components/match2/wikis/dota2/match_summary.lua index 18b0520bc3a..7670b3a7081 100644 --- a/components/match2/wikis/dota2/match_summary.lua +++ b/components/match2/wikis/dota2/match_summary.lua @@ -10,7 +10,6 @@ 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 MatchLinks = mw.loadData('Module:MatchLinks') @@ -20,14 +19,11 @@ 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 Opponent = Lua.import('Module:Opponent') local WidgetUtil = Lua.import('Module:Widget/Util') local HtmlWidgets = Lua.import('Module:Widget/Html/All') local MAX_NUM_BANS = 7 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 @@ -41,17 +37,6 @@ end function CustomMatchSummary.addToFooter(match, footer) footer = MatchSummary.addVodsToFooter(match, footer) - if - Logic.readBool(match.extradata.headtohead) and - match.opponents[1].type == Opponent.team and - match.opponents[2].type == Opponent.team - then - local team1, team2 = string.gsub(match.opponents[1].name, ' ', '_'), string.gsub(match.opponents[2].name, ' ', '_') - match.links.headtohead = tostring(mw.uri.fullUrl('Special:RunQuery/Match_history')) .. - '?pfRunQueryFormName=Match+history&Head_to_head_query%5Bplayer%5D=' .. team1 .. - '&Head_to_head_query%5Bopponent%5D=' .. team2 .. '&wpRunQuery=Run+query' - end - return footer:addLinks(MatchLinks, match.links) end @@ -94,7 +79,7 @@ function CustomMatchSummary._createGame(game, gameIndex) -- Map Comment local comment = Logic.isNotEmpty(game.comment) and { - MatchSummary.Break():create(), + MatchSummaryWidgets.Break{}, HtmlWidgets.Div{css = {margin = 'auto'}, children = game.comment}, } or {} @@ -107,12 +92,12 @@ function CustomMatchSummary._createGame(game, gameIndex) characters = heroesData[1], bg = 'brkts-popup-side-color-' .. (extradata.team1side or ''), }, - CustomMatchSummary._createCheckMark(game.winner == 1), + 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)}, }, - CustomMatchSummary._createCheckMark(game.winner == 2), + MatchSummaryWidgets.GameWinLossIndicator{winner = game.winner, opponentIndex = 2}, MatchSummaryWidgets.Characters{ flipped = true, characters = heroesData[2], @@ -123,22 +108,4 @@ function CustomMatchSummary._createGame(game, gameIndex) } end ----@param isWinner boolean? ----@return Html -function CustomMatchSummary._createCheckMark(isWinner) - local container = mw.html.create('div') - :addClass('brkts-popup-spaced') - :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 - return CustomMatchSummary diff --git a/components/widget/match/summary/widget_match_summary_all.lua b/components/widget/match/summary/widget_match_summary_all.lua index 4d240a33476..6c0b691a1b2 100644 --- a/components/widget/match/summary/widget_match_summary_all.lua +++ b/components/widget/match/summary/widget_match_summary_all.lua @@ -11,9 +11,11 @@ local Widgets = {} local Lua = require('Module:Lua') Widgets.Body = Lua.import('Module:Widget/Match/Summary/Body') +Widgets.Break = Lua.import('Module:Widget/Match/Summary/Break') Widgets.CharacterBanTable = Lua.import('Module:Widget/Match/Summary/CharacterBanTable') Widgets.Characters = Lua.import('Module:Widget/Match/Summary/Characters') Widgets.Character = Lua.import('Module:Widget/Match/Summary/Character') +Widgets.GameWinLossIndicator = Lua.import('Module:Widget/Match/Summary/GameWinLossIndicator') 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_break.lua b/components/widget/match/summary/widget_match_summary_break.lua new file mode 100644 index 00000000000..6b2fb527ab8 --- /dev/null +++ b/components/widget/match/summary/widget_match_summary_break.lua @@ -0,0 +1,27 @@ +--- +-- @Liquipedia +-- wiki=commons +-- page=Module:Widget/Match/Summary/Break +-- +-- Please see https://github.com/Liquipedia/Lua-Modules to contribute +-- + +local Class = require('Module:Class') +local Lua = require('Module:Lua') + +local Widget = Lua.import('Module:Widget') +local HtmlWidgets = Lua.import('Module:Widget/Html/All') +local Div = HtmlWidgets.Div + +---@class MatchSummaryBreak: Widget +---@operator call(table): MatchSummaryBreak +local MatchSummaryBreak = Class.new(Widget) + +---@return Widget +function MatchSummaryBreak:render() + return Div{ + classes = {'brkts-popup-break'}, + } +end + +return MatchSummaryBreak 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 new file mode 100644 index 00000000000..e79981928f5 --- /dev/null +++ b/components/widget/match/summary/widget_match_summary_game_winloss_indicator.lua @@ -0,0 +1,55 @@ +--- +-- @Liquipedia +-- wiki=commons +-- page=Module:Widget/Match/Summary/GameWinLossIndicator +-- +-- Please see https://github.com/Liquipedia/Lua-Modules to contribute +-- + +local Class = require('Module:Class') +local Icon = require('Module:Icon') +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 Div = HtmlWidgets.Div + +local ICONS = { + win = Icon.makeIcon{iconName = 'winner', color = 'forest-green-text', size = '110%'}, + draw = Icon.makeIcon{iconName = 'draw', color = 'bright-sun-text', size = '110%'}, + loss = Icon.makeIcon{iconName = 'loss', color = 'cinnabar-text', size = '110%'}, + empty = '[[File:NoCheck.png|link=|16px]]', +} + +---@class MatchSummaryGameWinLossIndicator: Widget +---@operator call(table): MatchSummaryGameWinLossIndicator +local MatchSummaryGameWinLossIndicator = Class.new(Widget) + +---@return Widget +function MatchSummaryGameWinLossIndicator:render() + local winner = self.props.winner + + local icon + if winner == self.props.opponentIndex then + icon = ICONS.win + elseif winner == 0 then + icon = ICONS.draw + elseif Logic.isNotEmpty(winner) then + icon = ICONS.loss + else + icon = ICONS.empty + end + + return Div{ + classes = {'brkts-popup-spaced'}, + css = { + ['line-height'] = '17px', + ['margin-left'] = '1%', + ['margin-right'] = '1%', + }, + children = {icon}, + } +end + +return MatchSummaryGameWinLossIndicator \ No newline at end of file