import { defineStore } from 'pinia' import type { Character, CollectionDetail } from '@/api/client' interface GameState { collection: CollectionDetail | null queue: Character[] smashed: Character[] passed: Character[] } export const useGameStore = defineStore('game', { state: (): GameState => ({ collection: null, queue: [], smashed: [], passed: [], }), getters: { isFinished: (s) => s.collection !== null && s.queue.length === 0, progress: (s) => { const total = s.collection?.characters.length ?? 0 if (total === 0) return 0 return ((s.smashed.length + s.passed.length) / total) * 100 }, }, actions: { start(collection: CollectionDetail) { this.collection = collection this.queue = [...collection.characters] this.smashed = [] this.passed = [] }, smash() { const c = this.queue.shift() if (c) this.smashed.push(c) }, pass() { const c = this.queue.shift() if (c) this.passed.push(c) }, reset() { this.collection = null this.queue = [] this.smashed = [] this.passed = [] }, }, })