From b0553cb44acfd69a40f5179835d162ffa1625f6a Mon Sep 17 00:00:00 2001 From: LegItMate <77503777+LegItMate@users.noreply.github.com> Date: Sun, 18 Sep 2022 19:19:08 +0530 Subject: [PATCH] Fix custom games not getting sorted on adding --- src/components/launchers/find-games.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/components/launchers/find-games.js b/src/components/launchers/find-games.js index 2d35afed..5374ff36 100644 --- a/src/components/launchers/find-games.js +++ b/src/components/launchers/find-games.js @@ -8,6 +8,7 @@ const { sha256 } = require('../modules/sha256.js'); const processes = new Map(); let loads = 0; +let __CACHE__ = []; async function getInstalledGames(launchers = ['CustomGames', 'EpicGames.js', 'Lutris.js', 'Minecraft.js', 'RiotGames.js', 'RockstarGames.js', 'Steam.js', 'Uplay.js']) { document.getElementById("loadingbtn").style.opacity = '1'; @@ -57,7 +58,7 @@ async function filterAndSort(games, type, list, stored) { } if (type === 'allGamesList') { - return games.map(x => x.DisplayName).sort().map(x => games[games.findIndex(y => y.DisplayName === x)]); + games = games.map(x => x.DisplayName).sort().map(x => games[games.findIndex(y => y.DisplayName === x)]); } else if (['recentGamesListMainPage', 'recentGamesList'].includes(type)) { let final = []; @@ -75,7 +76,7 @@ async function filterAndSort(games, type, list, stored) { return 0; } }); - return final.slice(0, type.includes('MainPage') ? 5 - list.children.length : final.length); + games = final.slice(0, type.includes('MainPage') ? 5 - list.children.length : final.length); } else if (type === 'favGamesList') { let final = []; @@ -83,11 +84,13 @@ async function filterAndSort(games, type, list, stored) { const game = stored?.find(x => x.GameID === games[i].GameID && x.LauncherName === games[i].LauncherName) ?? await getGames(games[i].GameID, games[i].LauncherName); if (typeof game?.Favourite === 'boolean' && game.Favourite === true) final.push(game); } - return final.map(x => x.DisplayName).sort().map(x => final[final.findIndex(y => y.DisplayName === x)]); + games = final.map(x => x.DisplayName).sort().map(x => final[final.findIndex(y => y.DisplayName === x)]); } else { return []; } + __CACHE__ = games; + return games; } async function loadGames(id, data, stored) { @@ -411,6 +414,12 @@ class Elements { } static async createGameElement(game, id, list, prev) { + if (game.LauncherName === 'CustomGame' && !prev) { + prev = __CACHE__; + prev.push(game); + const filtered = (await filterAndSort(prev, 'allGamesList', list)).reverse(); + prev = filtered[filtered.findIndex(x => Object.keys(game).every(y => game[y] === x[y])) - 1]; + } list = document.getElementById(id); const gameElement = Elements.getGameElement(game, id); if (prev && !list.children.namedItem(`game-div-${game.DisplayName.replaceAll(' ', '_')}`)) {