refactor(game): 重构游戏状态管理和WebSocket通信

- 定义统一的游戏动作类型GameAction替代原有发送函数
- 创建游戏状态管理store使用Pinia进行状态管理
- 实现游戏状态分发器处理各种游戏事件
- 重构WebSocket处理器支持多处理器注册
- 重命名状态类型文件统一使用State后缀
- 添加ACTION游戏阶段处理操作窗口逻辑
- 集成Pinia依赖管理应用状态
This commit is contained in:
2026-03-25 15:19:28 +08:00
parent 4a9b2f2db2
commit 2737971608
17 changed files with 334 additions and 178 deletions

33
src/game/dispatcher.ts Normal file
View File

@@ -0,0 +1,33 @@
import type {GameAction} from './actions'
import {useGameStore} from "../store/gameStore.ts";
export function dispatchGameAction(action: GameAction) {
const store = useGameStore()
switch (action.type) {
case 'GAME_INIT':
store.initGame(action.payload)
break
case 'GAME_START':
store.phase = 'playing'
store.dealerIndex = action.payload.dealerIndex
break
case 'DRAW_TILE':
store.onDrawTile(action.payload)
break
case 'PLAY_TILE':
store.onPlayTile(action.payload)
break
case 'PENDING_CLAIM':
store.onPendingClaim(action.payload)
break
case 'CLAIM_RESOLVED':
store.clearPendingClaim()
break
}
}