feat: add sort by players option to matchmaker
This commit is contained in:
@@ -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: {
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user