From 11ff7354d4cc2b0e27d8c442a8c7df7d560931b0 Mon Sep 17 00:00:00 2001 From: Rikard Blixt Date: Wed, 6 Nov 2024 13:48:47 +0100 Subject: [PATCH] feat(match2): standardize procesMatch on rocketleague (#5033) * feat(match2): standardize procesMatch on rocketleague * add some bestof calc * fix extradata --- .../match2/commons/match_group_input_util.lua | 8 +- .../rocketleague/match_group_input_custom.lua | 83 +++++-------------- 2 files changed, 30 insertions(+), 61 deletions(-) diff --git a/components/match2/commons/match_group_input_util.lua b/components/match2/commons/match_group_input_util.lua index e9b3dcfc163..656953cc489 100644 --- a/components/match2/commons/match_group_input_util.lua +++ b/components/match2/commons/match_group_input_util.lua @@ -1083,6 +1083,7 @@ end ---@field calculateMatchScore? fun(maps: table[], opponents: table[]): fun(opponentIndex: integer): integer ---@field removeUnsetMaps? fun(maps: table[]): table[] ---@field getExtraData? fun(match: table, games: table[], opponents: table[]): table +---@field adjustOpponent? fun(opponent: MGIParsedOpponent, opponentIndex: integer) ---@field getLinks? fun(match: table, games: table[]): table ---@field DEFAULT_MODE? string ---@field DATE_FALLBACKS? string[] @@ -1098,6 +1099,7 @@ end --- - calculateMatchScore(maps, opponents): fun(opponentIndex): integer --- - removeUnsetMaps(maps): table[] --- - getExtraData(match, games, opponents): table +--- - adjustOpponent(opponent, opponentIndex) --- - getLinks --- --- Additionally, the Parser may have the following properties: @@ -1115,7 +1117,11 @@ function MatchGroupInputUtil.standardProcessMatch(match, Parser, mapProps) Table.mergeInto(match, MatchGroupInputUtil.readDate(match.date, Parser.DATE_FALLBACKS)) local opponents = Array.mapIndexes(function(opponentIndex) - return MatchGroupInputUtil.readOpponent(match, opponentIndex, Parser.OPPONENT_CONFIG) + local opponent = MatchGroupInputUtil.readOpponent(match, opponentIndex, Parser.OPPONENT_CONFIG) + if opponent and Parser.adjustOpponent then + Parser.adjustOpponent(opponent, opponentIndex) + end + return opponent end) local games = Parser.extractMaps(match, opponents, mapProps) diff --git a/components/match2/wikis/rocketleague/match_group_input_custom.lua b/components/match2/wikis/rocketleague/match_group_input_custom.lua index 10d3de39b7a..b2cbab389a3 100644 --- a/components/match2/wikis/rocketleague/match_group_input_custom.lua +++ b/components/match2/wikis/rocketleague/match_group_input_custom.lua @@ -6,13 +6,10 @@ -- Please see https://github.com/Liquipedia/Lua-Modules to contribute -- -local CustomMatchGroupInput = {} - local Array = require('Module:Array') local Logic = require('Module:Logic') local Lua = require('Module:Lua') local Operator = require('Module:Operator') -local Streams = require('Module:Links/Stream') local String = require('Module:StringUtils') local Table = require('Module:Table') local Variables = require('Module:Variables') @@ -20,73 +17,38 @@ local Variables = require('Module:Variables') local MatchGroupInputUtil = Lua.import('Module:MatchGroup/Input/Util') local Opponent = Lua.import('Module:Opponent') -local DEFAULT_MODE = '3v3' +local CustomMatchGroupInput = {} +local MatchFunctions = {} +local MapFunctions = {} local EARNINGS_LIMIT_FOR_FEATURED = 10000 local CURRENT_YEAR = os.date('%Y') +MatchFunctions.DEFAULT_MODE = '3v3' +MatchFunctions.DATE_FALLBACKS = {'tournament_enddate'} +MatchFunctions.getBestOf = MatchGroupInputUtil.getBestOf --- containers for process helper functions -local MatchFunctions = {} -local MapFunctions = {} - --- called from Module:MatchGroup ---@param match table ---@param options table? ---@return table function CustomMatchGroupInput.processMatch(match, options) - local finishedInput = match.finished --[[@as string?]] - local winnerInput = match.winner --[[@as string?]] - - Table.mergeInto(match, MatchGroupInputUtil.readDate(match.date, {'tournament_enddate'})) - - local opponents = Array.mapIndexes(function(opponentIndex) - return MatchGroupInputUtil.readOpponent(match, opponentIndex, {}) - end) - local games = CustomMatchGroupInput.extractMaps(match, #opponents) - match.links = MatchGroupInputUtil.getLinks(match) - match.links.headtohead = MatchFunctions.getHeadToHeadLink(match, opponents) - - Array.forEach(opponents, function(opponent, opponentIndex) - opponent.extradata = CustomMatchGroupInput.getOpponentExtradata(opponent) - if opponent.extradata.additionalScores then - opponent.score = CustomMatchGroupInput._getSetWins(opponent) - end - opponent.score, opponent.status = MatchGroupInputUtil.computeOpponentScore({ - walkover = match.walkover, - winner = match.winner, - opponentIndex = opponentIndex, - score = opponent.score, - }) - end) - - match.finished = MatchGroupInputUtil.matchIsFinished(match, opponents) - - if match.finished then - match.resulttype = MatchGroupInputUtil.getResultType(winnerInput, finishedInput, opponents) - match.walkover = MatchGroupInputUtil.getWalkover(match.resulttype, opponents) - match.winner = MatchGroupInputUtil.getWinner(match.resulttype, winnerInput, opponents) - Array.forEach(opponents, function(opponent, opponentIndex) - opponent.placement = MatchGroupInputUtil.placementFromWinner(match.resulttype, match.winner, opponentIndex) - end) - end - - match.mode = Logic.emptyOr(match.mode, Variables.varDefault('tournament_mode', DEFAULT_MODE)) - Table.mergeInto(match, MatchGroupInputUtil.getTournamentContext(match)) - - match.stream = Streams.processStreams(match) - - match.games = games - match.opponents = opponents - - match.extradata = MatchFunctions.getExtraData(match, opponents) + local parsedMatch = MatchGroupInputUtil.standardProcessMatch(match, MatchFunctions) + parsedMatch.links.headtohead = MatchFunctions.getHeadToHeadLink(match, parsedMatch.opponents) + return parsedMatch +end - return match +---@param opponent MGIParsedOpponent +---@param opponentIndex integer +function MatchFunctions.adjustOpponent(opponent, opponentIndex) + opponent.extradata = CustomMatchGroupInput.getOpponentExtradata(opponent) + if opponent.extradata.additionalScores then + opponent.score = CustomMatchGroupInput._getSetWins(opponent) + end end ---@param match table ----@param opponentCount integer ----@return table -function CustomMatchGroupInput.extractMaps(match, opponentCount) +---@param opponents table[] +---@return table[] +function MatchFunctions.extractMaps(match, opponents) local maps = {} for key, map, mapIndex in Table.iter.pairsByPrefix(match, 'map', {requireIndex = true}) do if map.map == nil then @@ -99,7 +61,7 @@ function CustomMatchGroupInput.extractMaps(match, opponentCount) map.vod = map.vod or String.nilIfEmpty(match['vodgame' .. mapIndex]) map.finished = MatchGroupInputUtil.mapIsFinished(map) - local opponentInfo = Array.map(Array.range(1, opponentCount), function(opponentIndex) + local opponentInfo = Array.map(opponents, function(_, opponentIndex) local score, status = MatchGroupInputUtil.computeOpponentScore({ walkover = map.walkover, winner = map.winner, @@ -178,9 +140,10 @@ function MatchFunctions.getHeadToHeadLink(match, opponents) end ---@param match table +---@param games table[] ---@param opponents table[] ---@return table -function MatchFunctions.getExtraData(match, opponents) +function MatchFunctions.getExtraData(match, games, opponents) return { isfeatured = MatchFunctions.isFeatured(opponents, tonumber(match.liquipediatier)), casters = MatchGroupInputUtil.readCasters(match),