Skip to content

Commit

Permalink
feat(match2): standardize procesMatch on rocketleague (#5033)
Browse files Browse the repository at this point in the history
* feat(match2): standardize procesMatch on rocketleague

* add some bestof calc

* fix extradata
  • Loading branch information
Rathoz authored Nov 6, 2024
1 parent 2a7e62d commit 11ff735
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 61 deletions.
8 changes: 7 additions & 1 deletion components/match2/commons/match_group_input_util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
Expand All @@ -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:
Expand All @@ -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)
Expand Down
83 changes: 23 additions & 60 deletions components/match2/wikis/rocketleague/match_group_input_custom.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,87 +6,49 @@
-- 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')

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
Expand All @@ -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,
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit 11ff735

Please sign in to comment.