Skip to content

Commit

Permalink
fix(match2): wrong qualified displayed for reset matches (#4866)
Browse files Browse the repository at this point in the history
  • Loading branch information
hjpalpha authored Oct 15, 2024
1 parent c99c786 commit a219cab
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions components/match2/commons/match_group_display_bracket.lua
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ function BracketDisplay.NodeBody(props)
end

-- Include results from bracketResetMatch
---@type MatchGroupUtilMatch?
local bracketResetMatch = match.bracketData.bracketResetMatchId
and props.matchesById[match.bracketData.bracketResetMatchId]
if bracketResetMatch then
Expand Down Expand Up @@ -515,8 +516,9 @@ function BracketDisplay.NodeBody(props)
-- Qualifier entries
local qualWinNode
if match.bracketData.qualWin then
local opponent = match.winner
and match.opponents[match.winner]
local winner = (bracketResetMatch or match).winner
local opponent = winner
and match.opponents[winner]
or MatchGroupUtil.createOpponent({
type = 'literal',
name = match.bracketData.qualWinLiteral or '',
Expand All @@ -532,7 +534,7 @@ function BracketDisplay.NodeBody(props)

local qualLoseNode
if match.bracketData.qualLose then
local opponent = BracketDisplay.getRunnerUpOpponent(match)
local opponent = BracketDisplay.getRunnerUpOpponent(match, bracketResetMatch)
or MatchGroupUtil.createOpponent({
type = 'literal',
name = match.bracketData.qualLoseLiteral or '',
Expand Down Expand Up @@ -783,21 +785,30 @@ function BracketDisplay.ConnectorStub(props)
end

---@param match MatchGroupUtilMatch
---@param bracketResetMatch MatchGroupUtilMatch?
---@return standardOpponent?
function BracketDisplay.getRunnerUpOpponent(match)
function BracketDisplay.getRunnerUpOpponent(match, bracketResetMatch)
-- 2 opponents: the runner up is the one that is not the winner, assuming
-- there is a winner
if #match.opponents == 2 then
return match.winner
and match.opponents[2 + 1 - match.winner]
local winner = (bracketResetMatch or match).winner
return winner
and match.opponents[2 + 1 - winner]
or nil

-- >2 opponents: wait for the match to be finished, then look at the placement field
-- TODO remove match.finished requirement
else
return match.finished
and Array.find(match.opponents, function(opponent) return opponent.placement == 2 end)
or nil
and Array.find(match.opponents, function(opponent)
local place = opponent.placement
-- in case of reset match: need to even overwrite if placement2 is empty
if bracketResetMatch then
place = opponent.placement2
end

return place == 2
end) or nil
end
end

Expand Down

0 comments on commit a219cab

Please sign in to comment.