feat(game): 添加定缺功能支持

- 在游戏页面添加 dingQuePending 状态管理
- 实现 showDingQueChooser 计算属性控制定缺选择器显示
- 添加 chooseDingQue 函数处理定缺选择逻辑
- 集成 WebSocket 消息发送定缺选择结果
- 更新底部控制面板添加定缺选择按钮界面
- 添加相应的 CSS 样式支持定缺选择器布局和交互
- 修复房间状态更新时重置定缺待处理状态
This commit is contained in:
2026-03-27 17:12:18 +08:00
parent 7289635340
commit d1220cc45d
2 changed files with 105 additions and 1 deletions

View File

@@ -80,6 +80,7 @@ const wsError = ref('')
const leaveRoomPending = ref(false)
const readyTogglePending = ref(false)
const startGamePending = ref(false)
const dingQuePending = ref(false)
let clockTimer: number | null = null
let unsubscribe: (() => void) | null = null
let pendingRoomInfoRequest = false
@@ -345,6 +346,19 @@ const showReadyToggle = computed(() => {
return true
})
const showDingQueChooser = computed(() => {
const player = myPlayer.value
if (!player) {
return false
}
if (gameStore.phase === 'waiting' || gameStore.phase === 'settlement') {
return false
}
return player.handTiles.length > 0 && !player.missingSuit
})
function applyPlayerReadyState(playerId: string, ready: boolean): void {
const player = gameStore.players[playerId]
if (player) {
@@ -796,6 +810,7 @@ function handleRoomInfoResponse(message: unknown): void {
gameStore.roomId = roomId
if (Object.keys(nextPlayers).length > 0) {
gameStore.players = nextPlayers
dingQuePending.value = false
}
const phaseMap: Record<string, typeof gameStore.phase> = {
@@ -1115,6 +1130,7 @@ function handlePlayerHandResponse(message: unknown): void {
existingPlayer.handTiles = handTiles
existingPlayer.handCount = handTiles.length
}
dingQuePending.value = false
const room = activeRoom.value
if (room && room.roomId === (roomId || gameStore.roomId)) {
@@ -1455,6 +1471,21 @@ function startGame(): void {
})
}
function chooseDingQue(suit: Tile['suit']): void {
if (dingQuePending.value || !showDingQueChooser.value) {
return
}
dingQuePending.value = true
sendWsMessage({
type: 'ding_que',
roomId: gameStore.roomId,
payload: {
suit,
},
})
}
function handleLeaveRoom(): void {
menuOpen.value = false
backHall()
@@ -1763,7 +1794,34 @@ onBeforeUnmount(() => {
<div class="bottom-control-panel">
<div v-if="showReadyToggle || showStartGameButton" class="bottom-action-bar">
<div v-if="showDingQueChooser || showReadyToggle || showStartGameButton" class="bottom-action-bar">
<div v-if="showDingQueChooser" class="ding-que-bar">
<button
class="ding-que-button"
type="button"
:disabled="dingQuePending"
@click="chooseDingQue('W')"
>
</button>
<button
class="ding-que-button"
type="button"
:disabled="dingQuePending"
@click="chooseDingQue('T')"
>
</button>
<button
class="ding-que-button"
type="button"
:disabled="dingQuePending"
@click="chooseDingQue('B')"
>
</button>
</div>
<button
v-if="showReadyToggle"
class="ready-toggle ready-toggle-inline"