Skip to content

Commit

Permalink
feat(match2): standardize processMatch on halo (#5030)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rathoz authored Nov 6, 2024
1 parent 4a7357f commit b6474b9
Showing 1 changed file with 11 additions and 63 deletions.
74 changes: 11 additions & 63 deletions components/match2/wikis/halo/match_group_input_custom.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,90 +7,39 @@
--

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 Table = require('Module:Table')
local Variables = require('Module:Variables')

local MatchGroupInputUtil = Lua.import('Module:MatchGroup/Input/Util')
local OpponentLibrary = require('Module:OpponentLibraries')
local Opponent = OpponentLibrary.Opponent

local DEFAULT_BESTOF = 3
local DEFAULT_MODE = 'team'

-- containers for process helper functions
local CustomMatchGroupInput = {}
local MatchFunctions = {}
local MapFunctions = {}

local CustomMatchGroupInput = {}
local DEFAULT_BESTOF = 3
MatchFunctions.DEFAULT_MODE = 'team'

-- 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))

local opponents = Array.mapIndexes(function(opponentIndex)
return MatchGroupInputUtil.readOpponent(match, opponentIndex, {})
end)

local games = MatchFunctions.extractMaps(match, #opponents)
match.links = MatchGroupInputUtil.getLinks(match)
match.links.headtohead = MatchFunctions.getHeadToHeadLink(match, opponents)

match.bestof = MatchFunctions.getBestOf(match.bestof)

local autoScoreFunction = MatchGroupInputUtil.canUseAutoScore(match, games)
and MatchFunctions.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.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)

return match
local parsedMatch = MatchGroupInputUtil.standardProcessMatch(match, MatchFunctions)
parsedMatch.links.headtohead = MatchFunctions.getHeadToHeadLink(match, parsedMatch.opponents)
return parsedMatch
end

--
-- match related functions
--

---@param match table
---@param opponentCount integer
---@param opponents table[]
---@return table[]
function MatchFunctions.extractMaps(match, opponentCount)
function MatchFunctions.extractMaps(match, opponents)
local maps = {}
for key, map in Table.iter.pairsByPrefix(match, 'map', {requireIndex = true}) do
if not map.map then
Expand All @@ -99,10 +48,10 @@ function MatchFunctions.extractMaps(match, opponentCount)
local finishedInput = map.finished --[[@as string?]]
local winnerInput = map.winner --[[@as string?]]

map.extradata = MapFunctions.getExtraData(map, opponentCount)
map.extradata = MapFunctions.getExtraData(map)
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 @@ -195,9 +144,8 @@ end
--

---@param map table
---@param opponentCount integer
---@return table
function MapFunctions.getExtraData(map, opponentCount)
function MapFunctions.getExtraData(map)
return {
comment = map.comment,
points1 = map.points1,
Expand Down

0 comments on commit b6474b9

Please sign in to comment.