mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-01-28 21:31:03 +00:00
feat: starting showing local achievements
This commit is contained in:
@@ -5,14 +5,14 @@ import {
|
||||
OneToOne,
|
||||
PrimaryGeneratedColumn,
|
||||
} from "typeorm";
|
||||
import { Game } from "./game.entity";
|
||||
import type { Game } from "./game.entity";
|
||||
|
||||
@Entity("game_achievement")
|
||||
export class GameAchievement {
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number;
|
||||
|
||||
@OneToOne(() => Game)
|
||||
@OneToOne("Game", "achievements")
|
||||
@JoinColumn()
|
||||
game: Game;
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ import { Repack } from "./repack.entity";
|
||||
import type { GameShop, GameStatus } from "@types";
|
||||
import { Downloader } from "@shared";
|
||||
import type { DownloadQueue } from "./download-queue.entity";
|
||||
import { GameAchievement } from "./game-achievements.entity";
|
||||
|
||||
@Entity("game")
|
||||
export class Game {
|
||||
@@ -76,6 +77,9 @@ export class Game {
|
||||
@JoinColumn()
|
||||
repack: Repack;
|
||||
|
||||
@OneToOne("GameAchievement", "game")
|
||||
achievements: GameAchievement;
|
||||
|
||||
@OneToOne("DownloadQueue", "game")
|
||||
downloadQueue: DownloadQueue;
|
||||
|
||||
|
||||
46
src/main/events/catalogue/get-game-achievements.ts
Normal file
46
src/main/events/catalogue/get-game-achievements.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import type { GameShop } from "@types";
|
||||
|
||||
import { registerEvent } from "../register-event";
|
||||
import { HydraApi } from "@main/services";
|
||||
import { gameRepository } from "@main/repository";
|
||||
import { GameAchievement } from "@main/entity";
|
||||
|
||||
const getGameAchievements = async (
|
||||
_event: Electron.IpcMainInvokeEvent,
|
||||
objectId: string,
|
||||
shop: GameShop
|
||||
): Promise<GameAchievement[]> => {
|
||||
const game = await gameRepository.findOne({
|
||||
where: { objectID: objectId, shop },
|
||||
relations: {
|
||||
achievements: true,
|
||||
},
|
||||
});
|
||||
const gameAchievements = await HydraApi.get(
|
||||
"/games/achievements",
|
||||
{ objectId, shop },
|
||||
{ needsAuth: false }
|
||||
);
|
||||
|
||||
const unlockedAchievements = JSON.parse(
|
||||
game?.achievements?.unlockedAchievements || "[]"
|
||||
) as { name: string; unlockTime: number }[];
|
||||
|
||||
return gameAchievements.map((achievement) => {
|
||||
const unlockedAchiement = unlockedAchievements.find((localAchievement) => {
|
||||
return localAchievement.name == achievement.name;
|
||||
});
|
||||
|
||||
if (unlockedAchiement) {
|
||||
return {
|
||||
...achievement,
|
||||
unlocked: true,
|
||||
unlockTime: unlockedAchiement.unlockTime * 1000,
|
||||
};
|
||||
}
|
||||
|
||||
return { ...achievement, unlocked: false, unlockTime: null };
|
||||
});
|
||||
};
|
||||
|
||||
registerEvent("getGameAchievements", getGameAchievements);
|
||||
@@ -9,13 +9,10 @@ const getGameStats = async (
|
||||
objectId: string,
|
||||
shop: GameShop
|
||||
) => {
|
||||
const params = new URLSearchParams({
|
||||
objectId,
|
||||
shop,
|
||||
});
|
||||
|
||||
const response = await HydraApi.get<GameStats>(
|
||||
`/games/stats?${params.toString()}`
|
||||
`/games/stats`,
|
||||
{ objectId, shop },
|
||||
{ needsAuth: false }
|
||||
);
|
||||
return response;
|
||||
};
|
||||
|
||||
@@ -10,6 +10,7 @@ import "./catalogue/search-games";
|
||||
import "./catalogue/search-game-repacks";
|
||||
import "./catalogue/get-game-stats";
|
||||
import "./catalogue/get-trending-games";
|
||||
import "./catalogue/get-game-achievements";
|
||||
import "./hardware/get-disk-free-space";
|
||||
import "./library/add-game-to-library";
|
||||
import "./library/create-game-shortcut";
|
||||
|
||||
@@ -67,6 +67,7 @@ const runMigrations = async () => {
|
||||
);
|
||||
});
|
||||
|
||||
await knexClient.migrate.down(migrationConfig);
|
||||
await knexClient.migrate.latest(migrationConfig);
|
||||
await knexClient.destroy();
|
||||
};
|
||||
|
||||
@@ -16,7 +16,7 @@ import { publishNewRepacksNotifications } from "./services/notifications";
|
||||
import { MoreThan } from "typeorm";
|
||||
import { HydraApi } from "./services/hydra-api";
|
||||
import { uploadGamesBatch } from "./services/library-sync";
|
||||
import { saveAllLocalSteamAchivements } from "./events/achievements/services/save-all-local-steam-achivements";
|
||||
import { saveAllLocalSteamAchivements } from "./services/achievements/services/save-all-local-steam-achivements";
|
||||
|
||||
const loadState = async (userPreferences: UserPreferences | null) => {
|
||||
RepacksManager.updateRepacks();
|
||||
|
||||
@@ -8,7 +8,7 @@ import { Game } from "@main/entity";
|
||||
import {
|
||||
startGameAchievementObserver,
|
||||
stopGameAchievementObserver,
|
||||
} from "@main/events/achievements/game-achievements-observer";
|
||||
} from "@main/services/achievements/game-achievements-observer";
|
||||
|
||||
export const gamesPlaytime = new Map<
|
||||
number,
|
||||
|
||||
Reference in New Issue
Block a user