diff --git a/src/main/events/user/get-compared-unlocked-achievements.ts b/src/main/events/user/get-compared-unlocked-achievements.ts index 8c5c8779..0c117140 100644 --- a/src/main/events/user/get-compared-unlocked-achievements.ts +++ b/src/main/events/user/get-compared-unlocked-achievements.ts @@ -22,10 +22,10 @@ const getComparedUnlockedAchievements = async ( } ).then((achievements) => { const sortedAchievements = achievements.achievements.sort((a, b) => { - if (a.otherUserStat.unlocked && !b.otherUserStat.unlocked) return -1; - if (!a.otherUserStat.unlocked && b.otherUserStat.unlocked) return 1; - if (a.otherUserStat.unlocked && b.otherUserStat.unlocked) { - return b.otherUserStat.unlockTime! - a.otherUserStat.unlockTime!; + if (a.targetStat.unlocked && !b.targetStat.unlocked) return -1; + if (!a.targetStat.unlocked && b.targetStat.unlocked) return 1; + if (a.targetStat.unlocked && b.targetStat.unlocked) { + return b.targetStat.unlockTime! - a.targetStat.unlockTime!; } return Number(a.hidden) - Number(b.hidden); diff --git a/src/main/services/achievements/achievement-watcher.ts b/src/main/services/achievements/achievement-watcher.ts index 269e85e9..7e0009eb 100644 --- a/src/main/services/achievements/achievement-watcher.ts +++ b/src/main/services/achievements/achievement-watcher.ts @@ -11,11 +11,12 @@ import { import type { AchievementFile } from "@types"; import { achievementsLogger } from "../logger"; import { Cracker } from "@shared"; +import { IsNull, Not } from "typeorm"; const fileStats: Map = new Map(); const fltFiles: Map> = new Map(); -export const watchAchievements = async () => { +const watchAchiievementsWindows = async () => { const games = await gameRepository.find({ where: { isDeleted: false, @@ -23,7 +24,6 @@ export const watchAchievements = async () => { }); if (games.length === 0) return; - const achievementFiles = findAllAchievementFiles(); for (const game of games) { @@ -36,12 +36,6 @@ export const watchAchievements = async () => { if (!gameAchievementFiles.length) continue; - // console.log( - // "Achievements files to observe for:", - // game.title, - // gameAchievementFiles - // ); - for (const file of gameAchievementFiles) { compareFile(game, file); } @@ -49,6 +43,27 @@ export const watchAchievements = async () => { } }; +const watchAchievementsWithWine = async () => { + const games = await gameRepository.find({ + where: { + isDeleted: false, + winePrefixPath: Not(IsNull()), + }, + }); + + if (games.length === 0) return; + + // TODO: watch achievements with wine +}; + +export const watchAchievements = async () => { + if (process.platform === "win32") { + return watchAchiievementsWindows(); + } + + watchAchievementsWithWine(); +}; + const processAchievementFileDiff = async ( game: Game, file: AchievementFile diff --git a/src/renderer/src/pages/achievements/achievements-content.tsx b/src/renderer/src/pages/achievements/achievements-content.tsx index ca60be70..7a37358b 100644 --- a/src/renderer/src/pages/achievements/achievements-content.tsx +++ b/src/renderer/src/pages/achievements/achievements-content.tsx @@ -317,10 +317,10 @@ export function AchievementsContent({ ...userDetails, userId: userDetails.id, totalAchievementCount: comparedAchievements - ? comparedAchievements.ownerUser.totalAchievementCount + ? comparedAchievements.owner.totalAchievementCount : achievements!.length, unlockedAchievementCount: comparedAchievements - ? comparedAchievements.ownerUser.unlockedAchievementCount + ? comparedAchievements.owner.unlockedAchievementCount : achievements!.filter((achievement) => achievement.unlocked) .length, }} diff --git a/src/renderer/src/pages/achievements/achievements.tsx b/src/renderer/src/pages/achievements/achievements.tsx index d15ba0b9..c831dd0e 100644 --- a/src/renderer/src/pages/achievements/achievements.tsx +++ b/src/renderer/src/pages/achievements/achievements.tsx @@ -53,12 +53,11 @@ export default function Achievements() { return { userId: otherUserId, - displayName: comparedAchievements.otherUser.displayName, - profileImageUrl: comparedAchievements.otherUser.profileImageUrl, - totalAchievementCount: - comparedAchievements.otherUser.totalAchievementCount, + displayName: comparedAchievements.target.displayName, + profileImageUrl: comparedAchievements.target.profileImageUrl, + totalAchievementCount: comparedAchievements.target.totalAchievementCount, unlockedAchievementCount: - comparedAchievements.otherUser.unlockedAchievementCount, + comparedAchievements.target.unlockedAchievementCount, }; }, [otherUserId, comparedAchievements]); diff --git a/src/renderer/src/pages/achievements/compared-achievement-list.tsx b/src/renderer/src/pages/achievements/compared-achievement-list.tsx index 6c0484c3..21f11936 100644 --- a/src/renderer/src/pages/achievements/compared-achievement-list.tsx +++ b/src/renderer/src/pages/achievements/compared-achievement-list.tsx @@ -21,7 +21,7 @@ export function ComparedAchievementList({ className={styles.listItem} style={{ display: "grid", - gridTemplateColumns: achievement.onwerUserStat + gridTemplateColumns: achievement.ownerStat ? "3fr 1fr 1fr" : "3fr 2fr", }} @@ -48,8 +48,8 @@ export function ComparedAchievementList({ - {achievement.onwerUserStat ? ( - achievement.onwerUserStat.unlocked ? ( + {achievement.ownerStat ? ( + achievement.ownerStat.unlocked ? (
- {formatDateTime(achievement.onwerUserStat.unlockTime!)} + {formatDateTime(achievement.ownerStat.unlockTime!)}
) : ( @@ -77,7 +77,7 @@ export function ComparedAchievementList({ ) ) : null} - {achievement.otherUserStat.unlocked ? ( + {achievement.targetStat.unlocked ? (
- {formatDateTime(achievement.otherUserStat.unlockTime!)} + {formatDateTime(achievement.targetStat.unlockTime!)}
) : ( diff --git a/src/types/index.ts b/src/types/index.ts index c3a91053..41a51e40 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -343,11 +343,11 @@ export interface GameArtifact { } export interface ComparedAchievements { - ownerUser: { + owner: { totalAchievementCount: number; unlockedAchievementCount: number; }; - otherUser: { + target: { displayName: string; profileImageUrl: string; totalAchievementCount: number; @@ -358,11 +358,11 @@ export interface ComparedAchievements { icon: string; displayName: string; description: string; - onwerUserStat?: { + ownerStat?: { unlocked: boolean; unlockTime: number; }; - otherUserStat: { + targetStat: { unlocked: boolean; unlockTime: number; };