feat: add sort by players option to matchmaker

This commit is contained in:
2026-04-15 08:28:43 -07:00
parent 6582ddf93a
commit c1d1f6bce3
3 changed files with 16 additions and 2 deletions
+2
View File
@@ -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<AppConfig>({
minRemainingTime: 120,
openServerBrowser: true,
autoJoin: false,
sortByPlayers: false,
},
keybinds: DEFAULT_KEYBINDS,
userscripts: {
+7
View File
@@ -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();
+7 -2
View File
@@ -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<string, number>): MatchmakerGame[] {
function sortGames(games: MatchmakerGame[], pings: Record<string, number>, 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)