Skip to content

Commit

Permalink
feat: added backup text to game images
Browse files Browse the repository at this point in the history
  • Loading branch information
Tormak9970 committed Apr 2, 2023
1 parent 5bc729a commit f51156b
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
"height": 800,
"resizable": true,
"title": "Steam Art Manager",
"width": 1250,
"width": 1300,
"decorations": false,
"center": true,
"visible": true,
Expand Down
35 changes: 28 additions & 7 deletions src/components/core/games/Game.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import Lazy from "svelte-lazy";
import { SettingsManager } from "../../../lib/utils/SettingsManager";
import { appLibraryCache, gridType, hiddenGameIds, selectedGameAppId } from "../../../Stores";
import { appLibraryCache, gridType, GridTypes, hiddenGameIds, selectedGameAppId } from "../../../Stores";
export let game: SteamGame;
export let widths: any;
Expand All @@ -14,6 +14,7 @@
let gridTypeUnsub: Unsubscriber;
let libraryCacheUnsub: Unsubscriber;
let showImage = true;
let imagePath = "";
$: isHidden = $hiddenGameIds.includes(game.appid);
Expand All @@ -37,17 +38,33 @@
onMount(() => {
gridTypeUnsub = gridType.subscribe((type) => {
imagePath = tauri.convertFileSrc($appLibraryCache[game.appid][type]);
if ($appLibraryCache[game.appid][type]) {
showImage = true;
imagePath = tauri.convertFileSrc($appLibraryCache[game.appid][type]);
} else if (type == GridTypes.WIDE_CAPSULE) {
showImage = true;
imagePath = tauri.convertFileSrc($appLibraryCache[game.appid][GridTypes.CAPSULE]);
} else {
showImage = false;
}
});
libraryCacheUnsub = appLibraryCache.subscribe((cache) => {
imagePath = tauri.convertFileSrc(cache[game.appid][$gridType]);
if (cache[game.appid][$gridType]) {
showImage = true;
imagePath = tauri.convertFileSrc(cache[game.appid][$gridType]);
} else if ($gridType == GridTypes.WIDE_CAPSULE) {
showImage = true;
imagePath = tauri.convertFileSrc(cache[game.appid][GridTypes.CAPSULE]);
} else {
showImage = false;
}
});
});
onDestroy(() => {
if (gridTypeUnsub) gridTypeUnsub();
if (libraryCacheUnsub) libraryCacheUnsub();
})
});
</script>

<!-- svelte-ignore a11y-click-events-have-key-events -->
Expand All @@ -66,9 +83,13 @@
{/if}
</div>
<div class="img" style="height: {heights[$gridType]}px;">
<Lazy height="{heights[$gridType]}px" fadeOption={{delay: 500, duration: 1000}}>
<img src="{imagePath}" alt="{game.name}'s {$gridType} image" style="max-width: {widths[$gridType]}px; max-height: {heights[$gridType]}px; width: auto; height: auto;" />
</Lazy>
{#if showImage}
<Lazy height="{heights[$gridType]}px" fadeOption={{delay: 500, duration: 1000}}>
<img src="{imagePath}" alt="{game.name}'s {$gridType} image" style="max-width: {widths[$gridType]}px; max-height: {heights[$gridType]}px; width: auto; height: auto;" />
</Lazy>
{:else}
<div>No {$gridType} image for game</div>
{/if}
</div>
<div class="name">{game.name}</div>
</div>
Expand Down
8 changes: 3 additions & 5 deletions src/components/core/grids/Grid.svelte
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
<script lang="ts">
import Lazy from "svelte-lazy";
import { AppController } from "../../../lib/controllers/AppController";
import { AppController } from "../../../lib/controllers/AppController";
import type { SGDBImage } from "../../../lib/models/SGDB";
import { dowloadingGridId, gridType, selectedGameAppId } from "../../../Stores";
import LoadingSpinner from "../../info/LoadingSpinner.svelte";
import { dowloadingGridId, gridType } from "../../../Stores";
import LoadingSpinner from "../../info/LoadingSpinner.svelte";
export let grid: SGDBImage;
export let widths: any;
export let heights: any;
let clicked = false;
function selectGame() {
AppController.setSteamGridArt(grid.id, grid.url);
}
Expand Down
1 change: 1 addition & 0 deletions src/components/core/grids/Grids.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
if (online && $steamGridDBKey != "" && $selectedGameAppId != null) grids = filterGrids(await AppController.getSteamGridArt($selectedGameAppId), $gridType, $dbFilters);
});
gridTypeUnsub = gridType.subscribe(async (type) => {
console.log(type);
if ($isOnline && $steamGridDBKey != "" && $selectedGameAppId != null) grids = filterGrids(await AppController.getSteamGridArt($selectedGameAppId), type, $dbFilters);
});
apiKeyUnsub = steamGridDBKey.subscribe(async (key) => {
Expand Down
6 changes: 4 additions & 2 deletions src/lib/controllers/CacheController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,11 @@ export class CacheController {
async fetchGrids(appId: number): Promise<SGDBImage[]> {
LogController.log(`Fetching grids for game ${appId}...`);
const type = get(gridType);
const gridCacheKey = Object.keys(gridsCache);
const gridCacheKeys = Object.keys(gridsCache);

console.log(`get${type.includes("Capsule") ? "Grid": (type == GridTypes.HERO ? "Heroe" : type)}sBySteamAppId`);

if (gridCacheKey.includes(appId.toString())) {
if (gridCacheKeys.includes(appId.toString())) {
const types = Object.keys(gridsCache[appId.toString()]);

if (types.includes(type)) {
Expand Down
1 change: 1 addition & 0 deletions src/lib/models/SGDB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ export class SGDB {
}

let response = await http.fetch<any>(`${this.baseURL}${url}`, options);
console.log(`${this.baseURL}${url}`);

if (response.ok) {
if (response?.data.success) {
Expand Down

0 comments on commit f51156b

Please sign in to comment.