compose elt v0.1
Some checks failed
Deploy App / build (push) Has been cancelled
Deploy App / deploy (push) Has been cancelled

This commit is contained in:
valere
2025-12-23 12:55:37 +01:00
parent 8efafc4642
commit 2c826e29ea
16 changed files with 202 additions and 429 deletions

View File

@@ -1,19 +1,9 @@
import { defineStore } from 'pinia'
import type { Track } from '~~/types/types'
interface CardPosition {
x: number
y: number
}
type CardPositions = Record<string, Record<number, CardPosition>>
export const useCardStore = defineStore('card', {
state: () => ({
// Stocke les IDs des cartes déjà révélées
revealedCards: new Set<number>(),
// Stocke les positions personnalisées des cartes par box
// Format: { [boxId]: { [trackId]: { x: number, y: number } } }
cardPositions: {} as CardPositions
revealedCards: new Set<number>()
}),
actions: {
@@ -33,20 +23,6 @@ export const useCardStore = defineStore('card', {
return this.revealedCards.has(trackId)
},
// Définir la position d'une carte dans une box
setCardPosition(boxId: string, trackId: number, position: { x: number; y: number }) {
if (!this.cardPositions[boxId]) {
this.cardPositions[boxId] = {}
}
this.cardPositions[boxId][trackId] = position
this.saveToLocalStorage()
},
// Obtenir la position d'une carte dans une box
getCardPosition(boxId: string, trackId: number): { x: number; y: number } | undefined {
return this.cardPositions[boxId]?.[trackId]
},
// Basculer l'état de révélation de toutes les cartes
revealAllCards(tracks: Track[]) {
tracks.forEach((track) => {
@@ -69,8 +45,7 @@ export const useCardStore = defineStore('card', {
localStorage.setItem(
'cardStore',
JSON.stringify({
revealedCards: Array.from(this.revealedCards),
cardPositions: this.cardPositions
revealedCards: Array.from(this.revealedCards)
})
)
} catch (e) {
@@ -85,15 +60,12 @@ export const useCardStore = defineStore('card', {
try {
const saved = localStorage.getItem('cardStore')
if (saved) {
const { revealedCards, cardPositions } = JSON.parse(saved)
const { revealedCards } = JSON.parse(saved)
if (Array.isArray(revealedCards)) {
this.revealedCards = new Set(
revealedCards.filter((id): id is number => typeof id === 'number')
)
}
if (cardPositions && typeof cardPositions === 'object') {
this.cardPositions = cardPositions
}
}
} catch (e) {
console.error('Failed to load card store from localStorage', e)
@@ -111,11 +83,6 @@ export const useCardStore = defineStore('card', {
// Getter pour la réactivité dans les templates
isRevealed: (state) => (trackId: number) => {
return state.revealedCards.has(trackId)
},
// Obtenir toutes les positions des cartes d'une box
getBoxCardPositions: (state) => (boxId: string) => {
return state.cardPositions[boxId] || {}
}
}
})