refactor(game): 重构游戏模块并添加WebSocket客户端

- 修改开发环境配置中的代理目标地址
- 移除旧的活动房间状态管理模块
- 移除成都麻将游戏相关的测试用例
- 添加新的游戏动作发送功能
- 实现WebSocket客户端类并支持自动重连
- 添加WebSocket消息处理器注册机制
- 创建游戏相关状态类型定义
- 添加ID生成工具函数
- 移除废弃的游戏相关模块和常量定义
- 添加WebSocket消息结构定义
- 重构游戏状态相关类型定义
This commit is contained in:
2026-03-24 23:42:03 +08:00
parent 7316588d9e
commit 4f6ef1d0ec
48 changed files with 423 additions and 994 deletions

25
src/ws/handler.ts Normal file
View File

@@ -0,0 +1,25 @@
import {wsClient} from './client'
type Handler = (msg: any) => void
const handlerMap: Record<string, Handler> = {}
// 注册 handler
export function registerHandler(type: string, handler: Handler) {
handlerMap[type] = handler
}
// 初始化监听
export function initWsHandler() {
wsClient.onMessage((msg) => {
const handler = handlerMap[msg.type]
if (handler) {
handler(msg)
} else {
console.warn('[WS] 未处理消息:', msg.type, msg)
}
})
}