diff --git a/components/match2/wikis/fortnite/match_group_input_custom.lua b/components/match2/wikis/fortnite/match_group_input_custom.lua index ee69c06037..0423c05aa4 100644 --- a/components/match2/wikis/fortnite/match_group_input_custom.lua +++ b/components/match2/wikis/fortnite/match_group_input_custom.lua @@ -12,40 +12,92 @@ local Operator = require('Module:Operator') local MatchGroupInputUtil = Lua.import('Module:MatchGroup/Input/Util') -local MapFunctions = {} +local CustomMatchGroupInput = {} local MatchFunctions = { OPPONENT_CONFIG = { resolveRedirect = true, applyUnderScores = true, maxNumPlayers = 3, }, - DEFAULT_MODE = 'team' + DEFAULT_MODE = 'team', + getBestOf = MatchGroupInputUtil.getBestOf, } - -local CustomMatchGroupInput = {} +local FfaMatchFunctions = {} +local MapFunctions = {} +local FfaMapFunctions = {} ---@param match table ---@param options table? ---@return table function CustomMatchGroupInput.processMatch(match, options) - return MatchGroupInputUtil.standardProcessFfaMatch(match, MatchFunctions) + return MatchGroupInputUtil.standardProcessMatch(match, MatchFunctions, FfaMatchFunctions) end --- --- match related functions --- +--- Normal 2-opponent Match + +---@param match table +---@param opponents table[] +---@return table[] +function MatchFunctions.extractMaps(match, opponents) + return MatchGroupInputUtil.standardProcessMaps(match, opponents, MapFunctions) +end + +---@param match table +---@param games table[] +---@param opponents table[] +---@return table +function MatchFunctions.getExtraData(match, games, opponents) + return { + mvp = MatchGroupInputUtil.readMvp(match, opponents), + casters = MatchGroupInputUtil.readCasters(match), + } +end + +---@param maps table[] +---@return fun(opponentIndex: integer): integer? +function MatchFunctions.calculateMatchScore(maps) + return function(opponentIndex) + return MatchGroupInputUtil.computeMatchScoreFromMapWinners(maps, opponentIndex) + end +end + +---@param match table +---@param map table +---@param opponents table[] +---@return table +function MapFunctions.getExtraData(match, map, opponents) + return { + comment = map.comment, + } +end + +---@param map table +---@return fun(opponentIndex: integer): integer? +function MapFunctions.calculateMapScore(map) + local winner = tonumber(map.winner) + return function(opponentIndex) + -- TODO Better to check if map has started, rather than finished, for a more correct handling + if not winner and not map.finished then + return + end + return winner == opponentIndex and 1 or 0 + end +end + +--- FFA Match + ---@param match table ---@param opponents table[] ---@param scoreSettings table ---@return table[] -function MatchFunctions.extractMaps(match, opponents, scoreSettings) - return MatchGroupInputUtil.standardProcessFfaMaps(match, opponents, scoreSettings, MapFunctions) +function FfaMatchFunctions.extractMaps(match, opponents, scoreSettings) + return MatchGroupInputUtil.standardProcessFfaMaps(match, opponents, scoreSettings, FfaMapFunctions) end ---@param opponents table[] ---@param maps table[] ---@return fun(opponentIndex: integer): integer? -function MatchFunctions.calculateMatchScore(opponents, maps) +function FfaMatchFunctions.calculateMatchScore(opponents, maps) return function(opponentIndex) return Array.reduce(Array.map(maps, function(map) return map.opponents[opponentIndex].score or 0 @@ -58,22 +110,18 @@ end ---@param opponents table[] ---@param settings table ---@return table -function MatchFunctions.getExtraData(match, games, opponents, settings) +function FfaMatchFunctions.getExtraData(match, games, opponents, settings) return { placementinfo = settings.placementInfo, settings = settings.settings, } end --- --- map related functions --- - ---@param match table ---@param map table ---@param opponents table[] ---@return table -function MapFunctions.getExtraData(match, map, opponents) +function FfaMapFunctions.getExtraData(match, map, opponents) return { dateexact = map.dateexact, comment = map.comment, diff --git a/components/match2/wikis/fortnite/match_summary.lua b/components/match2/wikis/fortnite/match_summary.lua new file mode 100644 index 0000000000..a832ade085 --- /dev/null +++ b/components/match2/wikis/fortnite/match_summary.lua @@ -0,0 +1,51 @@ +--- +-- @Liquipedia +-- wiki=fortnite +-- page=Module:MatchSummary +-- +-- Please see https://github.com/Liquipedia/Lua-Modules to contribute +-- + +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') + +local CustomMatchSummary = {} + +---@param args table +---@return Html +function CustomMatchSummary.getByMatchId(args) + return MatchSummary.defaultGetByMatchId(CustomMatchSummary, args) +end + +---@param date string +---@param game MatchGroupUtilGame +---@param gameIndex integer +---@return Widget? +function CustomMatchSummary.createGame(date, game, gameIndex) + if not game.map then + return + end + + local function makeTeamSection(opponentIndex) + return { + MatchSummaryWidgets.GameWinLossIndicator{winner = game.winner, opponentIndex = opponentIndex}, + DisplayHelper.MapScore(game.opponents[opponentIndex], game.status) + } + end + + return MatchSummaryWidgets.Row{ + classes = {'brkts-popup-body-game'}, + children = WidgetUtil.collect( + MatchSummaryWidgets.GameTeamWrapper{children = makeTeamSection(1)}, + MatchSummaryWidgets.GameCenter{children = DisplayHelper.Map(game)}, + MatchSummaryWidgets.GameTeamWrapper{children = makeTeamSection(2), flipped = true}, + MatchSummaryWidgets.GameComment{children = game.comment} + ) + } +end + +return CustomMatchSummary