diff --git a/components/match2/commons/match_group_input_util.lua b/components/match2/commons/match_group_input_util.lua index e8bb68d6e5..fe223bcdb6 100644 --- a/components/match2/commons/match_group_input_util.lua +++ b/components/match2/commons/match_group_input_util.lua @@ -1159,7 +1159,7 @@ end ---@class MapParserInterface ---@field calculateMapScore? fun(map: table): fun(opponentIndex: integer): integer? ---@field getExtraData? fun(match: table, game: table, opponents: table[]): table? ----@field getMapName? fun(game: table, mapIndex: integer, match: table): string? +---@field getMapName? fun(game: table, mapIndex: integer, match: table): string?, string? ---@field getMapMode? fun(match: table, game: table, opponents: table[]): string? ---@field getPlayersOfMapOpponent? fun(game: table, opponent:table, opponentIndex: integer): table[] ---@field getPatch? fun(game: table): string? @@ -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 @@ -1175,7 +1176,7 @@ end --- The Parser injection may optionally have the following functions: --- - calculateMapScore(map): fun(opponentIndex): integer? --- - getExtraData(match, map, opponents): table? ---- - getMapName(map): string? +--- - getMapName(map, mapIndex, match): string?, string? --- - getMapMode(match, map, opponents): string? --- - getPlayersOfMapOpponent(map, opponent, opponentIndex): table[]? --- - getPatch(game): string? @@ -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? @@ -1207,7 +1209,7 @@ function MatchGroupInputUtil.standardProcessMaps(match, opponents, Parser) end if Parser.getMapName then - map.map = Parser.getMapName(map, mapIndex, match) + map.map, map.mapDisplayName = Parser.getMapName(map, mapIndex, match) end if Parser.getMapBestOf then @@ -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({ @@ -1254,7 +1260,10 @@ function MatchGroupInputUtil.standardProcessMaps(match, opponents, Parser) map.winner = MatchGroupInputUtil.getWinner(map.status, winnerInput, map.opponents) end - map.extradata = Parser.getExtraData and Parser.getExtraData(match, map, opponents) or nil + map.extradata = Table.merge( + {displayname = map.mapDisplayName}, + Parser.getExtraData and Parser.getExtraData(match, map, opponents) or nil + ) table.insert(maps, map) match[key] = nil diff --git a/components/match2/commons/starcraft_starcraft2/match_group_input_starcraft.lua b/components/match2/commons/starcraft_starcraft2/match_group_input_starcraft.lua index 525466a0fb..bca824f990 100644 --- a/components/match2/commons/starcraft_starcraft2/match_group_input_starcraft.lua +++ b/components/match2/commons/starcraft_starcraft2/match_group_input_starcraft.lua @@ -375,7 +375,6 @@ end function MapFunctions.getExtraData(match, map, opponents) local extradata = { comment = map.comment, - displayname = map.mapDisplayName, header = map.header, server = map.server, } @@ -420,10 +419,11 @@ end ---@param gameIndex table ---@param match table ---@return string? +---@return string? function MapFunctions.getMapName(game, gameIndex, match) local mapName = game.map if mapName and mapName:upper() ~= TBD then - return mw.ext.TeamLiquidIntegration.resolve_redirect(game.map) + return mw.ext.TeamLiquidIntegration.resolve_redirect(game.map), game.mapDisplayName elseif mapName then return TBD end diff --git a/components/match2/wikis/ageofempires/match_group_input_custom.lua b/components/match2/wikis/ageofempires/match_group_input_custom.lua index 1a64ae5caa..5aa290cab3 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 @@ -294,7 +263,7 @@ end ---@param opponent table ---@param opponentIndex integer ---@return {civ: string?, flag: string?, displayName: string?, pageName: string?}[] -function CustomMatchGroupInput.getPlayersOfMapOpponent(map, opponent, opponentIndex) +function MapFunctions.getPlayersOfMapOpponent(map, opponent, opponentIndex) local players if opponent.type == Opponent.team then players = Array.parseCommaSeparatedString(map['players' .. opponentIndex]) @@ -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.varDefault('tournament_game')) +end + return CustomMatchGroupInput diff --git a/components/match2/wikis/brawlhalla/match_group_input_custom.lua b/components/match2/wikis/brawlhalla/match_group_input_custom.lua index 7bad9eedd2..a2b3c1ad13 100644 --- a/components/match2/wikis/brawlhalla/match_group_input_custom.lua +++ b/components/match2/wikis/brawlhalla/match_group_input_custom.lua @@ -97,6 +97,7 @@ end ---@param mapIndex integer ---@param match table ---@return string? +---@return string? function MapFunctions.getMapName(map, mapIndex, match) if String.isNotEmpty(map.map) and map.map ~= 'TBD' then return mw.ext.TeamLiquidIntegration.resolve_redirect(map.map) diff --git a/components/match2/wikis/clashofclans/match_group_input_custom.lua b/components/match2/wikis/clashofclans/match_group_input_custom.lua index 05a2a7e9d3..c1497733c8 100644 --- a/components/match2/wikis/clashofclans/match_group_input_custom.lua +++ b/components/match2/wikis/clashofclans/match_group_input_custom.lua @@ -82,6 +82,7 @@ end ---@param mapIndex integer ---@param match table ---@return string? +---@return string? function MapFunctions.getMapName(map, mapIndex, match) return nil end diff --git a/components/match2/wikis/deadlock/match_group_input_custom.lua b/components/match2/wikis/deadlock/match_group_input_custom.lua index 0a68ee6a38..042442b2da 100644 --- a/components/match2/wikis/deadlock/match_group_input_custom.lua +++ b/components/match2/wikis/deadlock/match_group_input_custom.lua @@ -58,6 +58,7 @@ end ---@param mapIndex table ---@param match table ---@return string? +---@return string? function MapFunctions.getMapName(map, mapIndex, match) return nil end diff --git a/components/match2/wikis/easportsfc/match_group_input_custom.lua b/components/match2/wikis/easportsfc/match_group_input_custom.lua index 917ed46133..d111ddb6a7 100644 --- a/components/match2/wikis/easportsfc/match_group_input_custom.lua +++ b/components/match2/wikis/easportsfc/match_group_input_custom.lua @@ -136,6 +136,7 @@ end ---@param mapIndex integer ---@param match table ---@return string +---@return string? function MapFunctions.getMapName(map, mapIndex, match) if Logic.readBool(match.hasSubmatches) then -- generic map name (not displayed) diff --git a/components/match2/wikis/honorofkings/match_group_input_custom.lua b/components/match2/wikis/honorofkings/match_group_input_custom.lua index f18265845d..037826c0d2 100644 --- a/components/match2/wikis/honorofkings/match_group_input_custom.lua +++ b/components/match2/wikis/honorofkings/match_group_input_custom.lua @@ -85,6 +85,7 @@ end ---@param mapIndex integer ---@param match table ---@return string? +---@return string? function MapFunctions.getMapName(map, mapIndex, match) if map.map == DUMMY_MAP then return nil diff --git a/components/match2/wikis/magic/match_group_input_custom.lua b/components/match2/wikis/magic/match_group_input_custom.lua index db4d71b335..71f982d943 100644 --- a/components/match2/wikis/magic/match_group_input_custom.lua +++ b/components/match2/wikis/magic/match_group_input_custom.lua @@ -96,6 +96,7 @@ end ---@param mapIndex integer ---@param match table ---@return string? +---@return string? function MapFunctions.getMapName(map, mapIndex, match) return nil end diff --git a/components/match2/wikis/stormgate/match_group_input_custom.lua b/components/match2/wikis/stormgate/match_group_input_custom.lua index 2247266271..c8ae540679 100644 --- a/components/match2/wikis/stormgate/match_group_input_custom.lua +++ b/components/match2/wikis/stormgate/match_group_input_custom.lua @@ -161,10 +161,11 @@ end ---@param gameIndex integer ---@param match table ---@return string? +---@return string? function MapFunctions.getMapName(game, gameIndex, match) local mapName = game.map if mapName and mapName:upper() ~= TBD then - return mw.ext.TeamLiquidIntegration.resolve_redirect(game.map) + return mw.ext.TeamLiquidIntegration.resolve_redirect(game.map), game.mapDisplayName elseif mapName then return TBD end @@ -305,7 +306,6 @@ end function MapFunctions.getExtraData(match, map, opponents) local extradata = { comment = map.comment, - displayname = map.mapDisplayName, header = map.header, } diff --git a/components/match2/wikis/tetris/match_group_input_custom.lua b/components/match2/wikis/tetris/match_group_input_custom.lua index e3906fa62a..57c0b4469a 100644 --- a/components/match2/wikis/tetris/match_group_input_custom.lua +++ b/components/match2/wikis/tetris/match_group_input_custom.lua @@ -95,6 +95,7 @@ end ---@param mapIndex integer ---@param match table ---@return string? +---@return string? function MapFunctions.getMapName(map, mapIndex, match) return nil end diff --git a/components/match2/wikis/warcraft/match_group_input_custom.lua b/components/match2/wikis/warcraft/match_group_input_custom.lua index a52b86bfa0..c0134e8797 100644 --- a/components/match2/wikis/warcraft/match_group_input_custom.lua +++ b/components/match2/wikis/warcraft/match_group_input_custom.lua @@ -195,8 +195,9 @@ end ---@param gameIndex integer ---@param match table ---@return string? +---@return string? function MapFunctions.getMapName(game, gameIndex, match) - return (MapsData[(game.map or ''):lower()] or {}).name or game.map + return (MapsData[(game.map or ''):lower()] or {}).name or game.map, game.mapDisplayName end ---@param map table @@ -337,7 +338,6 @@ end function MapFunctions.getExtraData(match, map, opponents) local extradata = { comment = map.comment, - displayname = map.mapDisplayName, header = map.header, }