mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-01-23 21:44:55 +03:00
feat: update compare achievement response
This commit is contained in:
parent
1d7858438d
commit
33e91e2007
@ -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);
|
||||
|
@ -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<string, number> = new Map();
|
||||
const fltFiles: Map<string, Set<string>> = 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
|
||||
|
@ -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,
|
||||
}}
|
||||
|
@ -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]);
|
||||
|
||||
|
@ -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({
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{achievement.onwerUserStat ? (
|
||||
achievement.onwerUserStat.unlocked ? (
|
||||
{achievement.ownerStat ? (
|
||||
achievement.ownerStat.unlocked ? (
|
||||
<div
|
||||
style={{
|
||||
whiteSpace: "nowrap",
|
||||
@ -61,7 +61,7 @@ export function ComparedAchievementList({
|
||||
>
|
||||
<CheckCircleIcon />
|
||||
<small>
|
||||
{formatDateTime(achievement.onwerUserStat.unlockTime!)}
|
||||
{formatDateTime(achievement.ownerStat.unlockTime!)}
|
||||
</small>
|
||||
</div>
|
||||
) : (
|
||||
@ -77,7 +77,7 @@ export function ComparedAchievementList({
|
||||
)
|
||||
) : null}
|
||||
|
||||
{achievement.otherUserStat.unlocked ? (
|
||||
{achievement.targetStat.unlocked ? (
|
||||
<div
|
||||
style={{
|
||||
whiteSpace: "nowrap",
|
||||
@ -89,7 +89,7 @@ export function ComparedAchievementList({
|
||||
>
|
||||
<CheckCircleIcon />
|
||||
<small>
|
||||
{formatDateTime(achievement.otherUserStat.unlockTime!)}
|
||||
{formatDateTime(achievement.targetStat.unlockTime!)}
|
||||
</small>
|
||||
</div>
|
||||
) : (
|
||||
|
@ -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;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user