domino-client/src/managers/SocketIoEventManager.ts
2024-07-05 15:37:29 +02:00

59 lines
1.4 KiB
TypeScript

import { useGameStore } from '@/stores/game'
import { wait } from '@/common/helpers'
import type { GameSessionState } from '@/common/interfaces'
import { storeToRefs } from 'pinia'
export class SocketIoEventManager {
gameStore: any = useGameStore()
handleSessionStateEvent(data: GameSessionState) {
const { updateSessionState } = this.gameStore
updateSessionState(data)
return {
status: 'ok'
}
}
handleGameStateEvent(data: any) {
const { updateGameState } = this.gameStore
updateGameState(data)
return {
status: 'ok'
}
}
handlePlayerStateEvent(data: any) {
const { updatePlayerState } = this.gameStore
updatePlayerState(data)
return {
status: 'ok'
}
}
async handleCanMakeMoveEvent(data: any) {
const { canMakeMove, moveToMake } = storeToRefs(this.gameStore)
const { updateCanMakeMove, setIncomingFreeEnds } = this.gameStore
setIncomingFreeEnds(data.freeHands)
updateCanMakeMove(true)
while (canMakeMove.value) {
await wait(500)
}
return {
status: 'ok',
...moveToMake.value
}
}
async handleCanSelectTileEvent() {
const { canSelectTile } = storeToRefs(this.gameStore)
const { updateCanSelectTile } = this.gameStore
updateCanSelectTile(true)
while (canSelectTile.value) {
await wait(500)
}
return {
status: 'ok'
}
}
}