feat: add sort by players option to matchmaker
This commit is contained in:
@@ -55,6 +55,7 @@ export interface AppConfig {
|
|||||||
minRemainingTime: number;
|
minRemainingTime: number;
|
||||||
openServerBrowser: boolean;
|
openServerBrowser: boolean;
|
||||||
autoJoin: boolean;
|
autoJoin: boolean;
|
||||||
|
sortByPlayers: boolean;
|
||||||
};
|
};
|
||||||
keybinds: {
|
keybinds: {
|
||||||
reload: Keybind;
|
reload: Keybind;
|
||||||
@@ -169,6 +170,7 @@ export const config = new Store<AppConfig>({
|
|||||||
minRemainingTime: 120,
|
minRemainingTime: 120,
|
||||||
openServerBrowser: true,
|
openServerBrowser: true,
|
||||||
autoJoin: false,
|
autoJoin: false,
|
||||||
|
sortByPlayers: false,
|
||||||
},
|
},
|
||||||
keybinds: DEFAULT_KEYBINDS,
|
keybinds: DEFAULT_KEYBINDS,
|
||||||
userscripts: {
|
userscripts: {
|
||||||
|
|||||||
@@ -828,6 +828,13 @@ function buildMatchmakerSection(body: HTMLElement, mmConf: any, bag: SettingsBag
|
|||||||
onChange: (v) => { mm.autoJoin = v; saveMM(); },
|
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) => {
|
body.appendChild(createKeybindRow('Matchmaker Hotkey', 'Key to trigger the custom matchmaker', bag.binds.matchmaker, (b) => {
|
||||||
bag.binds.matchmaker = b;
|
bag.binds.matchmaker = b;
|
||||||
bag.saveBinds();
|
bag.saveBinds();
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ export interface MatchmakerConfig {
|
|||||||
minRemainingTime: number;
|
minRemainingTime: number;
|
||||||
openServerBrowser: boolean;
|
openServerBrowser: boolean;
|
||||||
autoJoin: boolean;
|
autoJoin: boolean;
|
||||||
|
sortByPlayers: boolean;
|
||||||
acceptKey: Keybind;
|
acceptKey: Keybind;
|
||||||
cancelKey: Keybind;
|
cancelKey: Keybind;
|
||||||
}
|
}
|
||||||
@@ -358,8 +359,12 @@ async function fetchAllGames(mmConfig: MatchmakerConfig): Promise<{ all: RawLobb
|
|||||||
return { all, filtered };
|
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) => {
|
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 pingA = pings[a.region] ?? 999;
|
||||||
const pingB = pings[b.region] ?? 999;
|
const pingB = pings[b.region] ?? 999;
|
||||||
if (pingA !== pingB) return pingA - pingB;
|
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');
|
_con?.log('[KCC-MM]', filtered.length, '/', allLobbies.length, 'games passed filters');
|
||||||
|
|
||||||
// Sort immediately — result is ready
|
// Sort immediately — result is ready
|
||||||
if (filtered.length > 0) sortByPingThenPlayers(filtered, pings);
|
if (filtered.length > 0) sortGames(filtered, pings, mmConfig.sortByPlayers);
|
||||||
popupCandidates = filtered;
|
popupCandidates = filtered;
|
||||||
|
|
||||||
// Fire animation in background (non-blocking eye candy)
|
// Fire animation in background (non-blocking eye candy)
|
||||||
|
|||||||
Reference in New Issue
Block a user