Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(match2): Support the use of playall instead of bestof #5148

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions components/match2/commons/match_group_input_util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,11 @@ function MatchGroupInputUtil.matchIsFinished(match, opponents)
return true
end

local playall = tonumber(match.playall) or 0
if playall > 0 then
return MatchGroupInputUtil.allHasBeenPlayed(playall, opponents)
end

local bestof = match.bestof
if not bestof then
return false
Expand Down Expand Up @@ -891,6 +896,15 @@ function MatchGroupInputUtil.majorityHasBeenWon(bestof, opponents)
return false
end

-- Check if all games/rounds have been played
---@param playall integer
---@param opponents {score: integer?}[]
---@return boolean
function MatchGroupInputUtil.allHasBeenPlayed(playall, opponents)
local scoreSum = Array.reduce(opponents, function(sum, opponent) return sum + (opponent.score or 0) end, 0)
return scoreSum >= playall
end
fregerson marked this conversation as resolved.
Show resolved Hide resolved

---@param bestOfInput string|integer?
---@param maps table[]
---@return integer?
Expand Down Expand Up @@ -1141,6 +1155,7 @@ function MatchGroupInputUtil.standardProcessMatch(match, Parser, mapProps)

match.stream = Streams.processStreams(match)
match.extradata = Parser.getExtraData and Parser.getExtraData(match, games, opponents) or {}
match.extradata = Table.merge({playall = tonumber(match.playall)}, match.extradata)

match.games = games
match.opponents = opponents
Expand Down
Loading