- 移除硬编码的花色图标导入,改用动态加载方式 - 添加新的 flowerColorMap 配置文件统一管理缺门图标 - 引入 clearActiveRoom 函数用于清理活动房间状态 - 在游戏数据解析中添加缺失花色的读取函数 - 当房间数据为空时自动清理房间状态并跳转回大厅 - 统一玩家缺门花色数据处理逻辑 - 注释掉浮动状态显示区域以优化界面布局 - 调整CSS样式中缺门标记尺寸和旋转效果 - 在游戏存储模块中添加清除快照功能 - 重构座位玩家卡片组件中的花色图标计算逻辑 - 优化花色标签映射和归一化处理函数
51 lines
1.4 KiB
TypeScript
51 lines
1.4 KiB
TypeScript
import { ref } from 'vue'
|
|
import type {
|
|
ActiveRoomState,
|
|
ActiveRoomSelectionInput,
|
|
} from './state'
|
|
import { clearActiveRoomSnapshot, readActiveRoomSnapshot, saveActiveRoom } from './storage'
|
|
|
|
const activeRoom = ref<ActiveRoomState | null>(readActiveRoomSnapshot())
|
|
|
|
function normalizeRoom(input: ActiveRoomSelectionInput): ActiveRoomState {
|
|
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 setActiveRoom(input: ActiveRoomSelectionInput) {
|
|
const next = normalizeRoom(input)
|
|
activeRoom.value = next
|
|
saveActiveRoom(next)
|
|
}
|
|
|
|
export function clearActiveRoom() {
|
|
activeRoom.value = null
|
|
clearActiveRoomSnapshot()
|
|
}
|
|
|
|
// 使用房间状态
|
|
export function useActiveRoomState() {
|
|
return activeRoom
|
|
}
|