Skip to content

Commit

Permalink
break widget, "checkmark" widget, move logic to MGI
Browse files Browse the repository at this point in the history
  • Loading branch information
Rathoz committed Oct 19, 2024
1 parent 1359205 commit c3dd004
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 41 deletions.
25 changes: 20 additions & 5 deletions components/match2/wikis/dota2/match_group_input_custom.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down
39 changes: 3 additions & 36 deletions components/match2/wikis/dota2/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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 {}

Expand All @@ -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],
Expand All @@ -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
2 changes: 2 additions & 0 deletions components/widget/match/summary/widget_match_summary_all.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
27 changes: 27 additions & 0 deletions components/widget/match/summary/widget_match_summary_break.lua
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit c3dd004

Please sign in to comment.