import { defineStore } from 'pinia'; import {models} from "../../wailsjs/go/models"; import Game = models.Game; import { StartGame } from "../../wailsjs/go/main/App"; export const useAppStore = defineStore('app', { state: () => ({ tags: [] as string[], games: [] as Game[], selectedTag: null as string | null, transitionDirection: 'down' as 'up' | 'down', selectedGame: null as Game | null, selectedGameIndex: -1, qrLink: '' as string, optionsOpen: false as boolean, gameIsStarting: false as boolean }), getters: { filteredGames(state): Game[] { return state.games.filter(game => game.Genres.split(",").includes(state.selectedTag ?? '')); } }, actions: { moveGameRight() { this.selectGame(this.selectedGameIndex + 1); }, moveGameLeft() { this.selectGame(this.selectedGameIndex - 1); }, moveTagUp() { const index = this.tags.findIndex(t => t === this.selectedTag); this.transitionDirection = 'down'; if (index > 0) this.selectTag(this.tags[index - 1]); }, moveTagDown() { const index = this.tags.findIndex(t => t === this.selectedTag); this.transitionDirection = 'up'; if (index < this.tags.length - 1) this.selectTag(this.tags[index + 1]); }, selectGame(index: number) { const games = this.filteredGames; if (index >= 0 && index < games.length) { this.selectedGameIndex = index; this.selectedGame = games[index]; } else { this.selectedGameIndex = -1; this.selectedGame = null; } }, selectTag(tag: string) { this.selectedTag = tag; this.selectGame(this.selectedGameIndex); }, showQr(link: string) { this.qrLink = link; }, async startSelectedGame() { if (this.selectedGame && !this.gameIsStarting) { this.gameIsStarting = true; await StartGame(this.selectedGame.Id); this.gameIsStarting = false; } else { console.log("No game selected") } } } });