Files
snatchgame/server/src/rooms/schemas/LobbyState.ts
josedario87 a28bc286a1 feat: implement competitive clicker MVP with Colyseus.js
- Add real-time multiplayer game server with Colyseus
- Implement unique player naming system with auto-increment
- Create lobby system with automatic matchmaking
- Build 10-minute competitive clicking game rooms (max 2 players)
- Add admin dashboard for game management (pause/resume/restart/kick)
- Implement Vue 3 client with professional UI
- Add WebSocket communication with state synchronization
- Include TypeScript throughout with proper typing
- Create REST API for admin operations
- Add reconnection support and error handling
2025-08-06 02:32:18 -06:00

61 lines
1.6 KiB
TypeScript

import { Schema, type, MapSchema, ArraySchema } from "@colyseus/schema";
export class LobbyPlayer extends Schema {
@type("string") sessionId: string = "";
@type("string") name: string = "";
@type("boolean") inGame: boolean = false;
constructor(sessionId: string, name: string) {
super();
this.sessionId = sessionId;
this.name = name;
this.inGame = false;
}
}
export class AvailableRoom extends Schema {
@type("string") roomId: string = "";
@type("number") playerCount: number = 0;
@type("string") status: string = "";
constructor(roomId: string, playerCount: number, status: string) {
super();
this.roomId = roomId;
this.playerCount = playerCount;
this.status = status;
}
}
export class LobbyState extends Schema {
@type({ map: LobbyPlayer }) players = new MapSchema<LobbyPlayer>();
@type([AvailableRoom]) availableRooms = new ArraySchema<AvailableRoom>();
@type("number") totalPlayers: number = 0;
constructor() {
super();
}
addPlayer(sessionId: string, name: string): LobbyPlayer {
const player = new LobbyPlayer(sessionId, name);
this.players.set(sessionId, player);
this.totalPlayers = this.players.size;
return player;
}
removePlayer(sessionId: string): void {
this.players.delete(sessionId);
this.totalPlayers = this.players.size;
}
updateAvailableRooms(rooms: AvailableRoom[]): void {
this.availableRooms.clear();
rooms.forEach(room => this.availableRooms.push(room));
}
setPlayerInGame(sessionId: string, inGame: boolean): void {
const player = this.players.get(sessionId);
if (player) {
player.inGame = inGame;
}
}
}