Skip to content

Commit 6fb6e85

Browse files
authored
refactor(match2): deprecate createbody (#7969)
* refactor(match2): depricate createbody * chore: update visual snapshots * allow only createGames too * lint * restore heroes * missing anno * chore: update visual snapshots * comments --------- Co-authored-by: Rathoz <3426850+Rathoz@users.noreply.github.com>
1 parent c85b655 commit 6fb6e85

17 files changed

Lines changed: 137 additions & 197 deletions

File tree

‎lua/wikis/ageofempires/MatchSummary.lua‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ end
5353

5454
---@param match MatchGroupUtilMatch
5555
---@return VNode
56-
function CustomMatchSummary.createBody(match)
56+
function CustomMatchSummary.createGames(match)
5757
return MatchSummaryWidgets.GamesContainer{
5858
children = Array.map(match.games, function (game, gameIndex)
5959
if (not game.map) and (not game.winner) and Logic.isEmpty(game.status) and Logic.isDeepEmpty(game.opponents) then

‎lua/wikis/brawlhalla/MatchSummary.lua‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ local Opponent = Lua.import('Module:Opponent/Custom')
2020
local CustomMatchSummary = {}
2121

2222
---@param args table
23-
---@return Widget
23+
---@return Renderable
2424
function CustomMatchSummary.getByMatchId(args)
2525
return MatchSummary.defaultGetByMatchId(CustomMatchSummary, args, {width = '350px', teamStyle = 'bracket'})
2626
end
2727

2828
---@param match MatchGroupUtilMatch
29-
---@return Widget[]
30-
function CustomMatchSummary.createBody(match)
29+
---@return Renderable[]
30+
function CustomMatchSummary.createGames(match)
3131
return WidgetUtil.collect(
3232
CustomMatchSummary._isSolo(match) and Array.map(match.games, CustomMatchSummary._createGame) or nil
3333
)
@@ -43,7 +43,7 @@ function CustomMatchSummary._isSolo(match)
4343
end
4444

4545
---@param game MatchGroupUtilGame
46-
---@return Widget?
46+
---@return Renderable?
4747
function CustomMatchSummary._createGame(game)
4848
if not game.map and not game.winner then return end
4949

‎lua/wikis/commons/MatchSummary/Base.lua‎

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ local MATCH_LINK_PRIORITY = Lua.import('Module:Links/MatchPriorityGroups', {load
3030
local TBD = Abbreviation.make{text = 'TBD', title = 'To Be Determined'}
3131

3232
---@class CustomMatchSummaryInterface
33-
---@field createBody? fun(match: MatchGroupUtilMatch): Renderable|Renderable[]
33+
---@field createBody? fun(match: MatchGroupUtilMatch): Renderable|Renderable[] @deprecated
34+
---@field createGames? fun(match: MatchGroupUtilMatch): Renderable|Renderable[]
3435
---@field createGame? fun(date: string, game: table, gameIndex: integer): Renderable|Renderable[]
3536
---@field createFooter? fun(match: MatchGroupUtilMatch): Renderable|Renderable[]
3637

@@ -59,13 +60,22 @@ end
5960

6061
-- Default body function
6162
---@param match MatchGroupUtilMatch
62-
---@param createGame fun(date: string, game: table, gameIndex: integer): Renderable|Renderable[]
63+
---@param createGames? fun(match: MatchGroupUtilMatch): Renderable|Renderable[]?
64+
---@param createGame? fun(date: string, game: table, gameIndex: integer): Renderable|Renderable[]
65+
---@param options {maxBans: integer?}?
6366
---@return Renderable[]
64-
function MatchSummary.createDefaultBody(match, createGame)
67+
function MatchSummary.createDefaultBody(match, createGames, createGame, options)
68+
options = options or {}
69+
70+
local characterBansData = MatchSummary.buildCharacterBanData(match.games, options.maxBans or 0)
71+
6572
return WidgetUtil.collect(
66-
Array.map(match.games, FnUtil.curry(createGame, match.date)),
73+
--- we assume that createGames and createGame are mutually exclusive, so we can safely call one or the other
74+
---@diagnostic disable-next-line: param-type-mismatch
75+
createGames and createGames(match) or Array.map(match.games, FnUtil.curry(createGame, match.date)),
6776
MatchSummaryWidgets.Mvp(match.extradata.mvp),
68-
MatchSummaryWidgets.MapVeto(MatchSummary.preProcessMapVeto(match.extradata.mapveto, {game = match.game}))
77+
MatchSummaryWidgets.MapVeto(MatchSummary.preProcessMapVeto(match.extradata.mapveto, {game = match.game})),
78+
MatchSummaryWidgets.CharacterBanTable{bans = characterBansData, date = match.date}
6979
)
7080
end
7181

@@ -167,7 +177,7 @@ end
167177
---Default createMatch function for usage in Custom MatchSummary
168178
---@param matchData MatchGroupUtilMatch?
169179
---@param CustomMatchSummary CustomMatchSummaryInterface
170-
---@param options {teamStyle: teamStyle?, noScore: boolean?}?
180+
---@param options {teamStyle: teamStyle?, noScore: boolean?, maxBans: integer?}?
171181
---@return VNode?
172182
function MatchSummary.createMatch(matchData, CustomMatchSummary, options)
173183
if not matchData then
@@ -181,7 +191,7 @@ function MatchSummary.createMatch(matchData, CustomMatchSummary, options)
181191
MatchSummary.createHeader(matchData, options),
182192
MatchSummaryWidgets.Body{
183193
children = WidgetUtil.collect(
184-
createBody(matchData, CustomMatchSummary.createGame),
194+
createBody(matchData, CustomMatchSummary.createGames, CustomMatchSummary.createGame, options),
185195
Html.Fragment{
186196
children = {
187197
MatchSummaryWidgets.Casters{casters = matchData.extradata.casters},
@@ -203,12 +213,17 @@ end
203213
---Default getByMatchId function for usage in Custom MatchSummary
204214
---@param CustomMatchSummary CustomMatchSummaryInterface
205215
---@param args table
206-
---@param options {teamStyle:teamStyle?, width: (fun(match: MatchGroupUtilMatch):string?)|string?, noScore:boolean?}?
216+
---@param options {teamStyle:teamStyle?, width: (fun(match: MatchGroupUtilMatch):string?)|string?,
217+
---noScore:boolean?, maxBans: integer?}?
207218
---@return VNode
208219
function MatchSummary.defaultGetByMatchId(CustomMatchSummary, args, options)
209220
assert(
210-
(type(CustomMatchSummary.createBody) == 'function' or type(CustomMatchSummary.createGame) == 'function'),
211-
'createBody(match) or createGame(date, game, gameIndex) must be implemented in Module:MatchSummary'
221+
(
222+
type(CustomMatchSummary.createBody) == 'function' or
223+
type(CustomMatchSummary.createGame) == 'function' or
224+
type(CustomMatchSummary.createGames) == 'function'
225+
),
226+
'One of createBody or createGame or createGames must be implemented in Module:MatchSummary'
212227
)
213228

214229
options = options or {}

‎lua/wikis/deadlock/MatchSummary.lua‎

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,20 @@ local DeadlockMatchSummaryGameRow = MatchSummaryWidgets.GameRow.createComponent(
3535
---@param args table
3636
---@return Renderable
3737
function CustomMatchSummary.getByMatchId(args)
38-
return MatchSummary.defaultGetByMatchId(CustomMatchSummary, args, {width = '480px', teamStyle = 'bracket'})
38+
local options = {width = '480px', teamStyle = 'bracket', maxBans = MAX_NUM_BANS}
39+
return MatchSummary.defaultGetByMatchId(CustomMatchSummary, args, options)
3940
end
4041

4142
---@param match MatchGroupUtilMatch
42-
---@return VNode[]
43-
function CustomMatchSummary.createBody(match)
44-
local characterBansData = MatchSummary.buildCharacterBanData(match.games, MAX_NUM_BANS)
45-
46-
return {
47-
MatchSummaryWidgets.GamesContainer{
48-
children = Array.map(match.games, function (game, gameIndex)
49-
if game.status == STATUS_NOT_PLAYED then
50-
return
51-
end
52-
return DeadlockMatchSummaryGameRow{game = game, gameIndex = gameIndex}
53-
end)
54-
},
55-
MatchSummaryWidgets.CharacterBanTable{bans = characterBansData, date = match.date}
43+
---@return VNode
44+
function CustomMatchSummary.createGames(match)
45+
return MatchSummaryWidgets.GamesContainer{
46+
children = Array.map(match.games, function (game, gameIndex)
47+
if game.status == STATUS_NOT_PLAYED then
48+
return
49+
end
50+
return DeadlockMatchSummaryGameRow{game = game, gameIndex = gameIndex}
51+
end)
5652
}
5753
end
5854

‎lua/wikis/dota2/MatchSummary.lua‎

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,20 @@ local Dota2MatchSummaryGameRow = MatchSummaryWidgets.GameRow.createComponent(Gam
2929
---@param args table
3030
---@return Renderable
3131
function CustomMatchSummary.getByMatchId(args)
32-
return MatchSummary.defaultGetByMatchId(CustomMatchSummary, args, {width = '400px', teamStyle = 'bracket'})
32+
local options = {width = '400px', teamStyle = 'bracket', maxBans = MAX_NUM_BANS}
33+
return MatchSummary.defaultGetByMatchId(CustomMatchSummary, args, options)
3334
end
3435

3536
---@param match MatchGroupUtilMatch
36-
---@return VNode[]
37-
function CustomMatchSummary.createBody(match)
38-
local characterBansData = MatchSummary.buildCharacterBanData(match.games, MAX_NUM_BANS)
39-
40-
return {
41-
MatchSummaryWidgets.GamesContainer{
42-
children = Array.map(match.games, function (game, gameIndex)
43-
if game.status == STATUS_NOT_PLAYED then
44-
return
45-
end
46-
return Dota2MatchSummaryGameRow{game = game, gameIndex = gameIndex}
47-
end)
48-
},
49-
MatchSummaryWidgets.Mvp(match.extradata.mvp),
50-
MatchSummaryWidgets.CharacterBanTable{bans = characterBansData, date = match.date}
37+
---@return VNode
38+
function CustomMatchSummary.createGames(match)
39+
return MatchSummaryWidgets.GamesContainer{
40+
children = Array.map(match.games, function (game, gameIndex)
41+
if game.status == STATUS_NOT_PLAYED then
42+
return
43+
end
44+
return Dota2MatchSummaryGameRow{game = game, gameIndex = gameIndex}
45+
end)
5146
}
5247
end
5348

‎lua/wikis/easportsfc/MatchSummary.lua‎

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,30 +23,28 @@ local NO_CHECK = '[[File:NoCheck.png|link=]]'
2323
local CustomMatchSummary = {}
2424

2525
---@param args table
26-
---@return Widget
26+
---@return Renderable
2727
function CustomMatchSummary.getByMatchId(args)
2828
return MatchSummary.defaultGetByMatchId(CustomMatchSummary, args)
2929
end
3030

3131
---@param match MatchGroupUtilMatch
32-
---@return Widget[]
33-
function CustomMatchSummary.createBody(match)
32+
---@return Renderable[]
33+
function CustomMatchSummary.createGames(match)
3434
local hasSubMatches = Logic.readBool((match.extradata or {}).hassubmatches)
3535

36-
local games = Array.map(match.games, function(game)
37-
if hasSubMatches then
38-
return CustomMatchSummary._createSubMatch(game, match)
39-
end
40-
return CustomMatchSummary._createGame(game)
41-
end)
42-
4336
return WidgetUtil.collect(
44-
games
37+
Array.map(match.games, function(game)
38+
if hasSubMatches then
39+
return CustomMatchSummary._createSubMatch(game, match)
40+
end
41+
return CustomMatchSummary._createGame(game)
42+
end)
4543
)
4644
end
4745

4846
---@param game MatchGroupUtilGame
49-
---@return MatchSummaryRow
47+
---@return Renderable
5048
function CustomMatchSummary._createGame(game)
5149
return MatchSummaryWidgets.Row{
5250
classes = {'brkts-popup-body-game'},
@@ -63,7 +61,7 @@ end
6361

6462
---@param game MatchGroupUtilGame
6563
---@param match MatchGroupUtilMatch
66-
---@return MatchSummaryRow
64+
---@return Renderable
6765
function CustomMatchSummary._createSubMatch(game, match)
6866
local players = CustomMatchSummary._extractPlayersFromGame(game, match)
6967

@@ -110,7 +108,7 @@ end
110108

111109
---@param game MatchGroupUtilGame
112110
---@param opponentIndex integer
113-
---@return string
111+
---@return string?
114112
function CustomMatchSummary._subMatchPenaltyScore(game, opponentIndex)
115113
local scores = (game.extradata or {}).penaltyscores
116114

@@ -137,7 +135,7 @@ function CustomMatchSummary._players(players, opponentIndex, winner)
137135
:css('text-align', flip and 'right' or 'left')
138136
:css('width', '35%')
139137
:node(OpponentDisplay.BlockPlayers{
140-
opponent = {players = players},
138+
opponent = {players = players, type = 'solo', extradata = {}},
141139
overflow = 'ellipsis',
142140
showLink = true,
143141
})

‎lua/wikis/fighters/MatchSummary.lua‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ end
5959

6060
---@param match MatchGroupUtilMatch
6161
---@return VNode
62-
function CustomMatchSummary.createBody(match)
62+
function CustomMatchSummary.createGames(match)
6363
return MatchSummaryWidgets.GamesContainer{
6464
children = Array.map(match.games, function (game, gameIndex)
6565
if Array.all(game.opponents, function(opponent) return Logic.isDeepEmpty(opponent.players) end) then

‎lua/wikis/heroes/MatchSummary.lua‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ local Logic = Lua.import('Module:Logic')
1313

1414
local MatchSummary = Lua.import('Module:MatchSummary/Base')
1515
local MatchSummaryWidgets = Lua.import('Module:Widget/Match/Summary/All')
16+
1617
local WidgetUtil = Lua.import('Module:Widget/Util')
1718

1819
local MAX_NUM_BANS = 3

‎lua/wikis/honorofkings/MatchSummary.lua‎

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,13 @@ local HoKMatchSummaryGameRow = MatchSummaryWidgets.GameRow.createComponent(GameR
2929
---@param args table
3030
---@return Renderable
3131
function CustomMatchSummary.getByMatchId(args)
32-
return MatchSummary.defaultGetByMatchId(CustomMatchSummary, args, {width = '420px', teamStyle = 'bracket'})
32+
local options = {width = '420px', teamStyle = 'bracket', maxBans = MAX_NUM_BANS}
33+
return MatchSummary.defaultGetByMatchId(CustomMatchSummary, args, options)
3334
end
3435

3536
---@param match MatchGroupUtilMatch
36-
---@return VNode[]
37-
function CustomMatchSummary.createBody(match)
38-
local characterBansData = MatchSummary.buildCharacterBanData(match.games, MAX_NUM_BANS)
39-
37+
---@return VNode
38+
function CustomMatchSummary.createGames(match)
4039
---@param game MatchGroupUtilGame
4140
---@return boolean
4241
local function hasCharacterData(game)
@@ -47,17 +46,13 @@ function CustomMatchSummary.createBody(match)
4746
end)
4847
end
4948

50-
return {
51-
MatchSummaryWidgets.GamesContainer{
52-
children = Array.map(match.games, function (game, gameIndex)
53-
if Logic.isEmpty(game.length) and Logic.isEmpty(game.winner) and not hasCharacterData(game) then
54-
return
55-
end
56-
return HoKMatchSummaryGameRow{game = game, gameIndex = gameIndex}
57-
end)
58-
},
59-
MatchSummaryWidgets.Mvp(match.extradata.mvp),
60-
MatchSummaryWidgets.CharacterBanTable{bans = characterBansData, date = match.date}
49+
return MatchSummaryWidgets.GamesContainer{
50+
children = Array.map(match.games, function (game, gameIndex)
51+
if Logic.isEmpty(game.length) and Logic.isEmpty(game.winner) and not hasCharacterData(game) then
52+
return
53+
end
54+
return HoKMatchSummaryGameRow{game = game, gameIndex = gameIndex}
55+
end)
6156
}
6257
end
6358

‎lua/wikis/lab/MatchSummary.lua‎

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,12 @@ function CustomMatchSummary.getByMatchId(args)
2929
end
3030

3131
---@param match MatchGroupUtilMatch
32-
---@return VNode[]
33-
function CustomMatchSummary.createBody(match)
34-
return {
35-
MatchSummaryWidgets.GamesContainer{
36-
children = Array.map(match.games, function (game, gameIndex)
37-
return LabMatchSummaryGameRow{game = game, gameIndex = gameIndex}
38-
end)
39-
},
40-
MatchSummaryWidgets.Mvp(match.extradata.mvp),
41-
MatchSummaryWidgets.MapVeto(MatchSummary.preProcessMapVeto(match.extradata.mapveto, {game = match.game}))
32+
---@return VNode
33+
function CustomMatchSummary.createGames(match)
34+
return MatchSummaryWidgets.GamesContainer{
35+
children = Array.map(match.games, function (game, gameIndex)
36+
return LabMatchSummaryGameRow{game = game, gameIndex = gameIndex}
37+
end)
4238
}
4339
end
4440

0 commit comments

Comments
 (0)