mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-01-23 21:44:55 +03:00
feat: get achievement from game directory on launch
This commit is contained in:
parent
5e313a0374
commit
2a6b757e37
@ -2,6 +2,7 @@ import { gameAchievementRepository, gameRepository } from "@main/repository";
|
||||
import {
|
||||
findAllAchievementFiles,
|
||||
findAchievementFiles,
|
||||
findAchievementFileInExecutableDirectory,
|
||||
} from "./find-achivement-files";
|
||||
import { parseAchievementFile } from "./parse-achievement-file";
|
||||
import { mergeAchievements } from "./merge-achievements";
|
||||
@ -12,26 +13,30 @@ import { achievementsLogger } from "../logger";
|
||||
export const updateAllLocalUnlockedAchievements = async () => {
|
||||
const gameAchievementFilesMap = await findAllAchievementFiles();
|
||||
|
||||
for (const objectId of gameAchievementFilesMap.keys()) {
|
||||
const gameAchievementFiles = gameAchievementFilesMap.get(objectId)!;
|
||||
const games = await gameRepository.find({
|
||||
where: {
|
||||
isDeleted: false,
|
||||
},
|
||||
});
|
||||
|
||||
const [game, localAchievements] = await Promise.all([
|
||||
gameRepository.findOne({
|
||||
where: { objectID: objectId, shop: "steam", isDeleted: false },
|
||||
}),
|
||||
gameAchievementRepository.findOne({
|
||||
where: { objectId, shop: "steam" },
|
||||
}),
|
||||
]);
|
||||
for (const game of games) {
|
||||
const gameAchievementFiles =
|
||||
gameAchievementFilesMap.get(game.objectID) || [];
|
||||
const achievementFileInsideDirectory =
|
||||
findAchievementFileInExecutableDirectory(game);
|
||||
|
||||
if (!game) continue;
|
||||
gameAchievementFiles.push(...achievementFileInsideDirectory);
|
||||
|
||||
const localAchievements = await gameAchievementRepository.findOne({
|
||||
where: { objectId: game.objectID, shop: "steam" },
|
||||
});
|
||||
|
||||
if (!localAchievements || !localAchievements.achievements) {
|
||||
await getGameAchievementData(objectId, "steam")
|
||||
await getGameAchievementData(game.objectID, "steam")
|
||||
.then((achievements) => {
|
||||
return gameAchievementRepository.upsert(
|
||||
{
|
||||
objectId,
|
||||
objectId: game.objectID,
|
||||
shop: "steam",
|
||||
achievements: JSON.stringify(achievements),
|
||||
},
|
||||
@ -60,7 +65,7 @@ export const updateAllLocalUnlockedAchievements = async () => {
|
||||
);
|
||||
}
|
||||
|
||||
mergeAchievements(objectId, "steam", unlockedAchievements, false);
|
||||
mergeAchievements(game.objectID, "steam", unlockedAchievements, false);
|
||||
}
|
||||
};
|
||||
|
||||
@ -78,6 +83,11 @@ export const updateLocalUnlockedAchivements = async (objectId: string) => {
|
||||
|
||||
const gameAchievementFiles = await findAchievementFiles(game);
|
||||
|
||||
const achievementFileInsideDirectory =
|
||||
findAchievementFileInExecutableDirectory(game);
|
||||
|
||||
gameAchievementFiles.push(...achievementFileInsideDirectory);
|
||||
|
||||
console.log("Achievements files for", game.title, gameAchievementFiles);
|
||||
|
||||
if (!localAchievements || !localAchievements.achievements) {
|
||||
|
Loading…
Reference in New Issue
Block a user