Skip to content

Commit

Permalink
Match.playall as a Boolean
Browse files Browse the repository at this point in the history
  • Loading branch information
fregerson committed Dec 11, 2024
1 parent 6124f3a commit 8b5e784
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions components/match2/commons/match_group_input_util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -837,9 +837,9 @@ function MatchGroupInputUtil.matchIsFinished(match, opponents)
return true
end

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

local bestof = match.bestof
Expand Down Expand Up @@ -896,13 +896,10 @@ function MatchGroupInputUtil.majorityHasBeenWon(bestof, opponents)
return false
end

-- Check if all games/rounds have been played
---@param playall integer
---@param opponents {score: integer?}[]
---@param games table[]
---@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
function MatchGroupInputUtil.allHasBeenPlayed(games)
return Array.all(games, function(game) return game.finished end)
end

---@param bestOfInput string|integer?
Expand Down Expand Up @@ -1155,7 +1152,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.extradata = Table.merge({playall = Logic.readBoolOrNil(match.playall)}, match.extradata)

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

0 comments on commit 8b5e784

Please sign in to comment.