diff --git a/components/match2/commons/match_group_input_util.lua b/components/match2/commons/match_group_input_util.lua index 48e3f8b94e..229579d6aa 100644 --- a/components/match2/commons/match_group_input_util.lua +++ b/components/match2/commons/match_group_input_util.lua @@ -1073,6 +1073,8 @@ end ---@field getHeadToHeadLink? fun(match: table, opponents: table[]): string? ---@field readDate? readDateFunction ---@field getMode? fun(opponents: table[]): string +---@field readOpponent? fun(match: table, opponentIndex: integer, opponentConfig: readOpponentOptions?): +---MGIParsedOpponent ---@field DEFAULT_MODE? string ---@field DATE_FALLBACKS? string[] ---@field OPPONENT_CONFIG? readOpponentOptions @@ -1093,6 +1095,7 @@ end --- - getHeadToHeadLink(match, opponents): string? --- - readDate(match): table --- - getMode(opponents): string? +--- - readOpponent(match, opponentIndex, opponentConfig): MGIParsedOpponent --- --- Additionally, the Parser may have the following properties: --- - DEFAULT_MODE: string @@ -1110,8 +1113,9 @@ function MatchGroupInputUtil.standardProcessMatch(match, Parser, FfaParser, mapP local dateProps = MatchGroupInputUtil.getMatchDate(Parser, matchInput) Table.mergeInto(match, dateProps) + local readOpponent = Parser.readOpponent or MatchGroupInputUtil.readOpponent local opponents = Array.mapIndexes(function(opponentIndex) - local opponent = MatchGroupInputUtil.readOpponent(match, opponentIndex, Parser.OPPONENT_CONFIG) + local opponent = readOpponent(match, opponentIndex, Parser.OPPONENT_CONFIG) if opponent and Parser.adjustOpponent then Parser.adjustOpponent(opponent, opponentIndex) end diff --git a/components/match2/wikis/ageofempires/match_group_input_custom.lua b/components/match2/wikis/ageofempires/match_group_input_custom.lua index 90b3eccdd9..850c09f0b3 100644 --- a/components/match2/wikis/ageofempires/match_group_input_custom.lua +++ b/components/match2/wikis/ageofempires/match_group_input_custom.lua @@ -20,78 +20,36 @@ local Variables = require('Module:Variables') local MatchGroupInputUtil = Lua.import('Module:MatchGroup/Input/Util') local Opponent = Lua.import('Module:Opponent') -local Streams = Lua.import('Module:Links/Stream') local CustomMatchGroupInput = {} -local MapFunctions = { - BREAK_ON_EMPTY = true, -} - local OPPONENT_CONFIG = { resolveRedirect = true, pagifyTeamNames = true, } +local MatchFunctions = { + OPPONENT_CONFIG = OPPONENT_CONFIG, +} +local MapFunctions = { + BREAK_ON_EMPTY = true, +} + ---@param match table ---@param options table? ---@return table function CustomMatchGroupInput.processMatch(match, options) assert(not Logic.readBool(match.ffa), 'FFA is not yet supported in AoE match2.') Table.mergeInto(match, MatchGroupInputUtil.getTournamentContext(match)) - match.game, match.mapsInfo = CustomMatchGroupInput._getMapsAndGame(match) - - Table.mergeInto(match, MatchGroupInputUtil.getMatchDate({}, match)) - - local opponents = Array.mapIndexes(function(opponentIndex) - return CustomMatchGroupInput.readOpponent(match, opponentIndex, OPPONENT_CONFIG) - end) + match.game, match.mapsInfo = MatchFunctions.getGameAndMapsFromTournament(match) - local games = CustomMatchGroupInput.extractMaps(match, opponents) - match.links = MatchGroupInputUtil.getLinks(match) - match.links.headtohead = CustomMatchGroupInput.getHeadToHeadLink(match, opponents) - - local autoScoreFunction = MatchGroupInputUtil.canUseAutoScore(match, games) - and CustomMatchGroupInput.calculateMatchScore(games) - or nil - - Array.forEach(opponents, function(opponent, opponentIndex) - opponent.score, opponent.status = MatchGroupInputUtil.computeOpponentScore({ - walkover = match.walkover, - winner = match.winner, - opponentIndex = opponentIndex, - score = opponent.score, - }, autoScoreFunction) - end) - match.bestof = CustomMatchGroupInput.getBestOf(match.bestof) - - local winnerInput = match.winner --[[@as string?]] - local finishedInput = match.finished --[[@as string?]] - match.finished = MatchGroupInputUtil.matchIsFinished(match, games, opponents) - - if match.finished then - match.status = MatchGroupInputUtil.getMatchStatus(winnerInput, finishedInput) - match.winner = MatchGroupInputUtil.getWinner(match.status, winnerInput, opponents) - Array.forEach(opponents, function(opponent, opponentIndex) - opponent.placement = MatchGroupInputUtil.placementFromWinner(match.status, match.winner, opponentIndex) - end) - end - - match.mode = Opponent.toLegacyMode(opponents[1].type, opponents[2].type) - match.stream = Streams.processStreams(match) - - match.games = games - match.opponents = opponents - - match.extradata = CustomMatchGroupInput._getExtraData(match) - - return match + return MatchGroupInputUtil.standardProcessMatch(match, MatchFunctions) end ---@param match table ---@param opponentIndex integer ---@param options readOpponentOptions ---@return table? -function CustomMatchGroupInput.readOpponent(match, opponentIndex, options) +function MatchFunctions.readOpponent(match, opponentIndex, options) options = options or {} local opponentInput = Json.parseIfString(Table.extract(match, 'opponent' .. opponentIndex)) if not opponentInput then @@ -149,13 +107,14 @@ end ---@param match table ---@param opponents table[] ---@return table[] -function CustomMatchGroupInput.extractMaps(match, opponents) +function MatchFunctions.extractMaps(match, opponents) return MatchGroupInputUtil.standardProcessMaps(match, opponents, MapFunctions) end ---@param bestofInput string|integer? +---@param maps table[] ---@return integer? -function CustomMatchGroupInput.getBestOf(bestofInput) +function MatchFunctions.getBestOf(bestofInput, maps) local bestof = tonumber(bestofInput) or tonumber(Variables.varDefault('bestof')) if bestof then @@ -165,9 +124,15 @@ function CustomMatchGroupInput.getBestOf(bestofInput) return bestof end +---@param opponents table[] +---@return string +function MatchFunctions.getMode(opponents) + return Opponent.toLegacyMode(opponents[1].type, opponents[2].type) +end + ---@param match table ---@return string?, table? -function CustomMatchGroupInput._getMapsAndGame(match) +function MatchFunctions.getGameAndMapsFromTournament(match) local mapsInfo = Json.parseIfString(Variables.varDefault('tournament_maps')) if Logic.isNotEmpty(mapsInfo) and match.game then @@ -196,15 +161,17 @@ end ---@param maps table[] ---@return fun(opponentIndex: integer): integer -function CustomMatchGroupInput.calculateMatchScore(maps) +function MatchFunctions.calculateMatchScore(maps) return function(opponentIndex) return MatchGroupInputUtil.computeMatchScoreFromMapWinners(maps, opponentIndex) end end ---@param match table +---@param games table[] +---@param opponents table[] ---@return table -function CustomMatchGroupInput._getExtraData(match) +function MatchFunctions.getExtraData(match, games, opponents) return { casters = MatchGroupInputUtil.readCasters(match, {noSort = true}), } @@ -213,7 +180,7 @@ end ---@param match table ---@param opponents table[] ---@return string? -function CustomMatchGroupInput.getHeadToHeadLink(match, opponents) +function MatchFunctions.getHeadToHeadLink(match, opponents) if opponents[1].type ~= Opponent.solo or opponents[2].type ~= Opponent.solo then return end