Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update RL, Sideswipe and Trackmania MatchSummary #3335

Merged
merged 9 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
215 changes: 96 additions & 119 deletions components/match2/wikis/rocketleague/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,66 +6,61 @@
-- Please see https://github.com/Liquipedia/Lua-Modules to contribute
--

local Abbreviation = require('Module:Abbreviation')
local Class = require('Module:Class')
local Json = require('Module:Json')
local Logic = require('Module:Logic')
local Lua = require('Module:Lua')
local Table = require('Module:Table')
local VodLink = require('Module:VodLink')
local Json = require('Module:Json')
local Abbreviation = require('Module:Abbreviation')
local String = require('Module:StringUtils')
local Table = require('Module:Table')

local DisplayHelper = Lua.import('Module:MatchGroup/Display/Helper', {requireDevIfEnabled = true})
local MatchGroupUtil = Lua.import('Module:MatchGroup/Util', {requireDevIfEnabled = true})
local MatchSummary = Lua.import('Module:MatchSummary/Base', {requireDevIfEnabled = true})
local MatchSummary = Lua.import('Module:MatchSummary/Base/temp', {requireDevIfEnabled = true})
local OpponentDisplay = Lua.import('Module:OpponentDisplay', {requireDevIfEnabled = true})

local _GREEN_CHECK = '[[File:GreenCheck.png|14x14px|link=]]'
local _NO_CHECK = '[[File:NoCheck.png|link=]]'
local _TIMEOUT = '[[File:Cooldown_Clock.png|14x14px|link=]]'
local GREEN_CHECK = '[[File:GreenCheck.png|14x14px|link=]]'
local NO_CHECK = '[[File:NoCheck.png|link=]]'
local TIMEOUT = '[[File:Cooldown_Clock.png|14x14px|link=]]'

local _SHIFT_PREFIX = '[[File:ShiftRLE icon.png|14x14px|link='
local _SHIFT_SUFFIX = '|ShiftRLE matchpage]]'
local _BALLCHASING_PREFIX = '[[File:Ballchasing icon.png|14x14px|link='
local _BALLCHASING_SUFFIX = '|Ballchasing replays]]'
local _HEADTOHEAD_PREFIX = '[[File:Match Info Stats.png|14x14px|link='
local _HEADTOHEAD_SUFFIX = '|Head to Head history]]'
local TBD_ICON = mw.ext.TeamTemplate.teamicon('tbd')

local _TBD_ICON = mw.ext.TeamTemplate.teamicon('tbd')
local LINK_DATA = {
shift = {icon = 'File:ShiftRLE icon.png', text = 'ShiftRLE matchpage'},
ballchasing = {icon = 'File:Ballchasing icon.png', text = 'Ballchasing replays'},
headtohead = {icon = 'File:Match Info Stats.png', text = 'Head to Head history'},
}

-- Custom Header Class
local Header = Class.new(
function(self)
self.root = mw.html.create('div')
self.root:addClass('brkts-popup-header-dev')
end
)

---@class RocketleagueMatchSummaryHeader: MatchSummaryHeader
---@field leftElementAdditional Html
---@field rightElementAdditional Html
---@field scoreBoardElement Html
local Header = Class.new(MatchSummary.Header)

---@param content Html
---@return self
function Header:leftOpponentTeam(content)
self.leftElementAdditional = content
return self
end

---@param content Html
---@return self
function Header:rightOpponentTeam(content)
self.rightElementAdditional = content
return self
end

---@param content Html
---@return self
function Header:scoreBoard(content)
self.scoreBoard = content
return self
end

function Header:leftOpponent(content)
self.leftElement = content
return self
end

function Header:rightOpponent(content)
self.rightElement = content
self.scoreBoardElement = content
return self
end

---@param opponent1 standardOpponent
---@param opponent2 standardOpponent
---@return Html
function Header:createScoreDisplay(opponent1, opponent2)
local function getScore(opponent)
local scoreText
Expand Down Expand Up @@ -103,6 +98,10 @@ function Header:createScoreDisplay(opponent1, opponent2)
:node(getScore(opponent2))
end

---@param score number?
---@param bestof number?
---@param isNotFinished boolean?
---@return Html
function Header:createScoreBoard(score, bestof, isNotFinished)
local scoreBoardNode = mw.html.create('div')
:addClass('brkts-popup-spaced')
Expand All @@ -129,17 +128,23 @@ function Header:createScoreBoard(score, bestof, isNotFinished)
return scoreBoardNode:node(score)
end

