- 实现 ChengduGamePage.vue 组件,包含完整的麻将游戏界面 - 实现 HallPage.vue 组件,支持房间列表展示、创建和加入功能 - 添加 mahjong API 接口用于房间管理操作 - 集成 store 状态管理和本地存储功能 - 实现 ChengduBottomActions 等游戏控制组件 - 添加 websocket 连接和游戏会话管理逻辑 - 实现游戏倒计时、结算等功能模块
49 lines
1.4 KiB
TypeScript
49 lines
1.4 KiB
TypeScript
import { ref } from 'vue'
|
|
import type {
|
|
RoomMetaSnapshotInput,
|
|
RoomMetaSnapshotState,
|
|
} from './state'
|
|
import { clearRoomMetaSnapshot, readRoomMetaSnapshot, saveRoomMetaSnapshot } from './storage'
|
|
|
|
const roomMetaSnapshot = ref<RoomMetaSnapshotState | null>(readRoomMetaSnapshot())
|
|
|
|
function normalizeRoom(input: RoomMetaSnapshotInput): RoomMetaSnapshotState {
|
|
return {
|
|
roomId: input.roomId,
|
|
roomName: input.roomName ?? '',
|
|
gameType: input.gameType ?? 'chengdu',
|
|
ownerId: input.ownerId ?? '',
|
|
maxPlayers: input.maxPlayers ?? 4,
|
|
playerCount: input.playerCount ?? input.players?.length ?? 0,
|
|
status: input.status ?? 'waiting',
|
|
createdAt: input.createdAt ?? '',
|
|
updatedAt: input.updatedAt ?? '',
|
|
players: input.players ?? [],
|
|
myHand: input.myHand ?? [],
|
|
game: input.game ?? {
|
|
state: {
|
|
wall: [],
|
|
scores: {},
|
|
dealerIndex: -1,
|
|
currentTurn: -1,
|
|
phase: 'waiting',
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
export function setRoomMetaSnapshot(input: RoomMetaSnapshotInput) {
|
|
const next = normalizeRoom(input)
|
|
roomMetaSnapshot.value = next
|
|
saveRoomMetaSnapshot(next)
|
|
}
|
|
|
|
export function clearRoomMetaSnapshotState() {
|
|
roomMetaSnapshot.value = null
|
|
clearRoomMetaSnapshot()
|
|
}
|
|
|
|
export function useRoomMetaSnapshotState() {
|
|
return roomMetaSnapshot
|
|
}
|