diff --git a/app.go b/app.go index 9ad4f4b..d21ea79 100644 --- a/app.go +++ b/app.go @@ -107,6 +107,10 @@ func (a *App) LoadGamesNewModel() []models.Game { return []models.Game{} } +func (a *App) Log(message string) { + fmt.Println(message) +} + func (a *App) LoadImage(gameId string, imageSrc string) provider.FileBlob { blob := provider.LoadImage(gameId, imageSrc) diff --git a/build/.DS_Store b/build/.DS_Store new file mode 100644 index 0000000..a358587 Binary files /dev/null and b/build/.DS_Store differ diff --git a/build/appicon.png b/build/appicon.png index 63617fe..8e2fb83 100644 Binary files a/build/appicon.png and b/build/appicon.png differ diff --git a/frontend/src/App.vue b/frontend/src/App.vue index ebb4ecf..7e27ab5 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -44,10 +44,8 @@ import GameCarousel from './components/GameCarousel.vue'; import OptionsModal from './components/OptionsModal.vue'; import QrModal from './components/QrModal.vue'; import LoadingModal from './components/LoadingModal.vue'; -import { useKeyboardNavigation } from './utils/use-keyboard-navigation'; import { useAppStore } from "./stores/app-store"; import { storeToRefs } from "pinia"; -import { KeyboardManager } from "./utils/keyboard-manager"; import CurrentActionsHelp from "./components/CurrentActionsHelp.vue"; const store = useAppStore(); @@ -77,15 +75,7 @@ const backgroundStyle = computed(() => { return { backgroundImage }; - }); - -if (showSidebar) { - KeyboardManager.switchContext("sidebar") -} else { - KeyboardManager.switchContext("carousel") -} -useKeyboardNavigation(); diff --git a/frontend/src/utils/keyboard-manager.ts b/frontend/src/inputs/input-manager.ts similarity index 70% rename from frontend/src/utils/keyboard-manager.ts rename to frontend/src/inputs/input-manager.ts index 46e2ccc..f202e2e 100644 --- a/frontend/src/utils/keyboard-manager.ts +++ b/frontend/src/inputs/input-manager.ts @@ -4,10 +4,13 @@ import { KeyContext } from "./key-contexts/key-context"; import { OptionsKeyContext } from "./key-contexts/options-key-context"; import { SidebarKeyContext } from "./key-contexts/sidebar-key-context"; import { GamePreviewKeyContext } from "./key-contexts/game-preview-key-context"; +import { EventsOn } from "../../wailsjs/runtime"; +import { log } from "../services/logger-service"; -export class KeyboardManager { +export class InputManager { private static current?: KeyContext; public static loaded = false; + public static loadedCount = 0; static switchContext(name: 'sidebar' | 'carousel' | 'options' | 'preview') { console.log("Switching context to " + name); @@ -38,4 +41,16 @@ export class KeyboardManager { static handleState(controllerState: ControllerState) { this.current?.handleState(controllerState); } + + static bind() { + console.log("Trying to load inputs") + if (!InputManager.loaded) { + log("Loading inputs"); + EventsOn("controller_change", InputManager.handleState.bind(InputManager)); + window.addEventListener('keydown', InputManager.handle.bind(InputManager)); + InputManager.loaded = true; + InputManager.loadedCount += 1; + log(InputManager.loadedCount); + } + } } \ No newline at end of file diff --git a/frontend/src/utils/key-contexts/carousel-key-context.ts b/frontend/src/inputs/key-contexts/carousel-key-context.ts similarity index 72% rename from frontend/src/utils/key-contexts/carousel-key-context.ts rename to frontend/src/inputs/key-contexts/carousel-key-context.ts index 3373eef..7b26a9b 100644 --- a/frontend/src/utils/key-contexts/carousel-key-context.ts +++ b/frontend/src/inputs/key-contexts/carousel-key-context.ts @@ -1,5 +1,5 @@ import { KeyContext } from "./key-context"; -import { KeyboardManager } from "../keyboard-manager"; +import { InputManager } from "../input-manager"; export class CarouselKeyContext extends KeyContext { readonly name: string = "CarouselContext"; @@ -26,7 +26,7 @@ export class CarouselKeyContext extends KeyContext { protected onKeyLeft() { super.onKeyLeft(); if (this.store.selectedGameIndex === 0 && this.store.showSidebar) { - KeyboardManager.switchContext("sidebar"); + InputManager.switchContext("sidebar"); this.store.selectGame(-1); } else { @@ -37,7 +37,7 @@ export class CarouselKeyContext extends KeyContext { protected onEscape() { super.onEscape(); this.store.optionsOpen = true; - KeyboardManager.switchContext("options"); + InputManager.switchContext("options"); } protected onEnter() { @@ -48,12 +48,22 @@ export class CarouselKeyContext extends KeyContext { protected onSpace() { super.onSpace(); if (this.store.selectedGameIndex !== -1) { - KeyboardManager.switchContext("preview"); + InputManager.switchContext("preview"); const playBtn = document.getElementById("btn-play"); + const repoBtn = document.getElementById("btn-repo"); + const itchBtn = document.getElementById("btn-itch"); + const preview = document.getElementById("preview"); if (playBtn) { playBtn.focus(); + } else if (repoBtn) { + repoBtn.focus(); + } else if (itchBtn) { + itchBtn.focus(); + } else { + preview.focus(); } + } } diff --git a/frontend/src/utils/key-contexts/game-preview-key-context.ts b/frontend/src/inputs/key-contexts/game-preview-key-context.ts similarity index 96% rename from frontend/src/utils/key-contexts/game-preview-key-context.ts rename to frontend/src/inputs/key-contexts/game-preview-key-context.ts index bc62d50..39accdb 100644 --- a/frontend/src/utils/key-contexts/game-preview-key-context.ts +++ b/frontend/src/inputs/key-contexts/game-preview-key-context.ts @@ -1,5 +1,5 @@ import { KeyContext } from "./key-context"; -import { KeyboardManager } from "../keyboard-manager"; +import { InputManager } from "../input-manager"; export class GamePreviewKeyContext extends KeyContext { readonly name: string = "GamePreviewKeyContext"; @@ -81,7 +81,7 @@ export class GamePreviewKeyContext extends KeyContext { protected onEscape() { super.onEscape(); (document.activeElement as any).blur(); - KeyboardManager.switchContext("carousel"); + InputManager.switchContext("carousel"); } setAvailableActions() { diff --git a/frontend/src/utils/key-contexts/key-context.ts b/frontend/src/inputs/key-contexts/key-context.ts similarity index 98% rename from frontend/src/utils/key-contexts/key-context.ts rename to frontend/src/inputs/key-contexts/key-context.ts index dcf4750..d668324 100644 --- a/frontend/src/utils/key-contexts/key-context.ts +++ b/frontend/src/inputs/key-contexts/key-context.ts @@ -8,6 +8,7 @@ export abstract class KeyContext { public handleKey(event: KeyboardEvent): void { this.store.currentInputDevice = "keyboard"; + event.preventDefault(); switch (event.key) { case 'ArrowRight': diff --git a/frontend/src/utils/key-contexts/modal-key-context.ts b/frontend/src/inputs/key-contexts/modal-key-context.ts similarity index 100% rename from frontend/src/utils/key-contexts/modal-key-context.ts rename to frontend/src/inputs/key-contexts/modal-key-context.ts diff --git a/frontend/src/utils/key-contexts/options-key-context.ts b/frontend/src/inputs/key-contexts/options-key-context.ts similarity index 74% rename from frontend/src/utils/key-contexts/options-key-context.ts rename to frontend/src/inputs/key-contexts/options-key-context.ts index f6e225a..5993573 100644 --- a/frontend/src/utils/key-contexts/options-key-context.ts +++ b/frontend/src/inputs/key-contexts/options-key-context.ts @@ -1,4 +1,4 @@ -import { KeyboardManager } from "../keyboard-manager"; +import { InputManager } from "../input-manager"; import { ModalKeyContext } from "./modal-key-context"; export class OptionsKeyContext extends ModalKeyContext { @@ -8,7 +8,7 @@ export class OptionsKeyContext extends ModalKeyContext { super.onEscape(); this.store.optionsOpen = false; this.store.qrLink = ""; - KeyboardManager.switchContext('carousel'); + InputManager.switchContext('carousel'); } } \ No newline at end of file diff --git a/frontend/src/utils/key-contexts/sidebar-key-context.ts b/frontend/src/inputs/key-contexts/sidebar-key-context.ts similarity index 79% rename from frontend/src/utils/key-contexts/sidebar-key-context.ts rename to frontend/src/inputs/key-contexts/sidebar-key-context.ts index 2312113..4fac0e1 100644 --- a/frontend/src/utils/key-contexts/sidebar-key-context.ts +++ b/frontend/src/inputs/key-contexts/sidebar-key-context.ts @@ -1,5 +1,5 @@ import { KeyContext } from "./key-context"; -import { KeyboardManager } from "../keyboard-manager"; +import { InputManager } from "../input-manager"; export class SidebarKeyContext extends KeyContext { readonly name: string = "SidebarContext"; @@ -17,13 +17,13 @@ export class SidebarKeyContext extends KeyContext { protected onKeyRight() { super.onKeyRight(); this.store.moveGameRight(); - KeyboardManager.switchContext("carousel") + InputManager.switchContext("carousel") } protected onEnter() { super.onEnter(); this.store.moveGameRight(); - KeyboardManager.switchContext("carousel") + InputManager.switchContext("carousel") } protected onEscape() { diff --git a/frontend/src/main.ts b/frontend/src/main.ts index 515b82e..1c81999 100644 --- a/frontend/src/main.ts +++ b/frontend/src/main.ts @@ -2,7 +2,10 @@ import {createApp} from 'vue' import App from './App.vue' import './style.css'; import { createPinia } from "pinia"; +import { InputManager } from "./inputs/input-manager"; const app = createApp(App); app.use(createPinia()); app.mount('#app'); +InputManager.bind(); +InputManager.switchContext("carousel") diff --git a/frontend/src/utils/image-manager.ts b/frontend/src/services/image-service.ts similarity index 97% rename from frontend/src/utils/image-manager.ts rename to frontend/src/services/image-service.ts index ea1fa6d..60471e3 100644 --- a/frontend/src/utils/image-manager.ts +++ b/frontend/src/services/image-service.ts @@ -1,6 +1,6 @@ import { LoadImage } from "../../wailsjs/go/main/App"; -export class ImageManager { +export class ImageService { static Dictionary: {[key: string]: string} = {} diff --git a/frontend/src/services/logger-service.ts b/frontend/src/services/logger-service.ts new file mode 100644 index 0000000..8c9f327 --- /dev/null +++ b/frontend/src/services/logger-service.ts @@ -0,0 +1,6 @@ +import { Log } from "../../wailsjs/go/main/App"; + +export function log(msg: any): void { + console.log(msg) + Log("[Frontend] " + msg.toString()).then(); +} \ No newline at end of file diff --git a/frontend/src/stores/app-store.ts b/frontend/src/stores/app-store.ts index d7dd46e..1eefc5b 100644 --- a/frontend/src/stores/app-store.ts +++ b/frontend/src/stores/app-store.ts @@ -3,7 +3,7 @@ import {models} from "../../wailsjs/go/models"; import Game = models.Game; import { StartGame } from "../../wailsjs/go/main/App"; import { fetchGames } from '../services/game-service'; -import { KeyboardManager } from '../utils/keyboard-manager'; +import { InputManager } from '../inputs/input-manager'; export const useAppStore = defineStore('app', { state: () => ({ @@ -67,7 +67,7 @@ export const useAppStore = defineStore('app', { }, showQr(link: string) { this.qrLink = link; - KeyboardManager.switchContext("options"); + InputManager.switchContext("options"); }, async startSelectedGame() { if (this.selectedGame && !this.gameIsStarting) { diff --git a/frontend/src/utils/use-keyboard-navigation.ts b/frontend/src/utils/use-keyboard-navigation.ts deleted file mode 100644 index dc19629..0000000 --- a/frontend/src/utils/use-keyboard-navigation.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { onMounted } from 'vue'; -import { KeyboardManager } from "./keyboard-manager"; -import { EventsOn } from "../../wailsjs/runtime"; - -export function useKeyboardNavigation(): void { - onMounted(() => { - if (KeyboardManager.loaded) { - console.log("Unloading inputs"); - window.removeEventListener('keydown', KeyboardManager.handle.bind(KeyboardManager)); - KeyboardManager.loaded = false; - } - - if (!KeyboardManager.loaded) { - console.log("Loading inputs") - EventsOn("controller_change", KeyboardManager.handleState.bind(KeyboardManager)); - window.addEventListener('keydown', KeyboardManager.handle.bind(KeyboardManager)); - KeyboardManager.loaded = true; - } - }); -} diff --git a/frontend/wailsjs/go/main/App.d.ts b/frontend/wailsjs/go/main/App.d.ts index 952543f..2f9f48b 100755 --- a/frontend/wailsjs/go/main/App.d.ts +++ b/frontend/wailsjs/go/main/App.d.ts @@ -9,4 +9,6 @@ export function LoadGamesNewModel():Promise>; export function LoadImage(arg1:string,arg2:string):Promise; +export function Log(arg1:string):Promise; + export function StartGame(arg1:string):Promise; diff --git a/frontend/wailsjs/go/main/App.js b/frontend/wailsjs/go/main/App.js index aa6e549..6d199b0 100755 --- a/frontend/wailsjs/go/main/App.js +++ b/frontend/wailsjs/go/main/App.js @@ -14,6 +14,10 @@ export function LoadImage(arg1, arg2) { return window['go']['main']['App']['LoadImage'](arg1, arg2); } +export function Log(arg1) { + return window['go']['main']['App']['Log'](arg1); +} + export function StartGame(arg1) { return window['go']['main']['App']['StartGame'](arg1); }