Skip to content

Commit

Permalink
feat(match2): standardize core body display logic (#5012)
Browse files Browse the repository at this point in the history
* feat(match2): create standardized body and use it

* update assert

* ??
  • Loading branch information
Rathoz authored Nov 4, 2024
1 parent 9f4715b commit 059640d
Show file tree
Hide file tree
Showing 22 changed files with 97 additions and 381 deletions.
68 changes: 26 additions & 42 deletions components/match2/commons/match_summary_base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
local Abbreviation = require('Module:Abbreviation')
local Array = require('Module:Array')
local Class = require('Module:Class')
local DateExt = require('Module:Date/Ext')
local FnUtil = require('Module:FnUtil')
local Logic = require('Module:Logic')
local Lua = require('Module:Lua')
local Page = require('Module:Page')
Expand All @@ -18,6 +20,7 @@ local Table = require('Module:Table')
local VodLink = require('Module:VodLink')

local MatchGroupUtil = Lua.import('Module:MatchGroup/Util')
local DisplayHelper = Lua.import('Module:MatchGroup/Display/Helper')
local Links = Lua.import('Module:Links')
local MatchSummaryWidgets = Lua.import('Module:Widget/Match/Summary/All')
local WidgetUtil = Lua.import('Module:Widget/Util')
Expand Down Expand Up @@ -179,36 +182,6 @@ function Row:create()
return self.root
end

---@class MatchSummaryBody
---@operator call: MatchSummaryBody
---@field root Html
local Body = Class.new(
function(self)
self.root = mw.html.create('div')
self.root:addClass('brkts-popup-body')
end
)

---@param cssClass string?
---@return MatchSummaryBody
function Body:addClass(cssClass)
self.root:addClass(cssClass)
return self
end

---@param row MatchSummaryRowInterface?
---@return MatchSummaryBody
function Body:addRow(row)
if not row then return self end
self.root:node(row:create())
return self
end

---@return Html
function Body:create()
return self.root
end

---@class MatchSummaryFooter
---@operator call: MatchSummaryFooter
---@field root Html
Expand Down Expand Up @@ -302,16 +275,10 @@ function Match:header(header)
return self
end

---@param body MatchSummaryBody|Widget
---@param body Widget
---@return MatchSummaryMatch
function Match:body(body)
if type(body.create) == 'function' then
---@cast body MatchSummaryBody
self.bodyElement = body:create()
else
---@cast body Widget
self.bodyElement = body
end
self.bodyElement = body
return self
end

Expand Down Expand Up @@ -346,7 +313,6 @@ end
---@class MatchSummary
---@operator call(string?):MatchSummary
---@field Header MatchSummaryHeader
---@field Body MatchSummaryBody
---@field Row MatchSummaryRow
---@field Footer MatchSummaryFooter
---@field Match MatchSummaryMatch
Expand All @@ -355,7 +321,6 @@ end
---@field root Html?
local MatchSummary = Class.new()
MatchSummary.Header = Header
MatchSummary.Body = Body
MatchSummary.Row = Row
MatchSummary.Footer = Footer
MatchSummary.Match = Match
Expand Down Expand Up @@ -427,6 +392,21 @@ function MatchSummary.createDefaultHeader(match, options)
:rightOpponent(header:createOpponent(match.opponents[2], 'right', teamStyle))
end

-- Default body function
---@param match table
---@return Widget
function MatchSummary.createDefaultBody(match, createGame)
local showCountdown = match.timestamp ~= DateExt.defaultTimestamp

return MatchSummaryWidgets.Body{children = WidgetUtil.collect(
showCountdown and MatchSummaryWidgets.Row{children = DisplayHelper.MatchCountdownBlock(match)} or nil,
Array.map(match.games, FnUtil.curry(createGame, match.date)),
MatchSummaryWidgets.Mvp(match.extradata.mvp),
MatchSummaryWidgets.Casters{casters = match.extradata.casters},
MatchSummaryWidgets.MapVeto(MatchSummary.preProcessMapVeto(match.extradata.mapveto, {game = match.game}))
)}
end

---Default footer function
---@param match table
---@param footer MatchSummaryFooter
Expand Down Expand Up @@ -525,7 +505,8 @@ function MatchSummary.createMatch(matchData, CustomMatchSummary, options)
local createHeader = CustomMatchSummary.createHeader or MatchSummary.createDefaultHeader
match:header(createHeader(matchData, options))

match:body(CustomMatchSummary.createBody(matchData))
local createBody = CustomMatchSummary.createBody or MatchSummary.createDefaultBody
match:body(createBody(matchData, CustomMatchSummary.createGame))

local substituteComment = MatchSummary.createSubstitutesComment(matchData)

Expand All @@ -545,7 +526,10 @@ end
---@param options {teamStyle: teamStyle?, width: fun(MatchGroupUtilMatch):string?|string?, noScore:boolean?}?
---@return Html
function MatchSummary.defaultGetByMatchId(CustomMatchSummary, args, options)
assert(type(CustomMatchSummary.createBody) == 'function', 'Function "createBody" missing in "Module:MatchSummary"')
assert(
(type(CustomMatchSummary.createBody) == 'function' or type(CustomMatchSummary.createGame) == 'function'),
'createBody(match) or createGame(date, game, gameIndex) must be implemented in Module:MatchSummary'
)

options = options or {}

Expand Down
20 changes: 3 additions & 17 deletions components/match2/wikis/arenafps/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
-- Please see https://github.com/Liquipedia/Lua-Modules to contribute
--

local Array = require('Module:Array')
local DateExt = require('Module:Date/Ext')
local Logic = require('Module:Logic')
local Lua = require('Module:Lua')
local Page = require('Module:Page')
Expand All @@ -16,7 +14,6 @@ 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')

local CustomMatchSummary = {}

Expand All @@ -26,22 +23,11 @@ function CustomMatchSummary.getByMatchId(args)
return MatchSummary.defaultGetByMatchId(CustomMatchSummary, args)
end

---@param match MatchGroupUtilMatch
---@return Widget
function CustomMatchSummary.createBody(match)
local showCountdown = match.timestamp ~= DateExt.defaultTimestamp

return MatchSummaryWidgets.Body{children = WidgetUtil.collect(
showCountdown and MatchSummaryWidgets.Row{children = DisplayHelper.MatchCountdownBlock(match)} or nil,
Array.map(match.games, CustomMatchSummary._createMapRow),
MatchSummaryWidgets.Mvp(match.extradata.mvp),
MatchSummaryWidgets.Casters{casters = match.extradata.casters}
)}
end

---@param date string
---@param game MatchGroupUtilGame
---@param gameIndex integer
---@return Html?
function CustomMatchSummary._createMapRow(game)
function CustomMatchSummary.createGame(date, game, gameIndex)
if not game.map then
return
end
Expand Down
19 changes: 3 additions & 16 deletions components/match2/wikis/battlerite/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@

local CustomMatchSummary = {}

local Array = require('Module:Array')
local DateExt = require('Module:Date/Ext')
local Logic = require('Module:Logic')
local Lua = require('Module:Lua')

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')
Expand All @@ -24,21 +21,11 @@ function CustomMatchSummary.getByMatchId(args)
return MatchSummary.defaultGetByMatchId(CustomMatchSummary, args, {width = '400px', teamStyle = 'bracket'})
end

---@param match MatchGroupUtilMatch
---@return Widget
function CustomMatchSummary.createBody(match)
local showCountdown = match.timestamp ~= DateExt.defaultTimestamp

return MatchSummaryWidgets.Body{children = WidgetUtil.collect(
showCountdown and MatchSummaryWidgets.Row{children = DisplayHelper.MatchCountdownBlock(match)} or nil,
Array.map(match.games, CustomMatchSummary._createGame)
)}
end

---@param date string
---@param game MatchGroupUtilGame
---@param gameIndex integer
---@return MatchSummaryRow
function CustomMatchSummary._createGame(game, gameIndex)
---@return Widget?
function CustomMatchSummary.createGame(date, game, gameIndex)
return MatchSummaryWidgets.Row{
classes = {'brkts-popup-body-game'},
css = {['font-size'] = '80%', padding = '4px'},
Expand Down
19 changes: 3 additions & 16 deletions components/match2/wikis/callofduty/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
-- Please see https://github.com/Liquipedia/Lua-Modules to contribute
--

local Array = require('Module:Array')
local DateExt = require('Module:Date/Ext')
local Logic = require('Module:Logic')
local Lua = require('Module:Lua')
local MapModes = require('Module:MapModes')
Expand All @@ -16,7 +14,6 @@ local String = require('Module:StringUtils')
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')

local CustomMatchSummary = {}

Expand All @@ -26,18 +23,6 @@ function CustomMatchSummary.getByMatchId(args)
return MatchSummary.defaultGetByMatchId(CustomMatchSummary, args)
end

---@param match MatchGroupUtilMatch
---@return Widget
function CustomMatchSummary.createBody(match)
local showCountdown = match.timestamp ~= DateExt.defaultTimestamp

return MatchSummaryWidgets.Body{children = WidgetUtil.collect(
showCountdown and MatchSummaryWidgets.Row{children = DisplayHelper.MatchCountdownBlock(match)} or nil,
Array.map(match.games, CustomMatchSummary._createMapRow),
MatchSummaryWidgets.Mvp(match.extradata.mvp)
)}
end

---@param game MatchGroupUtilGame
---@param opponentIndex integer
---@return Html
Expand All @@ -47,9 +32,11 @@ function CustomMatchSummary._gameScore(game, opponentIndex)
return mw.html.create('div'):wikitext(scoreDisplay)
end

---@param date string
---@param game MatchGroupUtilGame
---@param gameIndex integer
---@return Html?
function CustomMatchSummary._createMapRow(game)
function CustomMatchSummary.createGame(date, game, gameIndex)
if not game.map then
return
end
Expand Down
19 changes: 5 additions & 14 deletions components/match2/wikis/clashofclans/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,13 @@
--

local Abbreviation = require('Module:Abbreviation')
local Array = require('Module:Array')
local DateExt = require('Module:Date/Ext')
local Logic = require('Module:Logic')
local Lua = require('Module:Lua')
local Table = require('Module:Table')

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')

local CustomMatchSummary = {}

Expand Down Expand Up @@ -49,16 +46,6 @@ function CustomMatchSummary.createHeader(match)
return header
end

function CustomMatchSummary.createBody(match)
local showCountdown = match.timestamp ~= DateExt.defaultTimestamp

return MatchSummaryWidgets.Body{children = WidgetUtil.collect(
showCountdown and MatchSummaryWidgets.Row{children = DisplayHelper.MatchCountdownBlock(match)} or nil,
Array.map(match.games, CustomMatchSummary._createMapRow),
MatchSummaryWidgets.Mvp(match.extradata.mvp)
)}
end

function CustomMatchSummary._gameScore(game, opponentIndex)
return mw.html.create('div')
:css('width', '16px')
Expand Down Expand Up @@ -93,7 +80,11 @@ function CustomMatchSummary._time(game, opponentIndex)
:wikitext(Abbreviation.make('(' .. os.date('%M:%S', time) .. ')', 'Total Time'))
end

function CustomMatchSummary._createMapRow(game, gameIndex)
---@param date string
---@param game MatchGroupUtilGame
---@param gameIndex integer
---@return Html?
function CustomMatchSummary.createGame(date, game, gameIndex)
if Table.isEmpty(game.scores) then
return
end
Expand Down
19 changes: 3 additions & 16 deletions components/match2/wikis/criticalops/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,13 @@
-- Please see https://github.com/Liquipedia/Lua-Modules to contribute
--

local Array = require('Module:Array')
local Class = require('Module:Class')
local DateExt = require('Module:Date/Ext')
local Logic = require('Module:Logic')
local Lua = require('Module:Lua')

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')

-- Score Class
---@class CriticalopsScore
Expand Down Expand Up @@ -105,21 +102,11 @@ function CustomMatchSummary.getByMatchId(args)
return MatchSummary.defaultGetByMatchId(CustomMatchSummary, args, {width = '400px'})
end

---@param match MatchGroupUtilMatch
---@return MatchSummaryBody
function CustomMatchSummary.createBody(match)
local showCountdown = match.timestamp ~= DateExt.defaultTimestamp

return MatchSummaryWidgets.Body{children = WidgetUtil.collect(
showCountdown and MatchSummaryWidgets.Row{children = DisplayHelper.MatchCountdownBlock(match)} or nil,
Array.map(match.games, CustomMatchSummary._createMap),
MatchSummaryWidgets.MapVeto(MatchSummary.preProcessMapVeto(match.extradata.mapveto, {game = match.game}))
)}
end

---@param date string
---@param game MatchGroupUtilGame
---@param gameIndex integer
---@return Html?
function CustomMatchSummary._createMap(game)
function CustomMatchSummary.createGame(date, game, gameIndex)
if not game.map then
return
end
Expand Down
20 changes: 3 additions & 17 deletions components/match2/wikis/crossfire/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
-- Please see https://github.com/Liquipedia/Lua-Modules to contribute
--

local Array = require('Module:Array')
local DateExt = require('Module:Date/Ext')
local Logic = require('Module:Logic')
local Lua = require('Module:Lua')
local MapModes = require('Module:MapModes')
Expand All @@ -16,7 +14,6 @@ local String = require('Module:StringUtils')
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')

local CustomMatchSummary = {}

Expand All @@ -26,22 +23,11 @@ function CustomMatchSummary.getByMatchId(args)
return MatchSummary.defaultGetByMatchId(CustomMatchSummary, args)
end

---@param match MatchGroupUtilMatch
---@return MatchSummaryBody
function CustomMatchSummary.createBody(match)
local showCountdown = match.timestamp ~= DateExt.defaultTimestamp

return MatchSummaryWidgets.Body{children = WidgetUtil.collect(
showCountdown and MatchSummaryWidgets.Row{children = DisplayHelper.MatchCountdownBlock(match)} or nil,
Array.map(match.games, CustomMatchSummary._createMapRow),
MatchSummaryWidgets.Mvp(match.extradata.mvp),
MatchSummaryWidgets.Casters{casters = match.extradata.casters}
)}
end

---@param date string
---@param game MatchGroupUtilGame
---@param gameIndex integer
---@return Html?
function CustomMatchSummary._createMapRow(game)
function CustomMatchSummary.createGame(date, game, gameIndex)
if not game.map then
return
end
Expand Down
Loading

0 comments on commit 059640d

Please sign in to comment.