From 7cc6972766eaff296e7e73f5f93e11fec56d8b00 Mon Sep 17 00:00:00 2001 From: ynhhoJ <22500212+ynhhoJ@users.noreply.github.com> Date: Mon, 26 Aug 2024 16:54:07 +0300 Subject: [PATCH 1/3] Improve detection of game from custom IDs overrides list --- src/ts/AchievementsManager.ts | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/ts/AchievementsManager.ts b/src/ts/AchievementsManager.ts index bc7ed3e..1721372 100644 --- a/src/ts/AchievementsManager.ts +++ b/src/ts/AchievementsManager.ts @@ -277,11 +277,16 @@ export class AchievementManager implements Manager { const settings = this.state.settings; this.logger.debug(`${app_id} auth: `, settings.retroachievements.username, settings.retroachievements.api_key); - if (this.ids[app_id] === null) return undefined; + + if (this.ids[app_id] === null && (this.customIdsOverrides[app_id] && this.customIdsOverrides[app_id]?.retro_achivement_game_id === null)) { + return undefined; + }; + await waitForOnline(this.serverAPI); const shortcut = await getAppDetails(app_id); this.logger.debug(`${app_id} shortcut: `, shortcut); let hash: string | null = null; + if (shortcut) { const launchCommand = `${shortcut.strShortcutExe} ${shortcut.strShortcutLaunchOptions}`; @@ -631,10 +636,21 @@ export class AchievementManager implements Manager this.fetching = true; this.clearRuntimeCache(); - await this.refreshAchievementsForApps( - (await getAllNonSteamAppIds()).filter((appId) => this.ids[appId] !== null) - ); + const allNonSteamAppIds = await getAllNonSteamAppIds(); + const nonSteamAppIdsWithRetroAchievementId = allNonSteamAppIds.filter((appId) => { + if (this.ids[appId] !== null) { + return true; + } + + if (this.customIdsOverrides[appId] && this.customIdsOverrides[appId].retro_achivement_game_id !== null) { + return true; + } + + return false; + }) + + await this.refreshAchievementsForApps(nonSteamAppIdsWithRetroAchievementId); } } else { From 3cf2b4175f36058ae8ba383101def94df1b083b1 Mon Sep 17 00:00:00 2001 From: ynhhoJ <22500212+ynhhoJ@users.noreply.github.com> Date: Mon, 26 Aug 2024 17:19:55 +0300 Subject: [PATCH 2/3] Add description to object keys from CustomIdsOverrides type. --- src/ts/settings.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/ts/settings.ts b/src/ts/settings.ts index afb78f9..6a8551d 100644 --- a/src/ts/settings.ts +++ b/src/ts/settings.ts @@ -17,8 +17,18 @@ export type RetroAchievementsData = { }; export type CustomIdsOverrides = { + /** + * Game name + */ name: string | null, + /** + * RetroAchievements supported game files hash. + * Can be found on URL: `https://retroachievements.org/game/xyz/hashes` where `xyz` is Game ID + */ hash?: string | null, + /** + * RetroAchievement Game ID. + */ retro_achivement_game_id: number | null, } From b21ec32ff668cc5fb4fa9ba1aa7f90fdc352ef4c Mon Sep 17 00:00:00 2001 From: ynhhoJ <22500212+ynhhoJ@users.noreply.github.com> Date: Mon, 26 Aug 2024 19:29:11 +0300 Subject: [PATCH 3/3] Remove game from Custom IDs Overrides list if plugin can not find it in user library --- src/ts/AchievementsManager.ts | 11 +++++++++++ src/ts/components/settingsComponent.tsx | 6 +++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/ts/AchievementsManager.ts b/src/ts/AchievementsManager.ts index 1721372..10a1d8e 100644 --- a/src/ts/AchievementsManager.ts +++ b/src/ts/AchievementsManager.ts @@ -649,6 +649,17 @@ export class AchievementManager implements Manager return false; }) + // NOTE: Checks for games what does not exists in user library and removes them from + // `cache` configuration + const gameIdsToBeRemoved = Object.keys(this.customIdsOverrides) + .filter((appId) => !allNonSteamAppIds.includes(Number.parseInt(appId, 10))); + + for (const gameIdToBeRemoved of gameIdsToBeRemoved) { + const gameIdToBeRemovedAsNumber = Number.parseInt(gameIdToBeRemoved, 10); + + delete this.ids[gameIdToBeRemovedAsNumber] + delete this.customIdsOverrides[gameIdToBeRemovedAsNumber] + } await this.refreshAchievementsForApps(nonSteamAppIdsWithRetroAchievementId); } diff --git a/src/ts/components/settingsComponent.tsx b/src/ts/components/settingsComponent.tsx index b1bb53e..d288ccf 100644 --- a/src/ts/components/settingsComponent.tsx +++ b/src/ts/components/settingsComponent.tsx @@ -154,7 +154,7 @@ const CustomIdsOverrides: VFC = () => { const { custom_ids_overrides }= emuchievementsState.settings.data.cache; const gameOptions = Object.keys(custom_ids_overrides) .map((item) => { - const idAsNumber = Number.parseInt(item); + const idAsNumber = Number.parseInt(item, 10); const currentApp = custom_ids_overrides[idAsNumber]; return { @@ -190,7 +190,7 @@ const CustomIdsOverrides: VFC = () => { continue } - const appIdAsNumber = Number.parseInt(appId); + const appIdAsNumber = Number.parseInt(appId, 10); if (!retroAchievementAppId) { emuchievementsState.settings.data.cache.custom_ids_overrides[appIdAsNumber] = { @@ -202,7 +202,7 @@ const CustomIdsOverrides: VFC = () => { continue; } - const retroAchievementAppIdAsNumber = Number.parseInt(retroAchievementAppId); + const retroAchievementAppIdAsNumber = Number.parseInt(retroAchievementAppId, 10); if (Number.isNaN(retroAchievementAppIdAsNumber) || retroAchievementAppIdAsNumber <= 0) { emuchievementsState.settings.data.cache.custom_ids_overrides[appIdAsNumber] = {