48 lines
612 B
TypeScript
Raw Normal View History

2023-09-01 18:30:05 +08:00
import { BaseConnection } from "tsrpc";
2023-08-28 17:24:17 +08:00
/**
* Room
*/
2023-08-29 17:57:36 +08:00
export default class Room {
//#region public
2023-09-01 18:30:05 +08:00
static maxRoomId: number = 0;
static rooms: { [roomId: number]: Room } = {};
//#endregion
//#region public
2023-08-29 17:57:36 +08:00
//#endregion
2023-08-28 17:24:17 +08:00
//#region private
2023-09-01 18:30:05 +08:00
private roomId: number = 0
private conns: BaseConnection[] = [];
2023-08-28 17:24:17 +08:00
//#endregion
//#region Lifecycle
/**
*
*/
2023-09-01 18:30:05 +08:00
constructor() {
// 给每个新房间生成一个唯一的 ID
this.roomId = ++Room.maxRoomId;
2023-08-28 17:24:17 +08:00
}
//#endregion
//#region Custom
2023-08-31 19:28:35 +08:00
/** Join */
2023-09-01 18:30:05 +08:00
public Join(conn: BaseConnection): void {
this.conns.push(conn);
2023-08-31 19:28:35 +08:00
}
2023-08-28 17:24:17 +08:00
//#endregion
}