---@param opponent standardOpponent
---@param date string
---@return Html?
function Header:soloOpponentTeam(opponent, date)
if opponent.type == 'solo' then
local teamExists = mw.ext.TeamTemplate.teamexists(opponent.template or '')
local display = teamExists
and mw.ext.TeamTemplate.teamicon(opponent.template, date)
or _TBD_ICON
or TBD_ICON
return mw.html.create('div'):wikitext(display)
:addClass('brkts-popup-header-opponent-solo-team')
end
end

---@param opponent standardOpponent
---@param opponentIndex integer
---@return Html
function Header:createOpponent(opponent, opponentIndex)
return OpponentDisplay.BlockOpponent({
flip = opponentIndex == 1,
Expand All @@ -152,100 +157,32 @@ function Header:createOpponent(opponent, opponentIndex)
or 'brkts-popup-header-opponent-solo-with-team')
end

---@return Html
function Header:create()
self.root:tag('div'):addClass('brkts-popup-header-opponent'):addClass('brkts-popup-header-opponent-left')
:node(self.leftElementAdditional)
:node(self.leftElement)
self.root:node(self.scoreBoard)
self.root:node(self.scoreBoardElement)
self.root:tag('div'):addClass('brkts-popup-header-opponent'):addClass('brkts-popup-header-opponent-right')
:node(self.rightElement)
:node(self.rightElementAdditional)
return self.root
end


local CustomMatchSummary = {}

function CustomMatchSummary._getHeadToHead(opponents)
local team1, team2 = mw.uri.encode(opponents[1].name), mw.uri.encode(opponents[2].name)
local link = tostring(mw.uri.fullUrl('Special:RunQuery/Head2head'))
.. '?RunQuery=Run&pfRunQueryFormName=Head2head&Headtohead%5Bteam1%5D='
.. team1 .. '&Headtohead%5Bteam2%5D=' .. team2
return _HEADTOHEAD_PREFIX .. link .. _HEADTOHEAD_SUFFIX
end

---@param args table
---@return Html
function CustomMatchSummary.getByMatchId(args)
local match = MatchGroupUtil.fetchMatchForBracketDisplay(args.bracketId, args.matchId)

local matchSummary = MatchSummary():init()

matchSummary:header(CustomMatchSummary._createHeader(match))
:body(CustomMatchSummary._createBody(match))

if match.comment then
local comment = MatchSummary.Comment():content(match.comment)
matchSummary:comment(comment)
end

-- footer
local vods = {}
for index, game in ipairs(match.games) do
if game.vod then
vods[index] = game.vod
end
end

local headToHead = match.extradata.showh2h and
CustomMatchSummary._getHeadToHead(match.opponents) or nil

if
Table.isNotEmpty(vods) or
String.isNotEmpty(match.vod) or
Table.isNotEmpty(match.links) or
headToHead
then
local footer = MatchSummary.Footer()

-- Shift
for _, shift in Table.iter.pairsByPrefix(match.links, 'shift', {requireIndex = false}) do
footer:addElement(_SHIFT_PREFIX .. shift .. _SHIFT_SUFFIX)
end

-- Ballchasing
for _, ballchasing in Table.iter.pairsByPrefix(match.links, 'ballchasing', {requireIndex = false}) do
footer:addElement(_BALLCHASING_PREFIX .. ballchasing .. _BALLCHASING_SUFFIX)
end

-- Match Vod
if String.isNotEmpty(match.vod) then
footer:addElement(VodLink.display{
vod = match.vod,
})
end

-- Game Vods
for index, vod in pairs(vods) do
footer:addElement(VodLink.display{
gamenum = index,
vod = vod,
})
end

-- Head-to-head
if headToHead then
footer:addElement(headToHead)
end

matchSummary:footer(footer)
end

return matchSummary:create()
return MatchSummary.defaultGetByMatchId(CustomMatchSummary, args)
end

function CustomMatchSummary._createHeader(match)
---@param match MatchGroupUtilMatch
---@return RocketleagueMatchSummaryHeader
function CustomMatchSummary.createHeader(match)
local header = Header()

header
return header
:leftOpponentTeam(header:soloOpponentTeam(match.opponents[1], match.date))
:leftOpponent(header:createOpponent(match.opponents[1], 1))
:scoreBoard(header:createScoreBoard(
Expand All @@ -258,11 +195,41 @@ function CustomMatchSummary._createHeader(match)
))
:rightOpponent(header:createOpponent(match.opponents[2], 2))
:rightOpponentTeam(header:soloOpponentTeam(match.opponents[2], match.date))
end

return header
---@param match MatchGroupUtilMatch
---@param footer MatchSummaryFooter
---@return MatchSummaryFooter
function CustomMatchSummary.addToFooter(match, footer)
for linkType, linkData in pairs(LINK_DATA) do
for _, link in Table.iter.pairsByPrefix(match.links, linkType, {requireIndex = false}) do
footer:addLink(link, linkData.icon, linkData.iconDark, linkData.text)
end
end

footer = MatchSummary.addVodsToFooter(match, footer)

if not match.extradata.showh2h then
return footer
end

local h2hLinkData = LINK_DATA.headtohead
return footer:addLink(CustomMatchSummary._getHeadToHead(match.opponents),
h2hLinkData.icon, h2hLinkData.iconDark, h2hLinkData.text)
end

---@param opponents standardOpponent[]
---@return string
function CustomMatchSummary._getHeadToHead(opponents)
local team1, team2 = mw.uri.encode(opponents[1].name), mw.uri.encode(opponents[2].name)
return tostring(mw.uri.fullUrl('Special:RunQuery/Head2head'))
.. '?RunQuery=Run&pfRunQueryFormName=Head2head&Headtohead%5Bteam1%5D='
.. team1 .. '&Headtohead%5Bteam2%5D=' .. team2
end

function CustomMatchSummary._createBody(match)
---@param match MatchGroupUtilMatch
---@return MatchSummaryBody
function CustomMatchSummary.createBody(match)
local body = MatchSummary.Body()

body:addRow(MatchSummary.Row():addElement(DisplayHelper.MatchCountdownBlock(match)))
Expand All @@ -289,6 +256,8 @@ function CustomMatchSummary._createBody(match)
return body
end

---@param game MatchGroupUtilGame
---@return MatchSummaryRow
function CustomMatchSummary._createGame(game)
local row = MatchSummary.Row()
:addClass('brkts-popup-body-game')
Expand Down Expand Up @@ -316,14 +285,14 @@ function CustomMatchSummary._createGame(game)
end

row:addElement(CustomMatchSummary._iconDisplay(
_GREEN_CHECK,
GREEN_CHECK,
game.winner == 1,
game.scores[1],
1
))
row:addElement(centerNode)
row:addElement(CustomMatchSummary._iconDisplay(
_GREEN_CHECK,
GREEN_CHECK,
game.winner == 2,
game.scores[2],
2
Expand All @@ -333,15 +302,15 @@ function CustomMatchSummary._createGame(game)
local timeouts = Json.parseIfString(extradata.timeout)
row:addElement(MatchSummary.Break():create())
row:addElement(CustomMatchSummary._iconDisplay(
_TIMEOUT,
TIMEOUT,
Table.includes(timeouts, 1)
))
row:addElement(mw.html.create('div')
:addClass('brkts-popup-spaced')
:node(mw.html.create('div'):node('Timeout'))
)
row:addElement(CustomMatchSummary._iconDisplay(
_TIMEOUT,
TIMEOUT,
Table.includes(timeouts, 2)
))
end
Expand Down Expand Up @@ -370,6 +339,9 @@ function CustomMatchSummary._createGame(game)
return row
end

---@param goalesValue string|number
---@param side 1|2
---@return Html
function CustomMatchSummary._goalDisaplay(goalesValue, side)
local goalsDisplay = mw.html.create('div')
:cssText(side == 2 and 'float:right; margin-right:10px;' or nil)
Expand All @@ -384,12 +356,17 @@ function CustomMatchSummary._goalDisaplay(goalesValue, side)
:node(goalsDisplay)
end

---@param icon string
---@param shouldDisplay boolean?
---@param additionalElement number|string|Html|nil
---@param side integer?
---@return Html
function CustomMatchSummary._iconDisplay(icon, shouldDisplay, additionalElement, side)
local flip = side == 2
return mw.html.create('div')
:addClass('brkts-popup-spaced')
:node(additionalElement and flip and mw.html.create('div'):node(additionalElement) or nil)
:node(shouldDisplay and icon or _NO_CHECK)
:node(shouldDisplay and icon or NO_CHECK)
:node(additionalElement and (not flip) and mw.html.create('div'):node(additionalElement) or nil)
end

Expand Down
Loading
Loading