@@ -8,6 +8,7 @@ const { sha256 } = require('../modules/sha256.js');
8
8
9
9
const processes = new Map ( ) ;
10
10
let loads = 0 ;
11
+ let __CACHE__ = [ ] ;
11
12
12
13
async function getInstalledGames ( launchers = [ 'CustomGames' , 'EpicGames.js' , 'Lutris.js' , 'Minecraft.js' , 'RiotGames.js' , 'RockstarGames.js' , 'Steam.js' , 'Uplay.js' ] ) {
13
14
document . getElementById ( "loadingbtn" ) . style . opacity = '1' ;
@@ -57,7 +58,7 @@ async function filterAndSort(games, type, list, stored) {
57
58
}
58
59
59
60
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 ) ] ) ;
61
62
}
62
63
else if ( [ 'recentGamesListMainPage' , 'recentGamesList' ] . includes ( type ) ) {
63
64
let final = [ ] ;
@@ -75,19 +76,21 @@ async function filterAndSort(games, type, list, stored) {
75
76
return 0 ;
76
77
}
77
78
} ) ;
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 ) ;
79
80
}
80
81
else if ( type === 'favGamesList' ) {
81
82
let final = [ ] ;
82
83
for ( let i = 0 ; i < games . length ; i ++ ) {
83
84
const game = stored ?. find ( x => x . GameID === games [ i ] . GameID && x . LauncherName === games [ i ] . LauncherName ) ?? await getGames ( games [ i ] . GameID , games [ i ] . LauncherName ) ;
84
85
if ( typeof game ?. Favourite === 'boolean' && game . Favourite === true ) final . push ( game ) ;
85
86
}
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 ) ] ) ;
87
88
}
88
89
else {
89
90
return [ ] ;
90
91
}
92
+ __CACHE__ = games ;
93
+ return games ;
91
94
}
92
95
93
96
async function loadGames ( id , data , stored ) {
@@ -411,6 +414,12 @@ class Elements {
411
414
}
412
415
413
416
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
+ }
414
423
list = document . getElementById ( id ) ;
415
424
const gameElement = Elements . getGameElement ( game , id ) ;
416
425
if ( prev && ! list . children . namedItem ( `game-div-${ game . DisplayName . replaceAll ( ' ' , '_' ) } ` ) ) {
0 commit comments