From f1c0cd99ab0b51f6b01a03d78cb94551e03e2475 Mon Sep 17 00:00:00 2001 From: hjpalpha Date: Mon, 16 Dec 2024 14:46:42 +0100 Subject: [PATCH] aoe use `standardProcessMaps` --- .../match2/commons/match_group_input_util.lua | 8 ++- .../ageofempires/match_group_input_custom.lua | 66 ++++++------------- 2 files changed, 28 insertions(+), 46 deletions(-) diff --git a/components/match2/commons/match_group_input_util.lua b/components/match2/commons/match_group_input_util.lua index 48db275135..d1bc8f5d93 100644 --- a/components/match2/commons/match_group_input_util.lua +++ b/components/match2/commons/match_group_input_util.lua @@ -1167,6 +1167,7 @@ end ---@field extendMapOpponent? fun(map: table, opponentIndex: integer): table ---@field getMapBestOf? fun(map: table): integer? ---@field computeOpponentScore? fun(props: table, autoScore?: fun(opponentIndex: integer):integer?): integer?, string? +---@field getGame? fun(match: table, map:table): string? ---@field ADD_SUB_GROUP? boolean ---@field BREAK_ON_EMPTY? boolean @@ -1183,6 +1184,7 @@ end --- - extendMapOpponent(map, opponentIndex): table --- - getMapBestOf(map): integer? --- - computeOpponentScore(props, autoScore): integer?, string? +--- - getGame(match, map): string? --- --- Additionally, the Parser may have the following properties: --- - ADD_SUB_GROUP boolean? @@ -1224,6 +1226,10 @@ function MatchGroupInputUtil.standardProcessMaps(match, opponents, Parser) map.patch = Parser.getPatch(map) end + if Parser.getGame then + map.game = Parser.getGame(match, map) + end + map.opponents = Array.map(opponents, function(opponent, opponentIndex) local computeOpponentScore = Parser.computeOpponentScore or MatchGroupInputUtil.computeOpponentScore local score, status = computeOpponentScore({ @@ -1269,7 +1275,7 @@ end ---@class FfaMatchParserInterface ---@field extractMaps fun(match: table, opponents: table[], mapProps: any?): table[] ---@field parseSettings? fun(match: table, opponentCount: integer): table ----@field calculateMatchScore? fun(maps: table[], opponents table[]): fun(opponentIndex: integer): integer? +---@field calculateMatchScore? fun(maps: table[], opponents: table[]): fun(opponentIndex: integer): integer? ---@field getExtraData? fun(match: table, games: table[], opponents: table[], settings: table): table? ---@field getMode? fun(opponents: table[]): string ---@field readDate? fun(match: table): table diff --git a/components/match2/wikis/ageofempires/match_group_input_custom.lua b/components/match2/wikis/ageofempires/match_group_input_custom.lua index 1a64ae5caa..03197adea5 100644 --- a/components/match2/wikis/ageofempires/match_group_input_custom.lua +++ b/components/match2/wikis/ageofempires/match_group_input_custom.lua @@ -23,7 +23,9 @@ local Opponent = Lua.import('Module:Opponent') local Streams = Lua.import('Module:Links/Stream') local CustomMatchGroupInput = {} -local MapFunctions = {} +local MapFunctions = { + BREAK_ON_EMPTY = true, +} local OPPONENT_CONFIG = { resolveRedirect = true, @@ -148,43 +150,7 @@ end ---@param opponents table[] ---@return table[] function CustomMatchGroupInput.extractMaps(match, opponents) - local maps = {} - for key, map in Table.iter.pairsByPrefix(match, 'map', {requireIndex = true}) do - if map.map == nil and map.winner == nil then - break - end - local finishedInput = map.finished --[[@as string?]] - local winnerInput = map.winner --[[@as string?]] - - map.extradata = MapFunctions.getExtraData(match, map, opponents) - map.map, map.extradata.displayname = CustomMatchGroupInput._getMapName(map, match.mapsInfo) - map.extradata.mapmode = Table.extract(map, 'mode') - - Table.mergeInto(map, MatchGroupInputUtil.getTournamentContext(map, match)) - - map.finished = MatchGroupInputUtil.mapIsFinished(map) - map.opponents = Array.map(opponents, function(opponent, opponentIndex) - local score, status = MatchGroupInputUtil.computeOpponentScore({ - walkover = map.walkover, - winner = map.winner, - opponentIndex = opponentIndex, - score = map['score' .. opponentIndex], - }, CustomMatchGroupInput.calculateMapScore(map.winner, map.finished)) - local players = CustomMatchGroupInput.getPlayersOfMapOpponent(map, opponent, opponentIndex) - return {score = score, status = status, players = players} - end) - - map.scores = Array.map(map.opponents, Operator.property('score')) - if map.finished then - map.status = MatchGroupInputUtil.getMatchStatus(winnerInput, finishedInput) - map.winner = MatchGroupInputUtil.getWinner(map.status, winnerInput, map.opponents) - end - - table.insert(maps, map) - match[key] = nil - end - - return maps + return MatchGroupInputUtil.standardProcessMaps(match, opponents, MapFunctions) end ---@param bestofInput string|integer? @@ -268,10 +234,13 @@ function CustomMatchGroupInput.getHeadToHeadLink(match, opponents) end ---@param map table ----@param mapsInfo {name: string, link: string}[]? +---@param mapIndex integer +---@param match table ---@return string? ---@return string? -function CustomMatchGroupInput._getMapName(map, mapsInfo) +function MapFunctions.getMapName(map, mapIndex, match) + ---@type {name: string, link: string}[]? + local mapsInfo = match.mapsInfo if String.isEmpty(map.map) or map.map == 'TBD' then return end @@ -325,14 +294,13 @@ function CustomMatchGroupInput.getPlayersOfMapOpponent(map, opponent, opponentIn end ----@param winnerInput string|integer|nil ----@param finished boolean +---@param map table ---@return fun(opponentIndex: integer): integer? -function CustomMatchGroupInput.calculateMapScore(winnerInput, finished) - local winner = tonumber(winnerInput) +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 finished then + if not winner and not map.finished then return end return winner == opponentIndex and 1 or 0 @@ -346,7 +314,15 @@ end function MapFunctions.getExtraData(match, map, opponents) return { comment = map.comment, + mapmode = Table.extract(map, 'mode'), } end +---@param match table +---@param map table +---@return string? +function MapFunctions.getGame(match, map) + return Logic.emptyOr(map.game, match.game, Variables.varGet('tournament_game')) +end + return CustomMatchGroupInput