Skip to content

Commit 2493073

Browse files
committed
feat: adds lobby room
1 parent ce015da commit 2493073

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { Client, Room } from 'colyseus'
2+
import { Dispatcher } from '@colyseus/command'
3+
import { CountryRoomState } from './schema/game_modes/CountryRoomState'
4+
import { OnJoinCommand } from '../commands/OnJoinCommand'
5+
import { OnVoteCommand } from '../commands/OnVoteCommand'
6+
import { OnLeaveCommand } from '../commands/OnLeaveCommand'
7+
import { LOBBY_PHASE, ROUND_PREPARE_STATE } from '../constants/game'
8+
import { OnRoomStartCommand } from '../commands/OnRoomStartCommand'
9+
import { OnRoomSettingsCommand } from '../commands/OnRoomSettingsCommand'
10+
import { OnLobbyCommand } from '../commands/OnLobbyCommand'
11+
import { OnRoomRestartCommand } from '../commands/OnRoomRestartCommand'
12+
import { OnUserUpdateCommand } from '../commands/OnUserUpdateCommand'
13+
import { ConnectOptions } from '../constants/clients'
14+
import { OnUpdateMetadataCommand } from '../commands/OnUpdateMetadataCommand'
15+
import {
16+
ROOM_LOBBY,
17+
ROOM_RESTART,
18+
ROOM_SETTINGS,
19+
ROOM_START,
20+
ROOM_VOTE,
21+
USER_UPDATE,
22+
} from '../constants/messages'
23+
import { LobbyRoomState } from './schema/game_modes/LobbyRoomState'
24+
25+
export class LobbyRoom extends Room<LobbyRoomState> {
26+
dispatcher = new Dispatcher(this)
27+
autoDispose = false
28+
roundTimer = false
29+
async onCreate(options: any) {
30+
this.clock.start()
31+
this.roomId = "lobby";
32+
this.autoDispose = false;
33+
this.maxClients = 9999999999999;
34+
35+
this.setState(
36+
new LobbyRoomState({
37+
38+
})
39+
)
40+
41+
this.setPatchRate(1000);
42+
}
43+
44+
onJoin(client: Client, options: ConnectOptions) {
45+
this.state.players.set(client.sessionId, true);
46+
}
47+
48+
onLeave(client: Client, consented: boolean) {
49+
this.state.players.delete(client.sessionId);
50+
}
51+
52+
onDispose() {}
53+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { Schema, Context, type, MapSchema, ArraySchema } from '@colyseus/schema'
2+
import { Player } from '../entities/PlayerState'
3+
import { Vote } from '../entities/VoteState'
4+
import { Country } from '../entities/CountryState'
5+
import { ScoreBoard } from '../entities/ScoreBoardState'
6+
7+
export class LobbyRoomState extends Schema {
8+
@type({ map: 'boolean' }) players = new MapSchema<boolean>()
9+
10+
11+
}

0 commit comments

Comments
 (0)