- 实现 ChengduGamePage.vue 组件,包含完整的麻将游戏界面 - 实现 HallPage.vue 组件,支持房间列表展示、创建和加入功能 - 添加 mahjong API 接口用于房间管理操作 - 集成 store 状态管理和本地存储功能 - 实现 ChengduBottomActions 等游戏控制组件 - 添加 websocket 连接和游戏会话管理逻辑 - 实现游戏倒计时、结算等功能模块
80 lines
2.0 KiB
TypeScript
80 lines
2.0 KiB
TypeScript
import {authedRequest, type AuthSession} from './authed-request'
|
|
|
|
export interface Room {
|
|
room_id: string
|
|
name: string
|
|
game_type: string
|
|
owner_id: string
|
|
max_players: number
|
|
player_count: number
|
|
players?: Array<{
|
|
index: number
|
|
player_id: string
|
|
player_name?: string
|
|
PlayerName?: string
|
|
ready: boolean
|
|
}>
|
|
status: string
|
|
created_at: string
|
|
updated_at: string
|
|
}
|
|
|
|
export interface RoomListResult {
|
|
items: Room[]
|
|
page: number
|
|
size: number
|
|
total: number
|
|
}
|
|
|
|
const ROOM_CREATE_PATH =
|
|
import.meta.env.VITE_ROOM_CREATE_PATH ?? '/api/v1/game/mahjong/room/create'
|
|
const ROOM_LIST_PATH = import.meta.env.VITE_ROOM_LIST_PATH ?? '/api/v1/game/mahjong/room/list'
|
|
const ROOM_JOIN_PATH = import.meta.env.VITE_ROOM_JOIN_PATH ?? '/api/v1/game/mahjong/room/join'
|
|
|
|
export async function createRoom(
|
|
auth: AuthSession,
|
|
input: { name: string; gameType: string; totalRounds: number; maxPlayers: number },
|
|
onAuthUpdated?: (next: AuthSession) => void,
|
|
): Promise<Room> {
|
|
return authedRequest<Room>({
|
|
method: 'POST',
|
|
path: ROOM_CREATE_PATH,
|
|
auth,
|
|
onAuthUpdated,
|
|
body: {
|
|
name: input.name,
|
|
game_type: input.gameType,
|
|
total_rounds: input.totalRounds,
|
|
max_players: input.maxPlayers,
|
|
},
|
|
})
|
|
}
|
|
|
|
export async function listRooms(
|
|
auth: AuthSession,
|
|
onAuthUpdated?: (next: AuthSession) => void,
|
|
): Promise<RoomListResult> {
|
|
return authedRequest<RoomListResult>({
|
|
method: 'GET',
|
|
path: ROOM_LIST_PATH,
|
|
auth,
|
|
onAuthUpdated,
|
|
})
|
|
}
|
|
|
|
export async function joinRoom(
|
|
auth: AuthSession,
|
|
input: { roomId: string },
|
|
onAuthUpdated?: (next: AuthSession) => void,
|
|
): Promise<Room> {
|
|
return authedRequest<Room>({
|
|
method: 'POST',
|
|
path: ROOM_JOIN_PATH,
|
|
auth,
|
|
onAuthUpdated,
|
|
body: {
|
|
room_id: input.roomId,
|
|
},
|
|
})
|
|
}
|