- 添加 RoomTrusteePayload 接口定义和 ROOM_TRUSTEE 动作类型 - 在玩家状态中增加 trustee 字段用于标识托管状态 - 实现托管模式切换和状态同步功能 - 添加房间倒计时功能支持玩家操作限时 - 实现倒计时 UI 组件显示操作剩余时间 - 修改游戏开始逻辑避免回合开始后重复准备 - 更新 WebSocket 消息处理支持新的托管消息类型 - 添加托管玩家的视觉标识显示托管状态 - 移除房间创建时不必要的总回合数参数
79 lines
1.8 KiB
TypeScript
79 lines
1.8 KiB
TypeScript
import { authedRequest, type AuthSession } from './authed-request'
|
|
|
|
export interface RoomItem {
|
|
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: RoomItem[]
|
|
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; maxPlayers: number },
|
|
onAuthUpdated?: (next: AuthSession) => void,
|
|
): Promise<RoomItem> {
|
|
return authedRequest<RoomItem>({
|
|
method: 'POST',
|
|
path: ROOM_CREATE_PATH,
|
|
auth,
|
|
onAuthUpdated,
|
|
body: {
|
|
name: input.name,
|
|
game_type: input.gameType,
|
|
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<RoomItem> {
|
|
return authedRequest<RoomItem>({
|
|
method: 'POST',
|
|
path: ROOM_JOIN_PATH,
|
|
auth,
|
|
onAuthUpdated,
|
|
body: {
|
|
room_id: input.roomId,
|
|
},
|
|
})
|
|
}
|