Skip to content

Commit b0553cb

Browse files
committed
Fix custom games not getting sorted on adding
1 parent a47a8a9 commit b0553cb

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/components/launchers/find-games.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const { sha256 } = require('../modules/sha256.js');
88

99
const processes = new Map();
1010
let loads = 0;
11+
let __CACHE__ = [];
1112

1213
async function getInstalledGames(launchers = ['CustomGames', 'EpicGames.js', 'Lutris.js', 'Minecraft.js', 'RiotGames.js', 'RockstarGames.js', 'Steam.js', 'Uplay.js']) {
1314
document.getElementById("loadingbtn").style.opacity = '1';
@@ -57,7 +58,7 @@ async function filterAndSort(games, type, list, stored) {
5758
}
5859

5960
if (type === 'allGamesList') {
60-
return games.map(x => x.DisplayName).sort().map(x => games[games.findIndex(y => y.DisplayName === x)]);
61+
games = games.map(x => x.DisplayName).sort().map(x => games[games.findIndex(y => y.DisplayName === x)]);
6162
}
6263
else if (['recentGamesListMainPage', 'recentGamesList'].includes(type)) {
6364
let final = [];
@@ -75,19 +76,21 @@ async function filterAndSort(games, type, list, stored) {
7576
return 0;
7677
}
7778
});
78-
return final.slice(0, type.includes('MainPage') ? 5 - list.children.length : final.length);
79+
games = final.slice(0, type.includes('MainPage') ? 5 - list.children.length : final.length);
7980
}
8081
else if (type === 'favGamesList') {
8182
let final = [];
8283
for (let i = 0; i < games.length; i++) {
8384
const game = stored?.find(x => x.GameID === games[i].GameID && x.LauncherName === games[i].LauncherName) ?? await getGames(games[i].GameID, games[i].LauncherName);
8485
if (typeof game?.Favourite === 'boolean' && game.Favourite === true) final.push(game);
8586
}
86-
return final.map(x => x.DisplayName).sort().map(x => final[final.findIndex(y => y.DisplayName === x)]);
87+
games = final.map(x => x.DisplayName).sort().map(x => final[final.findIndex(y => y.DisplayName === x)]);
8788
}
8889
else {
8990
return [];
9091
}
92+
__CACHE__ = games;
93+
return games;
9194
}
9295

9396
async function loadGames(id, data, stored) {
@@ -411,6 +414,12 @@ class Elements {
411414
}
412415

413416
static async createGameElement(game, id, list, prev) {
417+
if (game.LauncherName === 'CustomGame' && !prev) {
418+
prev = __CACHE__;
419+
prev.push(game);
420+
const filtered = (await filterAndSort(prev, 'allGamesList', list)).reverse();
421+
prev = filtered[filtered.findIndex(x => Object.keys(game).every(y => game[y] === x[y])) - 1];
422+
}
414423
list = document.getElementById(id);
415424
const gameElement = Elements.getGameElement(game, id);
416425
if (prev && !list.children.namedItem(`game-div-${game.DisplayName.replaceAll(' ', '_')}`)) {

0 commit comments

Comments
 (0)