Skip to content
Open
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
18 changes: 6 additions & 12 deletions lua/wikis/chess/MatchSummary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,30 +46,24 @@ local KING_ICONS = {
},
}

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


Comment thread
Rathoz marked this conversation as resolved.
---@class ChessMatchSummaryGameRowComponentProps: MatchSummaryGameRowComponentProps
local GameRowComponentProps = {}

local ChessMatchSummaryGameRow = MatchSummaryWidgets.GameRow.createComponent(GameRowComponentProps)

---@class ChessCustomMatchSummary: CustomMatchSummaryInterface
local CustomMatchSummary = {
GameRow = ChessMatchSummaryGameRow,
}

---@param args table
---@return VNode
function CustomMatchSummary.getByMatchId(args)
return MatchSummary.defaultGetByMatchId(CustomMatchSummary, args)
end

---@param match MatchGroupUtilMatch
---@return Renderable
function CustomMatchSummary.createGames(match)
return MatchSummaryWidgets.GamesContainer{
children = Array.map(match.games, function (game, gameIndex)
return ChessMatchSummaryGameRow{game = game, gameIndex = gameIndex}
end)
}
end

---@param props MatchSummaryGameRowProps
---@return Renderable?
function GameRowComponentProps.createGameOverview(props)
Expand Down
36 changes: 26 additions & 10 deletions lua/wikis/commons/MatchSummary/Base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ local TBD = Abbreviation.make{text = 'TBD', title = 'To Be Determined'}

---@class CustomMatchSummaryInterface
---@field createBody? fun(match: MatchGroupUtilMatch): Renderable|Renderable[] @deprecated
---@field createGames? fun(match: MatchGroupUtilMatch): Renderable|Renderable[]
---@field createGame? fun(date: string, game: table, gameIndex: integer): Renderable|Renderable[]
---@field createGames? fun(match: MatchGroupUtilMatch): Renderable|Renderable[] @deprecated (but better than createBody)
---@field createGame? fun(date: string, game: table, gameIndex: integer): Renderable|Renderable[] @deprecated
---@field GameRow? Component<MatchSummaryGameRowProps>
---@field createFooter? fun(match: MatchGroupUtilMatch): Renderable|Renderable[]

---@class MatchSummary
Expand Down Expand Up @@ -60,19 +61,33 @@ end

-- Default body function
---@param match MatchGroupUtilMatch
---@param createGames? fun(match: MatchGroupUtilMatch): Renderable|Renderable[]?
---@param createGame? fun(date: string, game: table, gameIndex: integer): Renderable|Renderable[]
---@param CustomMatchSummary CustomMatchSummaryInterface
---@param options {maxBans: integer?}?
---@return Renderable[]
function MatchSummary.createDefaultBody(match, createGames, createGame, options)
function MatchSummary.createDefaultBody(match, CustomMatchSummary, options)
options = options or {}

local characterBansData = MatchSummary.buildCharacterBanData(match.games, options.maxBans or 0)

local createGames = CustomMatchSummary.createGames
local createGame = CustomMatchSummary.createGame

local nodes
if CustomMatchSummary.GameRow then
nodes = MatchSummaryWidgets.GamesContainer{
children = Array.map(match.games, function(game, gameIndex)
return CustomMatchSummary.GameRow{game = game, gameIndex = gameIndex}
end)
}
elseif createGames then
nodes = createGames(match)
else
---@diagnostic disable-next-line: param-type-mismatch fixed in another PR
nodes = Array.map(match.games, FnUtil.curry(createGame, match.date))
end

return WidgetUtil.collect(
--- we assume that createGames and createGame are mutually exclusive, so we can safely call one or the other
---@diagnostic disable-next-line: param-type-mismatch
createGames and createGames(match) or Array.map(match.games, FnUtil.curry(createGame, match.date)),
nodes,
MatchSummaryWidgets.Mvp(match.extradata.mvp),
MatchSummaryWidgets.MapVeto(MatchSummary.preProcessMapVeto(match.extradata.mapveto, {game = match.game})),
MatchSummaryWidgets.CharacterBanTable{bans = characterBansData, date = match.date}
Expand Down Expand Up @@ -191,7 +206,7 @@ function MatchSummary.createMatch(matchData, CustomMatchSummary, options)
MatchSummary.createHeader(matchData, options),
MatchSummaryWidgets.Body{
children = WidgetUtil.collect(
createBody(matchData, CustomMatchSummary.createGames, CustomMatchSummary.createGame, options),
createBody(matchData, CustomMatchSummary, options),
Html.Fragment{
children = {
MatchSummaryWidgets.Casters{casters = matchData.extradata.casters},
Expand Down Expand Up @@ -221,7 +236,8 @@ function MatchSummary.defaultGetByMatchId(CustomMatchSummary, args, options)
(
type(CustomMatchSummary.createBody) == 'function' or
type(CustomMatchSummary.createGame) == 'function' or
type(CustomMatchSummary.createGames) == 'function'
type(CustomMatchSummary.createGames) == 'function' or
CustomMatchSummary.GameRow
),
'One of createBody or createGame or createGames must be implemented in Module:MatchSummary'
)
Expand Down
Loading