From e6cba75f9ba66aad0e91af8a6e2eb537ff33cb74 Mon Sep 17 00:00:00 2001 From: wsy182 <2392948297@qq.com> Date: Fri, 3 Apr 2026 15:24:46 +0800 Subject: [PATCH] =?UTF-8?q?feat(game):=20=E6=B7=BB=E5=8A=A0=E6=B8=B8?= =?UTF-8?q?=E6=88=8F=E7=8A=B6=E6=80=81=E7=AE=A1=E7=90=86store=E5=B9=B6?= =?UTF-8?q?=E7=BB=9F=E4=B8=80=E5=B0=B1=E7=BB=AA=E7=8A=B6=E6=80=81=E5=AD=97?= =?UTF-8?q?=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在actions.ts中添加is_ready字段支持多种就绪状态标识 - 在ChengduGamePage.vue中更新就绪状态判断逻辑,优先使用is_ready字段 - 修改WebSocket消息类型从SET_READY到PLAYER_READY以保持一致性 - 更新就绪载荷中的用户ID字段从user_id到player_id - 创建新的gameStore.ts文件实现完整的麻将游戏状态管理 - 添加房间玩家更新、托管设置、玩家回合等核心游戏逻辑处理 - 实现摸牌、出牌、操作窗口等游戏状态变更功能 - 统一处理多种数据格式的兼容性问题 --- src/game/actions.ts | 1 + src/store/gameStore.ts | 2 +- src/views/ChengduGamePage.vue | 20 ++++++++++++-------- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/game/actions.ts b/src/game/actions.ts index 39b7f46..df17dca 100644 --- a/src/game/actions.ts +++ b/src/game/actions.ts @@ -17,6 +17,7 @@ export interface RoomPlayerUpdatePayload { avatar_url?: string Ready?: boolean ready?: boolean + is_ready?: boolean MissingSuit?: string | null missing_suit?: string | null }> diff --git a/src/store/gameStore.ts b/src/store/gameStore.ts index 2a81a90..5c4c483 100644 --- a/src/store/gameStore.ts +++ b/src/store/gameStore.ts @@ -172,7 +172,7 @@ export const useGameStore = defineStore('game', { const seatRaw = raw.Index ?? raw.index ?? index const seatIndex = 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 displayNameRaw = raw.PlayerName ?? raw.player_name const avatarUrlRaw = raw.AvatarUrl ?? raw.avatar_url diff --git a/src/views/ChengduGamePage.vue b/src/views/ChengduGamePage.vue index f20eb19..bc3ed63 100644 --- a/src/views/ChengduGamePage.vue +++ b/src/views/ChengduGamePage.vue @@ -667,7 +667,9 @@ function syncReadyStatesFromRoomUpdate(payload: RoomPlayerUpdatePayload): void { ? item.Ready : typeof item.ready === 'boolean' ? item.ready - : undefined + : typeof item.is_ready === 'boolean' + ? item.is_ready + : undefined if (!playerId || typeof ready !== 'boolean') { continue @@ -2177,7 +2179,7 @@ function handleReadyStateResponse(message: unknown): void { } const type = normalizeWsType(source.type) - if (type !== 'SET_READY') { + if (type !== 'PLAYER_READY') { return } @@ -2194,12 +2196,14 @@ function handleReadyStateResponse(message: unknown): void { ? source.roomId : '' const userId = - typeof readyPayload.user_id === 'string' - ? readyPayload.user_id - : typeof source.target === 'string' - ? source.target - : '' - const ready = readBoolean(readyPayload, 'ready', 'Ready') + typeof readyPayload.player_id === 'string' + ? readyPayload.player_id + : typeof readyPayload.user_id === 'string' + ? readyPayload.user_id + : typeof source.target === 'string' + ? source.target + : '' + const ready = readBoolean(readyPayload, 'is_ready', 'ready', 'Ready') if (roomId && roomId !== gameStore.roomId) { return