Skip to content
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
76 changes: 32 additions & 44 deletions lua/wikis/counterstrike/MatchSummary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,23 @@
local Lua = require('Module:Lua')

local Array = Lua.import('Module:Array')
local Class = Lua.import('Module:Class')
local Logic = Lua.import('Module:Logic')
local String = Lua.import('Module:StringUtils')
local Table = Lua.import('Module:Table')
local VodLink = Lua.import('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 WidgetUtil = Lua.import('Module:Widget/Util')

---@class CounterstrikeCustomMatchSummary: CustomMatchSummaryInterface
local CustomMatchSummary = {}

---@class CounterstrikeMatchSummaryGameRow: MatchSummaryGameRow
---@operator call(MatchSummaryGameRowProps): CounterstrikeMatchSummaryGameRow
local CounterstrikeMatchSummaryGameRow = Class.new(MatchSummaryWidgets.GameRow)

---@param args table
---@return Widget
function CustomMatchSummary.getByMatchId(args)
Expand Down Expand Up @@ -63,7 +68,14 @@ function CustomMatchSummary.createBody(match)
matchStatusText = '<b>Match ' .. mw.getContentLanguage():ucfirst(match.extradata.status) .. '</b>'
end
return WidgetUtil.collect(
Array.map(match.games, CustomMatchSummary._createMap),
MatchSummaryWidgets.GamesContainer{
children = Array.map(match.games, function (game, gameIndex)
if Logic.isEmpty(game.map) then
return
end
return CounterstrikeMatchSummaryGameRow{game = game, gameIndex = gameIndex}
end)
},
MatchSummaryWidgets.MapVeto(MatchSummary.preProcessMapVeto(match.extradata.mapveto, {game = match.game})),
MatchSummaryWidgets.MatchComment{children = matchStatusText} or nil
)
Expand Down Expand Up @@ -182,49 +194,25 @@ function CustomMatchSummary._createFooter(match, vods, secondVods)
return footer
end

---@param game MatchGroupUtilGame
---@return Widget?
function CustomMatchSummary._createMap(game)
if not game.map then
return
end

local function score(oppIdx)
return DisplayHelper.MapScore(game.opponents[oppIdx], game.status)
end

-- Teams scores
local extradata = game.extradata or {}
local t1sides = extradata.t1sides or {}
local t2sides = extradata.t2sides or {}
local t1halfs = extradata.t1halfs or {}
local t2halfs = extradata.t2halfs or {}

local team1Scores = {}
local team2Scores = {}
for sideIndex in ipairs(t1sides) do
local side1, side2 = t1sides[sideIndex], t2sides[sideIndex]
local score1, score2 = t1halfs[sideIndex], t2halfs[sideIndex]
table.insert(team1Scores, {style = side1 and ('brkts-cs-score-color-'.. side1) or nil, score = score1})
table.insert(team2Scores, {style = side2 and ('brkts-cs-score-color-'.. side2) or nil, score = score2})
end

local mapInfo = {
mapDisplayName = game.map,
map = game.game and (game.map .. '/' .. game.game) or game.map,
status = game.status,
}
---@return string
function CounterstrikeMatchSummaryGameRow:createGameOverview()
return self:mapDisplay()
end

return MatchSummaryWidgets.Row{
classes = {'brkts-popup-body-game'},
children = WidgetUtil.collect(
MatchSummaryWidgets.GameWinLossIndicator{winner = game.winner, opponentIndex = 1},
MatchSummaryWidgets.DetailedScore{score = score(1), partialScores = team1Scores, flipped = false},
MatchSummaryWidgets.GameCenter{children = DisplayHelper.Map(mapInfo), css = {['flex-grow'] = '1'}},
MatchSummaryWidgets.DetailedScore{score = score(2), partialScores = team2Scores, flipped = true},
MatchSummaryWidgets.GameWinLossIndicator{winner = game.winner, opponentIndex = 2},
MatchSummaryWidgets.GameComment{children = game.comment}
)
---@param opponentIndex integer
---@return Widget
function CounterstrikeMatchSummaryGameRow:createGameOpponentView(opponentIndex)
local game = self.props.game

local sides = game.extradata['t' .. opponentIndex .. 'sides']
local halfs = game.extradata['t' .. opponentIndex .. 'halfs']
local scores = Array.map(sides, function (side, sideIndex)
return {style = side and ('brkts-cs-score-color-'.. side) or nil, score = halfs[sideIndex]}
end)

return MatchSummaryWidgets.DetailedScore{
score = self:scoreDisplay(opponentIndex),
partialScores = scores,
}
end

Expand Down
82 changes: 43 additions & 39 deletions lua/wikis/honorofkings/MatchSummary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
-- Please see https://github.com/Liquipedia/Lua-Modules to contribute
--

local CustomMatchSummary = {}

local Lua = require('Module:Lua')

local Array = Lua.import('Module:Array')
local FnUtil = Lua.import('Module:FnUtil')
local Class = Lua.import('Module:Class')
local Logic = Lua.import('Module:Logic')

local MatchSummary = Lua.import('Module:MatchSummary/Base')
Expand All @@ -20,6 +18,13 @@ local WidgetUtil = Lua.import('Module:Widget/Util')
local MAX_NUM_BANS = 5
local NUM_CHAMPIONS_PICK = 5

---@class HoKCustomMatchSummary: CustomMatchSummaryInterface
local CustomMatchSummary = {}

---@class HoKMatchSummaryGameRow: MatchSummaryGameRow
---@operator call(MatchSummaryGameRowProps): HoKMatchSummaryGameRow
local HoKMatchSummaryGameRow = Class.new(MatchSummaryWidgets.GameRow)

---@param args table
---@return Widget
function CustomMatchSummary.getByMatchId(args)
Expand All @@ -31,50 +36,49 @@ end
function CustomMatchSummary.createBody(match)
local characterBansData = MatchSummary.buildCharacterBanData(match.games, MAX_NUM_BANS)

---@param game MatchGroupUtilGame
---@return boolean
local function hasCharacterData(game)
local extradata = game.extradata or {}
return Array.any(Array.range(1, NUM_CHAMPIONS_PICK), function (index)
return Logic.isNotEmpty(extradata['team1champion' .. index])
or Logic.isNotEmpty(extradata['team2champion' .. index])
end)
end

return WidgetUtil.collect(
Array.map(match.games, FnUtil.curry(CustomMatchSummary._createGame, match.date)),
MatchSummaryWidgets.GamesContainer{
children = Array.map(match.games, function (game, gameIndex)
if Logic.isEmpty(game.length) and Logic.isEmpty(game.winner) and not hasCharacterData(game) then
return
end
return HoKMatchSummaryGameRow{game = game, gameIndex = gameIndex}
end)
},
MatchSummaryWidgets.Mvp(match.extradata.mvp),
MatchSummaryWidgets.CharacterBanTable{bans = characterBansData, date = match.date}
)
end

---@param date string
---@param game MatchGroupUtilGame
---@param gameIndex integer
---@return MatchSummaryRow?
function CustomMatchSummary._createGame(date, game, gameIndex)
local extradata = game.extradata or {}

-- TODO: Change to use participant data
local characterData = {
MatchSummary.buildCharacterList(extradata, 'team1champion', NUM_CHAMPIONS_PICK),
MatchSummary.buildCharacterList(extradata, 'team2champion', NUM_CHAMPIONS_PICK),
}
---@return Renderable?
function HoKMatchSummaryGameRow:createGameOverview()
return self:lengthDisplay()
end

if Logic.isEmpty(game.length) and Logic.isEmpty(game.winner) and Logic.isDeepEmpty(characterData) then
return nil
end
---@param opponentIndex integer
---@return Widget
function HoKMatchSummaryGameRow:createGameOpponentView(opponentIndex)
local props = self.props
local game = props.game
local extradata = game.extradata or {}

return MatchSummaryWidgets.Row{
classes = {'brkts-popup-body-game'},
children = WidgetUtil.collect(
MatchSummaryWidgets.Characters{
flipped = false,
characters = characterData[1],
bg = 'brkts-popup-side-color brkts-popup-side-color--' .. (extradata.team1side or ''),
date = date,
},
MatchSummaryWidgets.GameWinLossIndicator{winner = game.winner, opponentIndex = 1},
MatchSummaryWidgets.GameCenter{children = Logic.nilIfEmpty(game.length) or ('Game ' .. gameIndex)},
MatchSummaryWidgets.GameWinLossIndicator{winner = game.winner, opponentIndex = 2},
MatchSummaryWidgets.Characters{
flipped = true,
characters = characterData[2],
bg = 'brkts-popup-side-color brkts-popup-side-color--' .. (extradata.team2side or ''),
date = date,
},
MatchSummaryWidgets.GameComment{children = game.comment}
)
return MatchSummaryWidgets.Characters{
flipped = opponentIndex == 2,
characters = MatchSummary.buildCharacterList(
extradata, 'team' .. opponentIndex .. 'champion', NUM_CHAMPIONS_PICK
),
bg = 'brkts-popup-side-color brkts-popup-side-color--' .. (extradata['team' .. opponentIndex .. 'side'] or ''),
date = game.date,
}
end

Expand Down
82 changes: 43 additions & 39 deletions lua/wikis/mobilelegends/MatchSummary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
-- Please see https://github.com/Liquipedia/Lua-Modules to contribute
--

local CustomMatchSummary = {}

local Lua = require('Module:Lua')

local Array = Lua.import('Module:Array')
local FnUtil = Lua.import('Module:FnUtil')
local Class = Lua.import('Module:Class')
local Logic = Lua.import('Module:Logic')

local MatchSummary = Lua.import('Module:MatchSummary/Base')
Expand All @@ -20,6 +18,13 @@ local WidgetUtil = Lua.import('Module:Widget/Util')
local MAX_NUM_BANS = 5
local NUM_CHAMPIONS_PICK = 5

---@class MobileLegendsCustomMatchSummary: CustomMatchSummaryInterface
local CustomMatchSummary = {}

---@class MobileLegendsMatchSummaryGameRow: MatchSummaryGameRow
---@operator call(MatchSummaryGameRowProps): MobileLegendsMatchSummaryGameRow
local MobileLegendsMatchSummaryGameRow = Class.new(MatchSummaryWidgets.GameRow)

---@param args table
---@return Widget
function CustomMatchSummary.getByMatchId(args)
Expand All @@ -31,50 +36,49 @@ end
function CustomMatchSummary.createBody(match)
local characterBansData = MatchSummary.buildCharacterBanData(match.games, MAX_NUM_BANS)

---@param game MatchGroupUtilGame
---@return boolean
local function hasCharacterData(game)
local extradata = game.extradata or {}
return Array.any(Array.range(1, NUM_CHAMPIONS_PICK), function (index)
return Logic.isNotEmpty(extradata['team1champion' .. index])
or Logic.isNotEmpty(extradata['team2champion' .. index])
end)
end

return WidgetUtil.collect(
Array.map(match.games, FnUtil.curry(CustomMatchSummary._createGame, match.date)),
MatchSummaryWidgets.GamesContainer{
children = Array.map(match.games, function (game, gameIndex)
if Logic.isEmpty(game.length) and Logic.isEmpty(game.winner) and not hasCharacterData(game) then
return
end
return MobileLegendsMatchSummaryGameRow{game = game, gameIndex = gameIndex}
end)
},
MatchSummaryWidgets.Mvp(match.extradata.mvp),
MatchSummaryWidgets.CharacterBanTable{bans = characterBansData, date = match.date}
)
end

---@param date string
---@param game MatchGroupUtilGame
---@param gameIndex integer
---@return MatchSummaryRow?
function CustomMatchSummary._createGame(date, game, gameIndex)
local extradata = game.extradata or {}

-- TODO: Change to use participant data
local characterData = {
MatchSummary.buildCharacterList(extradata, 'team1champion', NUM_CHAMPIONS_PICK),
MatchSummary.buildCharacterList(extradata, 'team2champion', NUM_CHAMPIONS_PICK),
}
---@return Renderable?
function MobileLegendsMatchSummaryGameRow:createGameOverview()
return self:lengthDisplay()
end

if Logic.isEmpty(game.length) and Logic.isEmpty(game.winner) and Logic.isDeepEmpty(characterData) then
return nil
end
---@param opponentIndex integer
---@return Widget
function MobileLegendsMatchSummaryGameRow:createGameOpponentView(opponentIndex)
local props = self.props
local game = props.game
local extradata = game.extradata or {}

return MatchSummaryWidgets.Row{
classes = {'brkts-popup-body-game'},
children = WidgetUtil.collect(
MatchSummaryWidgets.Characters{
flipped = false,
characters = characterData[1],
bg = 'brkts-popup-side-color brkts-popup-side-color--' .. (extradata.team1side or ''),
date = date,
},
MatchSummaryWidgets.GameWinLossIndicator{winner = game.winner, opponentIndex = 1},
MatchSummaryWidgets.GameCenter{children = Logic.nilIfEmpty(game.length) or ('Game ' .. gameIndex)},
MatchSummaryWidgets.GameWinLossIndicator{winner = game.winner, opponentIndex = 2},
MatchSummaryWidgets.Characters{
flipped = true,
characters = characterData[2],
bg = 'brkts-popup-side-color brkts-popup-side-color--' .. (extradata.team2side or ''),
date = date,
},
MatchSummaryWidgets.GameComment{children = game.comment}
)
return MatchSummaryWidgets.Characters{
flipped = opponentIndex == 2,
characters = MatchSummary.buildCharacterList(
extradata, 'team' .. opponentIndex .. 'champion', NUM_CHAMPIONS_PICK
),
bg = 'brkts-popup-side-color brkts-popup-side-color--' .. (extradata['team' .. opponentIndex .. 'side'] or ''),
date = game.date,
}
end

Expand Down
Loading
Loading