From 7cff3d290e50d8d6e69d88c127ceea0c6ea4179b Mon Sep 17 00:00:00 2001 From: Kalle <38327916+Sendouc@users.noreply.github.com> Date: Thu, 10 Oct 2024 17:40:34 +0300 Subject: [PATCH] Fix prepared maps round robin crash Closes #1919 --- .../tournament-bracket/components/BracketMapListDialog.tsx | 7 +++++-- app/features/tournament-bracket/core/Tournament.ts | 4 +++- app/features/tournament/tournament-constants.ts | 2 ++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/features/tournament-bracket/components/BracketMapListDialog.tsx b/app/features/tournament-bracket/components/BracketMapListDialog.tsx index 0478d3119..9482be4c9 100644 --- a/app/features/tournament-bracket/components/BracketMapListDialog.tsx +++ b/app/features/tournament-bracket/components/BracketMapListDialog.tsx @@ -14,6 +14,7 @@ import { useTournament, useTournamentPreparedMaps, } from "~/features/tournament/routes/to.$id"; +import { TOURNAMENT } from "~/features/tournament/tournament-constants"; import type { TournamentManagerDataSet } from "~/modules/brackets-manager/types"; import type { ModeShort, StageId } from "~/modules/in-game-lists"; import { nullFilledArray } from "~/utils/arrays"; @@ -576,9 +577,11 @@ function teamCountAdjustedBracketData({ // always has the same amount of rounds even if 0 participants return bracket.data; case "round_robin": - // 10 to ensure a full bracket gets generated even if registration is underway + // ensure a full bracket (no bye round) gets generated even if registration is underway return tournament.generateMatchesData( - nullFilledArray(10).map((_, i) => i + 1), + nullFilledArray(TOURNAMENT.DEFAULT_TEAM_COUNT_PER_RR_GROUP).map( + (_, i) => i + 1, + ), bracket.type, ); case "single_elimination": diff --git a/app/features/tournament-bracket/core/Tournament.ts b/app/features/tournament-bracket/core/Tournament.ts index 651333991..52058c09a 100644 --- a/app/features/tournament-bracket/core/Tournament.ts +++ b/app/features/tournament-bracket/core/Tournament.ts @@ -447,7 +447,9 @@ export class Tournament { case "round_robin": return { groupCount: Math.ceil( - participantsCount / (this.ctx.settings.teamsPerGroup ?? 4), + participantsCount / + (this.ctx.settings.teamsPerGroup ?? + TOURNAMENT.DEFAULT_TEAM_COUNT_PER_RR_GROUP), ), seedOrdering: ["groups.seed_optimized"], }; diff --git a/app/features/tournament/tournament-constants.ts b/app/features/tournament/tournament-constants.ts index b48f3121b..76045641d 100644 --- a/app/features/tournament/tournament-constants.ts +++ b/app/features/tournament/tournament-constants.ts @@ -7,6 +7,8 @@ export const TOURNAMENT = { ENOUGH_TEAMS_TO_START: 2, MIN_GROUP_SIZE: 3, MAX_GROUP_SIZE: 6, + // just a fallback, normally this should be set by user explicitly + DEFAULT_TEAM_COUNT_PER_RR_GROUP: 4, } as const; export const BRACKET_NAMES = {