feat: update compare achievement response

This commit is contained in:
Zamitto 2024-10-20 14:37:30 -03:00
parent 1d7858438d
commit 33e91e2007
6 changed files with 43 additions and 29 deletions

View File

@ -22,10 +22,10 @@ const getComparedUnlockedAchievements = async (
} }
).then((achievements) => { ).then((achievements) => {
const sortedAchievements = achievements.achievements.sort((a, b) => { const sortedAchievements = achievements.achievements.sort((a, b) => {
if (a.otherUserStat.unlocked && !b.otherUserStat.unlocked) return -1; if (a.targetStat.unlocked && !b.targetStat.unlocked) return -1;
if (!a.otherUserStat.unlocked && b.otherUserStat.unlocked) return 1; if (!a.targetStat.unlocked && b.targetStat.unlocked) return 1;
if (a.otherUserStat.unlocked && b.otherUserStat.unlocked) { if (a.targetStat.unlocked && b.targetStat.unlocked) {
return b.otherUserStat.unlockTime! - a.otherUserStat.unlockTime!; return b.targetStat.unlockTime! - a.targetStat.unlockTime!;
} }
return Number(a.hidden) - Number(b.hidden); return Number(a.hidden) - Number(b.hidden);

View File

@ -11,11 +11,12 @@ import {
import type { AchievementFile } from "@types"; import type { AchievementFile } from "@types";
import { achievementsLogger } from "../logger"; import { achievementsLogger } from "../logger";
import { Cracker } from "@shared"; import { Cracker } from "@shared";
import { IsNull, Not } from "typeorm";
const fileStats: Map<string, number> = new Map(); const fileStats: Map<string, number> = new Map();
const fltFiles: Map<string, Set<string>> = new Map(); const fltFiles: Map<string, Set<string>> = new Map();
export const watchAchievements = async () => { const watchAchiievementsWindows = async () => {
const games = await gameRepository.find({ const games = await gameRepository.find({
where: { where: {
isDeleted: false, isDeleted: false,
@ -23,7 +24,6 @@ export const watchAchievements = async () => {
}); });
if (games.length === 0) return; if (games.length === 0) return;
const achievementFiles = findAllAchievementFiles(); const achievementFiles = findAllAchievementFiles();
for (const game of games) { for (const game of games) {
@ -36,12 +36,6 @@ export const watchAchievements = async () => {
if (!gameAchievementFiles.length) continue; if (!gameAchievementFiles.length) continue;
// console.log(
// "Achievements files to observe for:",
// game.title,
// gameAchievementFiles
// );
for (const file of gameAchievementFiles) { for (const file of gameAchievementFiles) {
compareFile(game, file); 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 ( const processAchievementFileDiff = async (
game: Game, game: Game,
file: AchievementFile file: AchievementFile

View File

@ -317,10 +317,10 @@ export function AchievementsContent({
...userDetails, ...userDetails,
userId: userDetails.id, userId: userDetails.id,
totalAchievementCount: comparedAchievements totalAchievementCount: comparedAchievements
? comparedAchievements.ownerUser.totalAchievementCount ? comparedAchievements.owner.totalAchievementCount
: achievements!.length, : achievements!.length,
unlockedAchievementCount: comparedAchievements unlockedAchievementCount: comparedAchievements
? comparedAchievements.ownerUser.unlockedAchievementCount ? comparedAchievements.owner.unlockedAchievementCount
: achievements!.filter((achievement) => achievement.unlocked) : achievements!.filter((achievement) => achievement.unlocked)
.length, .length,
}} }}

View File

@ -53,12 +53,11 @@ export default function Achievements() {
return { return {
userId: otherUserId, userId: otherUserId,
displayName: comparedAchievements.otherUser.displayName, displayName: comparedAchievements.target.displayName,
profileImageUrl: comparedAchievements.otherUser.profileImageUrl, profileImageUrl: comparedAchievements.target.profileImageUrl,
totalAchievementCount: totalAchievementCount: comparedAchievements.target.totalAchievementCount,
comparedAchievements.otherUser.totalAchievementCount,
unlockedAchievementCount: unlockedAchievementCount:
comparedAchievements.otherUser.unlockedAchievementCount, comparedAchievements.target.unlockedAchievementCount,
}; };
}, [otherUserId, comparedAchievements]); }, [otherUserId, comparedAchievements]);

View File

@ -21,7 +21,7 @@ export function ComparedAchievementList({
className={styles.listItem} className={styles.listItem}
style={{ style={{
display: "grid", display: "grid",
gridTemplateColumns: achievement.onwerUserStat gridTemplateColumns: achievement.ownerStat
? "3fr 1fr 1fr" ? "3fr 1fr 1fr"
: "3fr 2fr", : "3fr 2fr",
}} }}
@ -48,8 +48,8 @@ export function ComparedAchievementList({
</div> </div>
</div> </div>
{achievement.onwerUserStat ? ( {achievement.ownerStat ? (
achievement.onwerUserStat.unlocked ? ( achievement.ownerStat.unlocked ? (
<div <div
style={{ style={{
whiteSpace: "nowrap", whiteSpace: "nowrap",
@ -61,7 +61,7 @@ export function ComparedAchievementList({
> >
<CheckCircleIcon /> <CheckCircleIcon />
<small> <small>
{formatDateTime(achievement.onwerUserStat.unlockTime!)} {formatDateTime(achievement.ownerStat.unlockTime!)}
</small> </small>
</div> </div>
) : ( ) : (
@ -77,7 +77,7 @@ export function ComparedAchievementList({
) )
) : null} ) : null}
{achievement.otherUserStat.unlocked ? ( {achievement.targetStat.unlocked ? (
<div <div
style={{ style={{
whiteSpace: "nowrap", whiteSpace: "nowrap",
@ -89,7 +89,7 @@ export function ComparedAchievementList({
> >
<CheckCircleIcon /> <CheckCircleIcon />
<small> <small>
{formatDateTime(achievement.otherUserStat.unlockTime!)} {formatDateTime(achievement.targetStat.unlockTime!)}
</small> </small>
</div> </div>
) : ( ) : (

View File

@ -343,11 +343,11 @@ export interface GameArtifact {
} }
export interface ComparedAchievements { export interface ComparedAchievements {
ownerUser: { owner: {
totalAchievementCount: number; totalAchievementCount: number;
unlockedAchievementCount: number; unlockedAchievementCount: number;
}; };
otherUser: { target: {
displayName: string; displayName: string;
profileImageUrl: string; profileImageUrl: string;
totalAchievementCount: number; totalAchievementCount: number;
@ -358,11 +358,11 @@ export interface ComparedAchievements {
icon: string; icon: string;
displayName: string; displayName: string;
description: string; description: string;
onwerUserStat?: { ownerStat?: {
unlocked: boolean; unlocked: boolean;
unlockTime: number; unlockTime: number;
}; };
otherUserStat: { targetStat: {
unlocked: boolean; unlocked: boolean;
unlockTime: number; unlockTime: number;
}; };