Skip to content

Commit

Permalink
Merge pull request #5 from ynhhoJ/bugfixes/read-new-added-games
Browse files Browse the repository at this point in the history
Improve detection of game from custom IDs overrides list
  • Loading branch information
ynhhoJ authored Aug 26, 2024
2 parents 4365e7c + b21ec32 commit 0612b89
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 7 deletions.
35 changes: 31 additions & 4 deletions src/ts/AchievementsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
Expand Down Expand Up @@ -631,10 +636,32 @@ 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;
})

// 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);
}
} else
{
Expand Down
6 changes: 3 additions & 3 deletions src/ts/components/settingsComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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] = {
Expand All @@ -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] = {
Expand Down
10 changes: 10 additions & 0 deletions src/ts/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down

0 comments on commit 0612b89

Please sign in to comment.