From 2872bd6220a28ffcaee5b3e11a9cb774ac4d7445 Mon Sep 17 00:00:00 2001 From: club Date: Thu, 3 Jul 2025 22:12:39 -0400 Subject: [PATCH] all two controllers and no extract every time --- app.go | 2 +- frontend/src/App.vue | 4 +--- frontend/src/stores/app-store.ts | 12 ++++++++---- .../src/utils/key-contexts/carousel-key-context.ts | 3 +++ frontend/src/utils/key-contexts/key-context.ts | 4 ++-- .../src/utils/key-contexts/options-key-context.ts | 13 +++++++++++++ frontend/src/utils/keyboard-manager.ts | 6 ++++-- lib/inputs/joystick.go | 5 +++-- lib/provider/provider.go | 6 ++++++ 9 files changed, 41 insertions(+), 14 deletions(-) create mode 100644 frontend/src/utils/key-contexts/options-key-context.ts diff --git a/app.go b/app.go index cc04e72..bacdfcc 100644 --- a/app.go +++ b/app.go @@ -16,7 +16,7 @@ import ( var ( games []models.Game lastEmitTimestamp = time.Now().Add(-10 * time.Second) - emitInterval = 300 * time.Millisecond + emitInterval = 150 * time.Millisecond gameIsOpen = false ) diff --git a/frontend/src/App.vue b/frontend/src/App.vue index 5f0a2cb..045c613 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -46,9 +46,7 @@ import { storeToRefs } from "pinia"; import { KeyboardManager } from "./utils/keyboard-manager"; const store = useAppStore(); -const { selectedTag, selectedGame, tags, games, transitionDirection, qrLink, gameIsStarting } = storeToRefs(store); - -const optionsOpen = ref(false); +const { selectedTag, selectedGame, tags, games, transitionDirection, qrLink, gameIsStarting, optionsOpen } = storeToRefs(store); onMounted(async () => { games.value = await fetchGames(); diff --git a/frontend/src/stores/app-store.ts b/frontend/src/stores/app-store.ts index 896d6f4..3c439fa 100644 --- a/frontend/src/stores/app-store.ts +++ b/frontend/src/stores/app-store.ts @@ -10,8 +10,9 @@ export const useAppStore = defineStore('app', { selectedTag: null as string | null, transitionDirection: 'down' as 'up' | 'down', selectedGame: null as Game | null, - selectedGameIndex: 0, + selectedGameIndex: -1, qrLink: '' as string, + optionsOpen: false as boolean, gameIsStarting: false as boolean }), getters: { @@ -42,17 +43,20 @@ export const useAppStore = defineStore('app', { this.selectedGameIndex = index; this.selectedGame = games[index]; } + else { + this.selectedGameIndex = -1; + this.selectedGame = null; + } }, selectTag(tag: string) { this.selectedTag = tag; - this.selectedGameIndex = 0; - this.selectedGame = this.filteredGames[0] ?? null; + this.selectGame(this.selectedGameIndex); }, showQr(link: string) { this.qrLink = link; }, async startSelectedGame() { - if (this.selectedGame) { + if (this.selectedGame && !this.gameIsStarting) { this.gameIsStarting = true; await StartGame(this.selectedGame.Id); this.gameIsStarting = false; diff --git a/frontend/src/utils/key-contexts/carousel-key-context.ts b/frontend/src/utils/key-contexts/carousel-key-context.ts index ef60030..e36648e 100644 --- a/frontend/src/utils/key-contexts/carousel-key-context.ts +++ b/frontend/src/utils/key-contexts/carousel-key-context.ts @@ -23,6 +23,7 @@ export class CarouselKeyContext extends KeyContext { super.onKeyLeft(); if (this.store.selectedGameIndex === 0) { KeyboardManager.switchContext("sidebar"); + this.store.selectGame(-1); } else { this.store.moveGameLeft(); @@ -31,6 +32,8 @@ export class CarouselKeyContext extends KeyContext { protected onEscape() { super.onEscape(); + this.store.optionsOpen = true; + KeyboardManager.switchContext('options'); } protected onEnter() { diff --git a/frontend/src/utils/key-contexts/key-context.ts b/frontend/src/utils/key-contexts/key-context.ts index 1eaffdc..dce2859 100644 --- a/frontend/src/utils/key-contexts/key-context.ts +++ b/frontend/src/utils/key-contexts/key-context.ts @@ -46,12 +46,12 @@ export abstract class KeyContext { this.onKeyDown() } - if ((state.buttons & 0x02) !== 0) { + if ((state.buttons & 0x04) !== 0) { this.onEnter() } // TODO should be 0x01 when the power button will work - if ((state.buttons & 0x04) !== 0) { + if ((state.buttons & 0x02) !== 0) { this.onEscape() } } diff --git a/frontend/src/utils/key-contexts/options-key-context.ts b/frontend/src/utils/key-contexts/options-key-context.ts new file mode 100644 index 0000000..713d151 --- /dev/null +++ b/frontend/src/utils/key-contexts/options-key-context.ts @@ -0,0 +1,13 @@ +import { KeyboardManager } from "../keyboard-manager"; +import { ModalKeyContext } from "./modal-key-context"; + +export class OptionsKeyContext extends ModalKeyContext { + public name: string = "OptionsKeyContext"; + + protected override onEscape(): void { + super.onEscape(); + this.store.optionsOpen = false; + KeyboardManager.switchContext('carousel'); + } + +} \ No newline at end of file diff --git a/frontend/src/utils/keyboard-manager.ts b/frontend/src/utils/keyboard-manager.ts index faf9cb7..6eadbae 100644 --- a/frontend/src/utils/keyboard-manager.ts +++ b/frontend/src/utils/keyboard-manager.ts @@ -1,15 +1,17 @@ import { ControllerState } from "../models/controller-state"; import { CarouselKeyContext } from "./key-contexts/carousel-key-context"; import { KeyContext } from "./key-contexts/key-context"; +import { OptionsKeyContext } from "./key-contexts/options-key-context"; import { SidebarKeyContext } from "./key-contexts/sidebar-key-context"; export class KeyboardManager { private static current?: KeyContext; - static switchContext(name: 'sidebar' | 'carousel') { + static switchContext(name: 'sidebar' | 'carousel' | 'options') { console.log("Switching context to " + name); if (name === 'sidebar') this.current = new SidebarKeyContext(); - else this.current = new CarouselKeyContext(); + else if (name === 'carousel') this.current = new CarouselKeyContext(); + else if (name === 'options') this.current = new OptionsKeyContext(); } static handle(event: KeyboardEvent) { diff --git a/lib/inputs/joystick.go b/lib/inputs/joystick.go index f3b123e..c948104 100644 --- a/lib/inputs/joystick.go +++ b/lib/inputs/joystick.go @@ -138,8 +138,9 @@ func Start(onStateChange func(ControllerState)) { state.Id = i - if state.Buttons != 0 || state.Joystick.X != 127 || state.Joystick.Y != 127 { - fmt.Printf("State changed on device %d\n", i) + // TODO Samuel please fix help me + if (state.Buttons != 0 || state.Joystick.X != 127 || state.Joystick.Y != 127) && !(state.Id == 0 && state.Buttons == 128 && state.Joystick.X != 127 && state.Joystick.Y != 127) { + // fmt.Printf("Id: %d - %d buttons ", state.Id, state.Buttons) onStateChange(*state) } } diff --git a/lib/provider/provider.go b/lib/provider/provider.go index aeb356a..38ae985 100644 --- a/lib/provider/provider.go +++ b/lib/provider/provider.go @@ -168,6 +168,12 @@ func ExtractGame(game models.Game) string { check(err) } gamePath := filepath.Join(config.GetDefaultConjureGamesDirectory(), game.Id) + + _, err = os.Stat(filepath.Join(gamePath, game.Files)) + if err == nil { + return filepath.Join(gamePath, game.Files) + } + err = extractZipsInFolder(gamePath) check(err) gamePath = filepath.Join(gamePath, game.Files)