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
Show file tree
Hide file tree
Changes from 12 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
31 changes: 30 additions & 1 deletion 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 then
fregerson marked this conversation as resolved.
Show resolved Hide resolved
return MatchGroupInputUtil.allHasBeenPlayed(playall, opponents)
end

local bestof = match.bestof
if not bestof then
return false
Expand Down Expand Up @@ -891,13 +896,31 @@ 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)
if scoreSum >= playall then
fregerson marked this conversation as resolved.
Show resolved Hide resolved
return true
end
return false
end

---@param bestOfInput string|integer?
---@param maps table[]
---@return integer?
function MatchGroupInputUtil.getBestOf(bestOfInput, maps)
return tonumber(bestOfInput) or #maps
end

---@param playAllInput string|integer?
---@return integer?
function MatchGroupInputUtil.getPlayAll(playAllInput)
fregerson marked this conversation as resolved.
Show resolved Hide resolved
return tonumber(playAllInput) or 0
end

---@param alias table<string, string>
---@param character string?
---@return string?
Expand Down Expand Up @@ -1046,6 +1069,7 @@ end
---@class MatchParserInterface
---@field extractMaps fun(match: table, opponents: table[], mapProps: any?): table[]
---@field getBestOf fun(bestOfInput: string|integer|nil, maps: table[]): integer?
---@field getPlayAll fun(playAllInput: string|integer|nil): integer?
fregerson marked this conversation as resolved.
Show resolved Hide resolved
---@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?
Expand Down Expand Up @@ -1079,6 +1103,7 @@ end
--- - getHeadToHeadLink(match, opponents): string?
--- - readDate(match): table
--- - getMode(opponents): string?
--- - getPlayAll(playAllinput): integer?
fregerson marked this conversation as resolved.
Show resolved Hide resolved
---
--- Additionally, the Parser may have the following properties:
--- - DEFAULT_MODE: string
Expand Down Expand Up @@ -1141,6 +1166,10 @@ function MatchGroupInputUtil.standardProcessMatch(match, Parser, mapProps)

match.stream = Streams.processStreams(match)
match.extradata = Parser.getExtraData and Parser.getExtraData(match, games, opponents) or {}
local playallData = {
playall = Parser.getPlayAll and Parser.getPlayAll(match.playall) or MatchGroupInputUtil.getPlayAll(match.playall)
}
match.extradata = Table.merge(playallData, match.extradata)
fregerson marked this conversation as resolved.
Show resolved Hide resolved

match.games = games
match.opponents = opponents
Expand Down Expand Up @@ -1383,4 +1412,4 @@ function MatchGroupInputUtil.calculatePlacementOfOpponents(opponents)
end


return MatchGroupInputUtil
return MatchGroupInputUtil
fregerson marked this conversation as resolved.
Show resolved Hide resolved
fregerson marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ end
function CustomMatchGroupInput._getExtraData(match)
return {
casters = MatchGroupInputUtil.readCasters(match, {noSort = true}),
playall = MatchGroupInputUtil.getPlayAll(match.playall)
fregerson marked this conversation as resolved.
Show resolved Hide resolved
}
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ function MatchFunctions.getExtraData(match, opponents, finishedInput)
status = match.status == MatchGroupInputUtil.MATCH_STATUS.NOT_PLAYED and finishedInput or nil,
overturned = Logic.isNotEmpty(match.overturned),
featured = MatchFunctions.isFeatured(match, opponents),
hidden = Logic.readBool(Variables.varDefault('match_hidden'))
hidden = Logic.readBool(Variables.varDefault('match_hidden')),
playall = match.playall
fregerson marked this conversation as resolved.
Show resolved Hide resolved
}
end

Expand Down
2 changes: 1 addition & 1 deletion components/transfer/commons/transfer_references.lua
Original file line number Diff line number Diff line change
Expand Up @@ -311,4 +311,4 @@ function TransferRef._getTextAndLink(reference, options)
end
end

return TransferRef
return TransferRef
fregerson marked this conversation as resolved.
Show resolved Hide resolved
Loading