mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-04-25 07:32:19 -05:00
Fix seeds, SPR & matches played in tournament result page when many starting brackets
Closes #2631
This commit is contained in:
parent
7dd1765442
commit
db9c296094
|
|
@ -55,6 +55,10 @@ export class Tournament {
|
|||
const hasStarted = data.stage.length > 0;
|
||||
|
||||
const teamsInSeedOrder = ctx.teams.sort((a, b) => {
|
||||
if (a.startingBracketIdx !== b.startingBracketIdx) {
|
||||
return (a.startingBracketIdx ?? 0) - (b.startingBracketIdx ?? 0);
|
||||
}
|
||||
|
||||
if (a.seed && b.seed) {
|
||||
return a.seed - b.seed;
|
||||
}
|
||||
|
|
@ -718,11 +722,27 @@ export class Tournament {
|
|||
}
|
||||
|
||||
teamById(id: number) {
|
||||
const teamIdx = this.ctx.teams.findIndex((team) => team.id === id);
|
||||
let result: (typeof this.ctx.teams)[number] | null = null;
|
||||
let seed = 0;
|
||||
let currStartingBracketIdx = this.ctx.teams.at(0)?.startingBracketIdx;
|
||||
|
||||
if (teamIdx === -1) return;
|
||||
for (const team of this.ctx.teams) {
|
||||
if (team.startingBracketIdx !== currStartingBracketIdx) {
|
||||
currStartingBracketIdx = team.startingBracketIdx;
|
||||
seed = 1;
|
||||
} else {
|
||||
seed++;
|
||||
}
|
||||
|
||||
return { ...this.ctx.teams[teamIdx], seed: teamIdx + 1 };
|
||||
if (team.id === id) {
|
||||
result = team;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!result) return;
|
||||
|
||||
return { ...result, seed };
|
||||
}
|
||||
|
||||
participatedPlayersByTeamId(id: number) {
|
||||
|
|
|
|||
|
|
@ -66,13 +66,32 @@ export function matchesPlayed({
|
|||
tournament: Tournament;
|
||||
teamId: number;
|
||||
}) {
|
||||
const brackets = Progression.bracketIdxsForStandings(
|
||||
tournament.ctx.settings.bracketProgression,
|
||||
)
|
||||
const startingBracketIdx = tournament.teamById(teamId)?.startingBracketIdx;
|
||||
|
||||
let bracketIdxs: number[];
|
||||
|
||||
if (typeof startingBracketIdx !== "number" || startingBracketIdx === 0) {
|
||||
bracketIdxs = Progression.bracketIdxsForStandings(
|
||||
tournament.ctx.settings.bracketProgression,
|
||||
);
|
||||
} else {
|
||||
const reachableBrackets = Progression.bracketsReachableFrom(
|
||||
startingBracketIdx,
|
||||
tournament.ctx.settings.bracketProgression,
|
||||
);
|
||||
const reachableSet = new Set(reachableBrackets);
|
||||
|
||||
const allBracketIdxs = tournament.ctx.settings.bracketProgression
|
||||
.map((_, idx) => idx)
|
||||
.sort((a, b) => b - a);
|
||||
bracketIdxs = allBracketIdxs.filter((idx) => reachableSet.has(idx));
|
||||
}
|
||||
|
||||
const brackets = bracketIdxs
|
||||
.reverse()
|
||||
.map((bracketIdx) => tournament.bracketByIdx(bracketIdx)!);
|
||||
|
||||
const matches = brackets.flatMap((bracket, bracketIdx) =>
|
||||
const matches = brackets.flatMap((bracket, i) =>
|
||||
bracket.data.match
|
||||
.filter(
|
||||
(match) =>
|
||||
|
|
@ -82,7 +101,10 @@ export function matchesPlayed({
|
|||
(match.opponent1.result === "win" ||
|
||||
match.opponent2?.result === "win"),
|
||||
)
|
||||
.map((match) => ({ ...match, bracketIdx })),
|
||||
.map((match) => ({
|
||||
...match,
|
||||
bracketIdx: bracketIdxs[bracketIdxs.length - 1 - i],
|
||||
})),
|
||||
);
|
||||
|
||||
return matches.map((match) => {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user