feat(game): 添加游戏状态管理store并统一就绪状态字段

- 在actions.ts中添加is_ready字段支持多种就绪状态标识
- 在ChengduGamePage.vue中更新就绪状态判断逻辑,优先使用is_ready字段
- 修改WebSocket消息类型从SET_READY到PLAYER_READY以保持一致性
- 更新就绪载荷中的用户ID字段从user_id到player_id
- 创建新的gameStore.ts文件实现完整的麻将游戏状态管理
- 添加房间玩家更新、托管设置、玩家回合等核心游戏逻辑处理
- 实现摸牌、出牌、操作窗口等游戏状态变更功能
- 统一处理多种数据格式的兼容性问题
This commit is contained in:
2026-04-03 15:24:46 +08:00
parent 6c3fca3530
commit e6cba75f9b
3 changed files with 14 additions and 9 deletions

View File

@@ -17,6 +17,7 @@ export interface RoomPlayerUpdatePayload {
avatar_url?: string avatar_url?: string
Ready?: boolean Ready?: boolean
ready?: boolean ready?: boolean
is_ready?: boolean
MissingSuit?: string | null MissingSuit?: string | null
missing_suit?: string | null missing_suit?: string | null
}> }>

View File

@@ -172,7 +172,7 @@ export const useGameStore = defineStore('game', {
const seatRaw = raw.Index ?? raw.index ?? index const seatRaw = raw.Index ?? raw.index ?? index
const seatIndex = const seatIndex =
typeof seatRaw === 'number' && Number.isFinite(seatRaw) ? seatRaw : index typeof seatRaw === 'number' && Number.isFinite(seatRaw) ? seatRaw : index
const readyRaw = raw.Ready ?? raw.ready const readyRaw = raw.Ready ?? raw.ready ?? raw.is_ready
const ready = parseBooleanish(readyRaw) const ready = parseBooleanish(readyRaw)
const displayNameRaw = raw.PlayerName ?? raw.player_name const displayNameRaw = raw.PlayerName ?? raw.player_name
const avatarUrlRaw = raw.AvatarUrl ?? raw.avatar_url const avatarUrlRaw = raw.AvatarUrl ?? raw.avatar_url

View File

@@ -667,7 +667,9 @@ function syncReadyStatesFromRoomUpdate(payload: RoomPlayerUpdatePayload): void {
? item.Ready ? item.Ready
: typeof item.ready === 'boolean' : typeof item.ready === 'boolean'
? item.ready ? item.ready
: undefined : typeof item.is_ready === 'boolean'
? item.is_ready
: undefined
if (!playerId || typeof ready !== 'boolean') { if (!playerId || typeof ready !== 'boolean') {
continue continue
@@ -2177,7 +2179,7 @@ function handleReadyStateResponse(message: unknown): void {
} }
const type = normalizeWsType(source.type) const type = normalizeWsType(source.type)
if (type !== 'SET_READY') { if (type !== 'PLAYER_READY') {
return return
} }
@@ -2194,12 +2196,14 @@ function handleReadyStateResponse(message: unknown): void {
? source.roomId ? source.roomId
: '' : ''
const userId = const userId =
typeof readyPayload.user_id === 'string' typeof readyPayload.player_id === 'string'
? readyPayload.user_id ? readyPayload.player_id
: typeof source.target === 'string' : typeof readyPayload.user_id === 'string'
? source.target ? readyPayload.user_id
: '' : typeof source.target === 'string'
const ready = readBoolean(readyPayload, 'ready', 'Ready') ? source.target
: ''
const ready = readBoolean(readyPayload, 'is_ready', 'ready', 'Ready')
if (roomId && roomId !== gameStore.roomId) { if (roomId && roomId !== gameStore.roomId) {
return return