Merge branch 'feature/game-achievements' of github.com:hydralauncher/hydra into feature/cloud-sync

This commit is contained in:
Chubby Granny Chaser
2024-10-20 18:16:02 +01:00
26 changed files with 599 additions and 436 deletions

View File

@@ -51,7 +51,7 @@ const getAchievementLocalUser = async (shop: string, objectId: string) => {
...achievementData,
unlocked: false,
unlockTime: null,
icon: icongray,
icongray: icongray,
} as UserAchievement;
})
.sort((a, b) => {
@@ -110,7 +110,7 @@ const getAchievementsRemoteUser = async (
...achievementData,
unlocked: false,
unlockTime: null,
icon: icongray,
icongray: icongray,
} as UserAchievement;
})
.sort((a, b) => {

View File

@@ -50,6 +50,7 @@ import "./user/unblock-user";
import "./user/get-user-friends";
import "./user/get-user-stats";
import "./user/report-user";
import "./user/get-compared-unlocked-achievements";
import "./profile/get-friend-requests";
import "./profile/get-me";
import "./profile/undo-friendship";

View File

@@ -0,0 +1,44 @@
import type { ComparedAchievements, GameShop } from "@types";
import { registerEvent } from "../register-event";
import { userPreferencesRepository } from "@main/repository";
import { HydraApi } from "@main/services";
const getComparedUnlockedAchievements = async (
_event: Electron.IpcMainInvokeEvent,
objectId: string,
shop: GameShop,
userId: string
) => {
const userPreferences = await userPreferencesRepository.findOne({
where: { id: 1 },
});
return HydraApi.get<ComparedAchievements>(
`/users/${userId}/games/achievements/compare`,
{
shop,
objectId,
language: userPreferences?.language || "en",
}
).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!;
}
return Number(a.hidden) - Number(b.hidden);
});
return {
...achievements,
achievements: sortedAchievements,
} as ComparedAchievements;
});
};
registerEvent(
"getComparedUnlockedAchievements",
getComparedUnlockedAchievements
);