From 1aff3ba353730643da27b75d234339f1afeb962f Mon Sep 17 00:00:00 2001 From: VariableVince <24507472+VariableVince@users.noreply.github.com> Date: Fri, 3 Apr 2026 04:43:34 +0200 Subject: [PATCH] Make sure 1 in 3 games stays Compact by capturing playlist length before while loop --- src/server/MapPlaylist.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/server/MapPlaylist.ts b/src/server/MapPlaylist.ts index 3e9e96f15..5bc7cdc7b 100644 --- a/src/server/MapPlaylist.ts +++ b/src/server/MapPlaylist.ts @@ -156,9 +156,14 @@ export class MapPlaylist { const maxAttempts = 6; let attempts = 0; + // Capture playlist length because isCompact decision depends on it in buildConfig, and + // cycleNextMap could modify playlist length via generateNewPlaylist + this.ensurePlaylistPopulated(type); + const playlistLength = this.playlists[type].length; + while (true) { const map = this.peekNextMap(type); - const config = await this.buildConfig(type, map); + const config = await this.buildConfig(type, map, playlistLength); attempts++; if (notInUse(config) || attempts >= maxAttempts) { @@ -173,6 +178,7 @@ export class MapPlaylist { private async buildConfig( type: PublicGameType, map: GameMapType, + playlistLength: number = this.playlists[type].length, ): Promise { if (type === "special") { return this.buildSpecialConfig(map); @@ -182,8 +188,7 @@ export class MapPlaylist { const playerTeams = mode === GameMode.Team ? this.getTeamCount(map) : undefined; - let isCompact: boolean | undefined = - this.playlists[type].length % 3 === 0 || undefined; + let isCompact: boolean | undefined = playlistLength % 3 === 0 || undefined; if ( isCompact && mode === GameMode.Team &&