feat: custom game support/game info changing

This commit is contained in:
Moyasee
2025-09-19 16:58:58 +03:00
parent 3409b53268
commit f4e84e46cc
15 changed files with 556 additions and 32 deletions

View File

@@ -10,7 +10,15 @@ const saveGameShopAssets = async (
): Promise<void> => {
const key = levelKeys.game(shop, objectId);
const existingAssets = await gamesShopAssetsSublevel.get(key);
return gamesShopAssetsSublevel.put(key, { ...existingAssets, ...assets });
// Preserve existing title if it differs from the incoming title (indicating it was customized)
const shouldPreserveTitle = existingAssets?.title && existingAssets.title !== assets.title;
return gamesShopAssetsSublevel.put(key, {
...existingAssets,
...assets,
title: shouldPreserveTitle ? existingAssets.title : assets.title
});
};
registerEvent("saveGameShopAssets", saveGameShopAssets);

View File

@@ -16,6 +16,7 @@ import "./hardware/check-folder-write-permission";
import "./library/add-game-to-library";
import "./library/add-custom-game-to-library";
import "./library/update-custom-game";
import "./library/update-game-custom-assets";
import "./library/add-game-to-favorites";
import "./library/remove-game-from-favorites";
import "./library/create-game-shortcut";

View File

@@ -43,12 +43,14 @@ const addGameToLibrary = async (
await gamesSublevel.put(gameKey, game);
}
await createGame(game).catch(() => {});
if (game) {
await createGame(game).catch(() => {});
AchievementWatcherManager.firstSyncWithRemoteIfNeeded(
game.shop,
game.objectId
);
AchievementWatcherManager.firstSyncWithRemoteIfNeeded(
game.shop,
game.objectId
);
}
};
registerEvent("addGameToLibrary", addGameToLibrary);

View File

@@ -18,18 +18,14 @@ const getLibrary = async (): Promise<LibraryGame[]> => {
const download = await downloadsSublevel.get(key);
const gameAssets = await gamesShopAssetsSublevel.get(key);
// 确保返回的对象符合 LibraryGame 类型
return {
id: key,
...game,
download: download ?? null,
// 确保 gameAssets 中的可能为 null 的字段转换为 undefined
libraryHeroImageUrl: gameAssets?.libraryHeroImageUrl ?? undefined,
libraryImageUrl: gameAssets?.libraryImageUrl ?? undefined,
logoImageUrl: gameAssets?.logoImageUrl ?? undefined,
logoPosition: gameAssets?.logoPosition ?? undefined,
coverImageUrl: gameAssets?.coverImageUrl ?? undefined,
};
...gameAssets,
// Ensure compatibility with LibraryGame type
libraryHeroImageUrl: game.libraryHeroImageUrl ?? gameAssets?.libraryHeroImageUrl,
} as LibraryGame;
})
);
});

View File

@@ -0,0 +1,45 @@
import { registerEvent } from "../register-event";
import { gamesSublevel, gamesShopAssetsSublevel, levelKeys } from "@main/level";
import type { GameShop } from "@types";
const updateGameCustomAssets = async (
_event: Electron.IpcMainInvokeEvent,
shop: GameShop,
objectId: string,
title: string,
customIconUrl?: string | null,
customLogoImageUrl?: string | null,
customHeroImageUrl?: string | null
) => {
const gameKey = levelKeys.game(shop, objectId);
const existingGame = await gamesSublevel.get(gameKey);
if (!existingGame) {
throw new Error("Game not found");
}
const updatedGame = {
...existingGame,
title,
customIconUrl: customIconUrl !== undefined ? customIconUrl : existingGame.customIconUrl,
customLogoImageUrl: customLogoImageUrl !== undefined ? customLogoImageUrl : existingGame.customLogoImageUrl,
customHeroImageUrl: customHeroImageUrl !== undefined ? customHeroImageUrl : existingGame.customHeroImageUrl,
};
await gamesSublevel.put(gameKey, updatedGame);
// Also update the shop assets for non-custom games
const existingAssets = await gamesShopAssetsSublevel.get(gameKey);
if (existingAssets) {
const updatedAssets = {
...existingAssets,
title, // Update the title in shop assets as well
};
await gamesShopAssetsSublevel.put(gameKey, updatedAssets);
}
return updatedGame;
};
registerEvent("updateGameCustomAssets", updateGameCustomAssets);

View File

@@ -57,7 +57,7 @@ export const mergeWithRemoteGames = async () => {
await gamesShopAssetsSublevel.put(gameKey, {
shop: game.shop,
objectId: game.objectId,
title: game.title,
title: localGame?.title || game.title, // Preserve local title if it exists
coverImageUrl: game.coverImageUrl,
libraryHeroImageUrl: game.libraryHeroImageUrl,
libraryImageUrl: game.libraryImageUrl,