From 753837b73a913e7545d1a5c5b057e76978d286e3 Mon Sep 17 00:00:00 2001 From: Tormak <63308171+Tormak9970@users.noreply.github.com> Date: Fri, 14 Apr 2023 10:28:28 -0500 Subject: [PATCH] feat: added full support for non-steam games --- src/Stores.ts | 2 ++ src/lib/controllers/AppController.ts | 27 ++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/Stores.ts b/src/Stores.ts index bd582467..df4e0778 100644 --- a/src/Stores.ts +++ b/src/Stores.ts @@ -46,7 +46,9 @@ export const activeUserId = writable(0); export const showHidden = writable(false); +export const originalSteamShortcuts:Writable = writable([]); export const steamShortcuts:Writable = writable([]); + export const steamGames:Writable = writable([]); export const nonSteamGames:Writable = writable([]); export const hiddenGameIds:Writable = writable([]); diff --git a/src/lib/controllers/AppController.ts b/src/lib/controllers/AppController.ts index 009c4cef..b46e8713 100644 --- a/src/lib/controllers/AppController.ts +++ b/src/lib/controllers/AppController.ts @@ -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"; @@ -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) => { @@ -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."); } @@ -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."); @@ -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); @@ -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);