From c1d1f6bce3d297a389d3d0d90931612696d8a30d Mon Sep 17 00:00:00 2001 From: bigjakk Date: Wed, 15 Apr 2026 08:28:43 -0700 Subject: [PATCH] feat: add sort by players option to matchmaker --- src/main/config.ts | 2 ++ src/preload/index.ts | 7 +++++++ src/preload/matchmaker.ts | 9 +++++++-- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/main/config.ts b/src/main/config.ts index e516b48..e3249f4 100644 --- a/src/main/config.ts +++ b/src/main/config.ts @@ -55,6 +55,7 @@ export interface AppConfig { minRemainingTime: number; openServerBrowser: boolean; autoJoin: boolean; + sortByPlayers: boolean; }; keybinds: { reload: Keybind; @@ -169,6 +170,7 @@ export const config = new Store({ minRemainingTime: 120, openServerBrowser: true, autoJoin: false, + sortByPlayers: false, }, keybinds: DEFAULT_KEYBINDS, userscripts: { diff --git a/src/preload/index.ts b/src/preload/index.ts index 359421f..73c4ae6 100644 --- a/src/preload/index.ts +++ b/src/preload/index.ts @@ -828,6 +828,13 @@ function buildMatchmakerSection(body: HTMLElement, mmConf: any, bag: SettingsBag onChange: (v) => { mm.autoJoin = v; saveMM(); }, })); + body.appendChild(createToggleRow({ + label: 'Prioritize Player Count', + desc: 'Sort results by most players first, then by ping (default is ping first)', + checked: mm.sortByPlayers ?? false, instant: true, + onChange: (v) => { mm.sortByPlayers = v; saveMM(); }, + })); + body.appendChild(createKeybindRow('Matchmaker Hotkey', 'Key to trigger the custom matchmaker', bag.binds.matchmaker, (b) => { bag.binds.matchmaker = b; bag.saveBinds(); diff --git a/src/preload/matchmaker.ts b/src/preload/matchmaker.ts index e80a224..363ccc3 100644 --- a/src/preload/matchmaker.ts +++ b/src/preload/matchmaker.ts @@ -66,6 +66,7 @@ export interface MatchmakerConfig { minRemainingTime: number; openServerBrowser: boolean; autoJoin: boolean; + sortByPlayers: boolean; acceptKey: Keybind; cancelKey: Keybind; } @@ -358,8 +359,12 @@ async function fetchAllGames(mmConfig: MatchmakerConfig): Promise<{ all: RawLobb return { all, filtered }; } -function sortByPingThenPlayers(games: MatchmakerGame[], pings: Record): MatchmakerGame[] { +function sortGames(games: MatchmakerGame[], pings: Record, sortByPlayers: boolean): MatchmakerGame[] { return games.sort((a, b) => { + if (sortByPlayers) { + if (a.playerCount !== b.playerCount) return b.playerCount - a.playerCount; + return (pings[a.region] ?? 999) - (pings[b.region] ?? 999); + } const pingA = pings[a.region] ?? 999; const pingB = pings[b.region] ?? 999; if (pingA !== pingB) return pingA - pingB; @@ -406,7 +411,7 @@ export async function fetchGame(mmConfig: MatchmakerConfig, _con?: SavedConsole) _con?.log('[KCC-MM]', filtered.length, '/', allLobbies.length, 'games passed filters'); // Sort immediately — result is ready - if (filtered.length > 0) sortByPingThenPlayers(filtered, pings); + if (filtered.length > 0) sortGames(filtered, pings, mmConfig.sortByPlayers); popupCandidates = filtered; // Fire animation in background (non-blocking eye candy)