Skip to content

Commit

Permalink
feat: added reset logo position
Browse files Browse the repository at this point in the history
  • Loading branch information
Tormak9970 committed May 14, 2023
1 parent 3532b40 commit 2be9b31
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src-tauri/src/zip_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn get_id_from_grid_name(grid_name: &str) -> (String, String) {
return (id.to_owned(), "capsule".to_owned());
} else {
if &grid_name[(dot_index+1)..] == "json" {
return (name.to_owned(), "logoconfig".to_owned());
return (name.to_owned(), "logoposition".to_owned());
} else {
return (name.to_owned(), "widecapsule".to_owned());
}
Expand Down Expand Up @@ -89,7 +89,7 @@ fn get_import_grid_name(app_handle: &AppHandle, filename: &str, name_id_map: &Ma
"icon" => {
file_grid_type = "_icon";
},
"logoconfig" => {
"logoposition" => {
file_grid_type = "";
},
_ => {
Expand Down
25 changes: 21 additions & 4 deletions src/components/toast-modals/LogoPositionModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@
-->
<script lang="ts">
import Lazy from "svelte-lazy";
import { appLibraryCache, nonSteamGames, selectedGameAppId, showLogoPositionModal, steamGames, steamLogoPositions, unfilteredLibraryCache } from "../../Stores";
import { appLibraryCache, nonSteamGames, originalLogoPositions, selectedGameAppId, showLogoPositionModal, steamGames, steamLogoPositions, unfilteredLibraryCache } from "../../Stores";
import Button from "../interactables/Button.svelte";
import { AppController } from "../../lib/controllers/AppController";
import { afterUpdate, onMount } from "svelte";
import { tauri } from "@tauri-apps/api";
import DropDown from "../interactables/DropDown.svelte";
import Slider from "../interactables/Slider.svelte";
import { fade } from "svelte/transition";
import HorizontalSpacer from "../spacers/HorizontalSpacer.svelte";
export let onClose: () => void;
Expand Down Expand Up @@ -59,6 +60,8 @@
let logoPosition: LogoPinPositions = "CenterCenter";
let currentCssStyles: LogoCssStyles = getLogoPosition(logoPosition, logoHeight, logoWidth);
$: canClear = !!$originalLogoPositions[game.appid];
const widths = {
"Hero": 956,
Expand Down Expand Up @@ -109,11 +112,18 @@
/**
* Apply the logo position changes.
*/
async function applyChanges() {
await AppController.setLogoPosition($selectedGameAppId, logoPosition, logoHeight, logoWidth);
function applyChanges() {
AppController.setLogoPosition($selectedGameAppId, logoPosition, logoHeight, logoWidth);
onClose();
}
/**
* Clears any changes made to the logo position.
*/
function clearLogoPosition() {
AppController.clearLogoPosition($selectedGameAppId);
}
afterUpdate(() => {
currentCssStyles = getLogoPosition(logoPosition, logoHeight, logoWidth);
canSave = (originalHeight != logoHeight) || (originalWidth != logoWidth) || (originalPosition != logoPosition);
Expand Down Expand Up @@ -190,7 +200,14 @@
<div class="logo-position">
<DropDown label="Position" options={dropdownOptions} bind:value={logoPosition} width="140px" />
</div>
<Button label="Save" onClick={applyChanges} width="300px" />
{#if canClear}
<Button label="Save" onClick={applyChanges} width="182px" disabled={!canSave} />
<HorizontalSpacer />
<HorizontalSpacer />
<Button label="Reset" onClick={clearLogoPosition} width="102px" />
{:else}
<Button label="Save" onClick={applyChanges} width="300px" disabled={!canSave} />
{/if}
</div>
</div>
</div>
Expand Down
31 changes: 23 additions & 8 deletions src/lib/controllers/AppController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ export class AppController {
* Discards the current changes
* ? Logging complete.
*/
static async discardChanges(): Promise<void> {
static discardChanges(): void {
const originalCache = get(originalAppLibraryCache);
appLibraryCache.set(JSON.parse(JSON.stringify(originalCache)));

Expand All @@ -496,7 +496,7 @@ export class AppController {
* Discard changes for a given app.
* @param appId The id of the app to clear changes for.
*/
static async discardChangesForGame(appId: number): Promise<void> {
static discardChangesForGame(appId: number): void {
const originalCache = get(originalAppLibraryCache);
const originalLogoCache = get(originalLogoPositions);
const originalShortcuts = get(originalSteamShortcuts);
Expand Down Expand Up @@ -529,7 +529,7 @@ export class AppController {
* Clears all custom grids for a given app.
* @param appId The id of the app to clear art for.
*/
static async clearCustomArtForGame(appId: number): Promise<void> {
static clearCustomArtForGame(appId: number): void {
const appCache = get(appLibraryCache);
const shortcuts = get(steamShortcuts);
const platform = get(currentPlatform);
Expand All @@ -555,10 +555,25 @@ export class AppController {
canSave.set(true);
}

/**
* Clears the logo position for a given app.
* @param appid The id of the app to clear the logo position of.
*/
static clearLogoPosition(appid: number): void {
const logoPositionCache = get(steamLogoPositions);

logoPositionCache[appid].logoPosition.pinnedPosition = "REMOVE";
steamLogoPositions.set(JSON.parse(JSON.stringify(logoPositionCache)));

LogController.log(`Cleared logo position for ${appid}`);

canSave.set(true);
}

/**
* Clears all custom grids.
*/
static async clearAllGrids(): Promise<void> {
static clearAllGrids(): void {
const sGames = get(steamGames);
const nonSGames = get(steamShortcuts);
const games = [...sGames, ...nonSGames];
Expand Down Expand Up @@ -595,7 +610,7 @@ export class AppController {
* Opens a SteamGridDB image for viewing.
* @param grid The grid info of the grid to view.
*/
static async viewSteamGridImage(grid: SGDBImage): Promise<void> {
static viewSteamGridImage(grid: SGDBImage): void {
showGridModal.set(true);
gridModalInfo.set(grid);
}
Expand All @@ -605,7 +620,7 @@ export class AppController {
* @param path The path of the new art.
* ? Logging complete.
*/
static async setCustomArt(path: string): Promise<void> {
static setCustomArt(path: string): void {
const type = get(gridType);
const selectedGameId = get(selectedGameAppId);
const gameName = get(selectedGameName);
Expand Down Expand Up @@ -675,7 +690,7 @@ export class AppController {
* @param widthPct The width percentage.
* ? Logging complete.
*/
static async setLogoPosition(appId: number, pinPosition: LogoPinPositions, heightPct: number, widthPct: number): Promise<void> {
static setLogoPosition(appId: number, pinPosition: LogoPinPositions, heightPct: number, widthPct: number): void {
const logoPositions = get(steamLogoPositions);

const currentPos = logoPositions[appId];
Expand Down Expand Up @@ -784,7 +799,7 @@ export class AppController {
* Checks if the app can go online, goes online if so, otherwise notifies the user.
* ? Logging complete.
*/
static async tryGoOnline(): Promise<void> {
static tryGoOnline(): void {
LogController.log("Attempting to go online...");
if (navigator.onLine) {
isOnline.set(true);
Expand Down

0 comments on commit 2be9b31

Please sign in to comment.