refactor(game): 重构缺门花色处理逻辑并优化组件结构
- 移除硬编码的花色图标导入,改用动态加载方式 - 添加新的 flowerColorMap 配置文件统一管理缺门图标 - 引入 clearActiveRoom 函数用于清理活动房间状态 - 在游戏数据解析中添加缺失花色的读取函数 - 当房间数据为空时自动清理房间状态并跳转回大厅 - 统一玩家缺门花色数据处理逻辑 - 注释掉浮动状态显示区域以优化界面布局 - 调整CSS样式中缺门标记尺寸和旋转效果 - 在游戏存储模块中添加清除快照功能 - 重构座位玩家卡片组件中的花色图标计算逻辑 - 优化花色标签映射和归一化处理函数
This commit is contained in:
41
src/config/flowerColorMap.ts
Normal file
41
src/config/flowerColorMap.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
// src/config/lackSuitMap.ts
|
||||
|
||||
|
||||
import type {Suit} from "../types/tile.ts";
|
||||
|
||||
const lackSuitImageModules = import.meta.glob(
|
||||
'/src/assets/images/flowerClolor/*.png',
|
||||
{
|
||||
eager: true,
|
||||
import: 'default',
|
||||
},
|
||||
) as Record<string, string>
|
||||
|
||||
const SUIT_FILE_MAP: Record<Suit, 'wan' | 'tong' | 'tiao'> = {
|
||||
W: 'wan',
|
||||
T: 'tong',
|
||||
B: 'tiao',
|
||||
}
|
||||
|
||||
function buildLackSuitImageKey(suit: Suit): string {
|
||||
const fileName = SUIT_FILE_MAP[suit]
|
||||
return `/src/assets/images/flowerClolor/${fileName}.png`
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据花色获取缺门图标
|
||||
* W -> wan.png
|
||||
* T -> tong.png
|
||||
* B -> tiao.png
|
||||
*/
|
||||
export function getLackSuitImage(suit: Suit): string {
|
||||
const key = buildLackSuitImageKey(suit)
|
||||
return lackSuitImageModules[key] || ''
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为合法缺门花色
|
||||
*/
|
||||
export function isValidLackSuit(suit: string): suit is Suit {
|
||||
return suit === 'W' || suit === 'T' || suit === 'B'
|
||||
}
|
||||
Reference in New Issue
Block a user