From 8a3e93e5d8d7c570e64558e0583dd5b8d5e72092 Mon Sep 17 00:00:00 2001 From: JianMiau Date: Fri, 1 Sep 2023 18:30:05 +0800 Subject: [PATCH] [mod] Room --- src/api/ApiLobbyList.ts | 2 +- src/component/Room/Room.ts | 26 +++++++++++++++----------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/api/ApiLobbyList.ts b/src/api/ApiLobbyList.ts index 40c7fc5..33ce61c 100644 --- a/src/api/ApiLobbyList.ts +++ b/src/api/ApiLobbyList.ts @@ -6,7 +6,7 @@ export default async function (call: ApiCall) { const data: any[] = [] for (let i = 0; i < Lobby.Room.length; i++) { const room = Lobby.Room[i] - data.push(room.SerialNumber) + data.push(room.RoomId) } call.succ(data) } \ No newline at end of file diff --git a/src/component/Room/Room.ts b/src/component/Room/Room.ts index 54af4a9..f7fa129 100644 --- a/src/component/Room/Room.ts +++ b/src/component/Room/Room.ts @@ -1,4 +1,5 @@ -import Client from "../Client/Client" +import { BaseConnection } from "tsrpc"; + /** * Room @@ -7,13 +8,19 @@ export default class Room { //#region public - public SerialNumber: number = 0 + static maxRoomId: number = 0; + static rooms: { [roomId: number]: Room } = {}; + + //#endregion + + //#region public //#endregion //#region private - private wsArr: Client[] = [] + private roomId: number = 0 + private conns: BaseConnection[] = []; //#endregion @@ -22,9 +29,9 @@ export default class Room { /** * */ - constructor(serialNumber: number, ws: Client) { - this.SerialNumber = serialNumber - this.wsArr.push(ws) + constructor() { + // 给每个新房间生成一个唯一的 ID + this.roomId = ++Room.maxRoomId; } //#endregion @@ -32,11 +39,8 @@ export default class Room { //#region Custom /** Join */ - public Join(ws: Client): void { - this.wsArr.forEach(otherWS => { - // otherWS.SendClient() - }) - this.wsArr.push(ws) + public Join(conn: BaseConnection): void { + this.conns.push(conn); } //#endregion