Skip to content

Commit

Permalink
feat: added full support for non-steam games
Browse files Browse the repository at this point in the history
  • Loading branch information
Tormak9970 committed Apr 14, 2023
1 parent 6c9f979 commit 753837b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/Stores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ export const activeUserId = writable(0);
export const showHidden = writable(false);


export const originalSteamShortcuts:Writable<SteamShortcut[]> = writable([]);
export const steamShortcuts:Writable<SteamShortcut[]> = writable([]);

export const steamGames:Writable<GameStruct[]> = writable([]);
export const nonSteamGames:Writable<GameStruct[]> = writable([]);
export const hiddenGameIds:Writable<number[]> = writable([]);
Expand Down
27 changes: 26 additions & 1 deletion src/lib/controllers/AppController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { ToastController } from "./ToastController";
import { SettingsManager } from "../utils/SettingsManager";
import { LogController } from "./LogController";
import { get } from "svelte/store";
import { GridTypes, appLibraryCache, canSave, gridType, hiddenGameIds, isOnline, needsSGDBAPIKey, needsSteamKey, nonSteamGames, originalAppLibraryCache, selectedGameAppId, selectedGameName, steamGames, steamGridDBKey, steamKey, steamShortcuts } from "../../Stores";
import { GridTypes, Platforms, appLibraryCache, canSave, currentPlatform, gridType, hiddenGameIds, isOnline, needsSGDBAPIKey, needsSteamKey, nonSteamGames, originalAppLibraryCache, originalSteamShortcuts, selectedGameAppId, selectedGameName, steamGames, steamGridDBKey, steamKey, steamShortcuts } from "../../Stores";
import { CacheController } from "./CacheController";
import { RustInterop } from "./RustInterop";
import type { SGDBImage } from "../models/SGDB";
Expand Down Expand Up @@ -265,6 +265,7 @@ export class AppController {

LogController.log("Loading non-steam games...");
const shortcuts = await RustInterop.readShortcutsVdf();
originalSteamShortcuts.set(JSON.parse(JSON.stringify(Object.values(shortcuts))));
steamShortcuts.set(Object.values(shortcuts));

const structuredShortcuts = Object.values(shortcuts).map((shortcut: any) => {
Expand Down Expand Up @@ -347,9 +348,16 @@ export class AppController {
} else {
for (const changedPath of (changedPaths as ChangedPath[])) {
libraryCache[changedPath.appId][changedPath.gridType] = changedPath.targetPath;
if (changedPath.gridType == GridTypes.ICON && shortcutIds.includes(changedPath.appId)) {
const shortcut = shortcuts.find((s) => s.appid.toString() == changedPath.appId);
shortcut.icon = changedPath.targetPath;
}
}
originalAppLibraryCache.set(JSON.parse(JSON.stringify(libraryCache)));
appLibraryCache.set(libraryCache);

originalSteamShortcuts.set(JSON.parse(JSON.stringify(shortcuts)));
steamShortcuts.set(shortcuts);
ToastController.showSuccessToast("Changes saved!");
LogController.log("Saved changes.");
}
Expand All @@ -365,6 +373,9 @@ export class AppController {
const originalCache = get(originalAppLibraryCache);
appLibraryCache.set(JSON.parse(JSON.stringify(originalCache)));

const originalShortcuts = get(originalSteamShortcuts);
steamShortcuts.set(JSON.parse(JSON.stringify(originalShortcuts)));

ToastController.showSuccessToast("Changes discarded!");
LogController.log("Discarded changes.");

Expand All @@ -383,6 +394,13 @@ export class AppController {
const gameImages = get(appLibraryCache);
gameImages[selectedGameId][selectedGridType] = path;

if (get(currentPlatform) == Platforms.NON_STEAM) {
const shortcuts = get(steamShortcuts);
const shortcut = shortcuts.find((s) => s.appid == selectedGameId);
shortcut.icon = path;
steamShortcuts.set(shortcuts);
}

appLibraryCache.set(gameImages);
canSave.set(true);

Expand All @@ -403,6 +421,13 @@ export class AppController {
const selectedGridType = get(gridType);
const gameImages = get(appLibraryCache);
gameImages[selectedGameId][selectedGridType] = localPath;

if (get(currentPlatform) == Platforms.NON_STEAM) {
const shortcuts = get(steamShortcuts);
const shortcut = shortcuts.find((s) => s.appid == selectedGameId);
shortcut.icon = localPath;
steamShortcuts.set(shortcuts);
}

appLibraryCache.set(gameImages);
canSave.set(true);
Expand Down

0 comments on commit 753837b

Please sign in to comment.