Skip to content

Commit

Permalink
Fix custom games not getting sorted on adding
Browse files Browse the repository at this point in the history
  • Loading branch information
LegItMate committed Sep 23, 2022
1 parent a47a8a9 commit b0553cb
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/components/launchers/find-games.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 = [];
Expand All @@ -75,19 +76,21 @@ 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 = [];
for (let i = 0; i < games.length; i++) {
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) {
Expand Down Expand Up @@ -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(' ', '_')}`)) {
Expand Down

0 comments on commit b0553cb

Please sign in to comment.