mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-03-09 15:40:26 +00:00
feat: implement reset game achievements functionality
This commit is contained in:
parent
47a5f4d327
commit
ac6eb247df
6 changed files with 65 additions and 5 deletions
|
@ -25,6 +25,7 @@ import "./library/verify-executable-path";
|
||||||
import "./library/remove-game";
|
import "./library/remove-game";
|
||||||
import "./library/remove-game-from-library";
|
import "./library/remove-game-from-library";
|
||||||
import "./library/select-game-wine-prefix";
|
import "./library/select-game-wine-prefix";
|
||||||
|
import "./library/reset-game-achievements";
|
||||||
import "./misc/open-checkout";
|
import "./misc/open-checkout";
|
||||||
import "./misc/open-external";
|
import "./misc/open-external";
|
||||||
import "./misc/show-open-dialog";
|
import "./misc/show-open-dialog";
|
||||||
|
|
52
src/main/events/library/reset-game-achievements.ts
Normal file
52
src/main/events/library/reset-game-achievements.ts
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
import { gameAchievementRepository, gameRepository } from "@main/repository";
|
||||||
|
import { registerEvent } from "../register-event";
|
||||||
|
import { findAchievementFiles } from "@main/services/achievements/find-achivement-files";
|
||||||
|
import fs from "fs";
|
||||||
|
import { WindowManager } from "@main/services";
|
||||||
|
import { getUnlockedAchievements } from "../user/get-unlocked-achievements";
|
||||||
|
|
||||||
|
const resetGameAchievements = async (
|
||||||
|
_event: Electron.IpcMainInvokeEvent,
|
||||||
|
gameId: number
|
||||||
|
) => {
|
||||||
|
const game = await gameRepository.findOne({ where: { id: gameId } });
|
||||||
|
|
||||||
|
if (!game) return;
|
||||||
|
|
||||||
|
const achievementFiles = findAchievementFiles(game);
|
||||||
|
|
||||||
|
if (achievementFiles.length) {
|
||||||
|
try {
|
||||||
|
await Promise.all(
|
||||||
|
achievementFiles.map(async (achievementFile) => {
|
||||||
|
await fs.promises.rm(achievementFile.filePath, { recursive: true });
|
||||||
|
})
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await gameAchievementRepository.update(
|
||||||
|
{ objectId: game.objectID },
|
||||||
|
{
|
||||||
|
unlockedAchievements: null,
|
||||||
|
achievements: null,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// TODO: remove from db
|
||||||
|
|
||||||
|
const gameAchievements = await getUnlockedAchievements(
|
||||||
|
game.objectID,
|
||||||
|
game.shop,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
|
WindowManager.mainWindow?.webContents.send(
|
||||||
|
`on-update-achievements-${game.objectID}-${game.shop}`,
|
||||||
|
gameAchievements
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
registerEvent("resetGameAchievements", resetGameAchievements);
|
|
@ -110,6 +110,8 @@ contextBridge.exposeInMainWorld("electron", {
|
||||||
ipcRenderer.invoke("deleteGameFolder", gameId),
|
ipcRenderer.invoke("deleteGameFolder", gameId),
|
||||||
getGameByObjectId: (objectId: string) =>
|
getGameByObjectId: (objectId: string) =>
|
||||||
ipcRenderer.invoke("getGameByObjectId", objectId),
|
ipcRenderer.invoke("getGameByObjectId", objectId),
|
||||||
|
resetGameAchievements: (gameId: number) =>
|
||||||
|
ipcRenderer.invoke("resetGameAchievements", gameId),
|
||||||
onGamesRunning: (
|
onGamesRunning: (
|
||||||
cb: (
|
cb: (
|
||||||
gamesRunning: Pick<GameRunning, "id" | "sessionDurationInMillis">[]
|
gamesRunning: Pick<GameRunning, "id" | "sessionDurationInMillis">[]
|
||||||
|
|
2
src/renderer/src/declaration.d.ts
vendored
2
src/renderer/src/declaration.d.ts
vendored
|
@ -105,7 +105,7 @@ declare global {
|
||||||
) => void
|
) => void
|
||||||
) => () => Electron.IpcRenderer;
|
) => () => Electron.IpcRenderer;
|
||||||
onLibraryBatchComplete: (cb: () => void) => () => Electron.IpcRenderer;
|
onLibraryBatchComplete: (cb: () => void) => () => Electron.IpcRenderer;
|
||||||
|
resetGameAchievements: (gameId: number) => Promise<void>;
|
||||||
/* User preferences */
|
/* User preferences */
|
||||||
getUserPreferences: () => Promise<UserPreferences | null>;
|
getUserPreferences: () => Promise<UserPreferences | null>;
|
||||||
updateUserPreferences: (
|
updateUserPreferences: (
|
||||||
|
|
|
@ -122,6 +122,11 @@ export function GameOptionsModal({
|
||||||
const shouldShowWinePrefixConfiguration =
|
const shouldShowWinePrefixConfiguration =
|
||||||
window.electron.platform === "linux";
|
window.electron.platform === "linux";
|
||||||
|
|
||||||
|
const handleResetAchievements = async () => {
|
||||||
|
await window.electron.resetGameAchievements(game.id);
|
||||||
|
updateGame();
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<DeleteGameModal
|
<DeleteGameModal
|
||||||
|
@ -140,7 +145,7 @@ export function GameOptionsModal({
|
||||||
<ResetAchievementsModal
|
<ResetAchievementsModal
|
||||||
visible={showResetAchievementsModal}
|
visible={showResetAchievementsModal}
|
||||||
onClose={() => setShowResetAchievementsModal(false)}
|
onClose={() => setShowResetAchievementsModal(false)}
|
||||||
// resetAchievements={handleResetAchievements}
|
resetAchievements={handleResetAchievements}
|
||||||
game={game}
|
game={game}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
|
|
@ -7,19 +7,19 @@ interface ResetAchievementsModalProps {
|
||||||
visible: boolean;
|
visible: boolean;
|
||||||
game: Game;
|
game: Game;
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
// resetAchievements: () => Promise<void>;
|
resetAchievements: () => Promise<void>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ResetAchievementsModal({
|
export function ResetAchievementsModal({
|
||||||
onClose,
|
onClose,
|
||||||
game,
|
game,
|
||||||
visible,
|
visible,
|
||||||
// resetAchievements,
|
resetAchievements,
|
||||||
}: ResetAchievementsModalProps) {
|
}: ResetAchievementsModalProps) {
|
||||||
const { t } = useTranslation("game_details");
|
const { t } = useTranslation("game_details");
|
||||||
|
|
||||||
const handleResetAchievements = async () => {
|
const handleResetAchievements = async () => {
|
||||||
// await resetAchievements();
|
await resetAchievements();
|
||||||
onClose();
|
onClose();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue