Add roundStartsAt property to Table class and update state management
This commit is contained in:
@@ -30,6 +30,7 @@ class Table {
|
||||
this.turnTimeout = null;
|
||||
this.turnEndsAt = null;
|
||||
this.turnCounter = 0;
|
||||
this.roundStartsAt = null;
|
||||
this.clients = new Set();
|
||||
}
|
||||
|
||||
@@ -60,6 +61,7 @@ class Table {
|
||||
maxBet: MAX_BET,
|
||||
roundId: this.roundId,
|
||||
turnEndsAt: this.turnEndsAt,
|
||||
roundStartsAt: this.roundStartsAt,
|
||||
dealerHand,
|
||||
currentSeatIndex: this.currentSeatIndex,
|
||||
seats: this.seats.map((seat, index) => ({
|
||||
@@ -271,10 +273,14 @@ class Table {
|
||||
return;
|
||||
}
|
||||
|
||||
this.roundStartsAt = Date.now() + ROUND_START_DELAY_MS;
|
||||
this.broadcastState();
|
||||
this.roundTimeout = setTimeout(() => {
|
||||
this.roundTimeout = null;
|
||||
const hasBets = this.seats.some((seat) => seat.bet > 0);
|
||||
if (!hasBets) {
|
||||
this.roundStartsAt = null;
|
||||
this.broadcastState();
|
||||
return;
|
||||
}
|
||||
void this.startRound();
|
||||
@@ -287,6 +293,7 @@ class Table {
|
||||
}
|
||||
|
||||
this.clearTurnTimer();
|
||||
this.roundStartsAt = null;
|
||||
this.phase = 'playing';
|
||||
this.roundId += 1;
|
||||
this.deck = shuffle(createDeck());
|
||||
@@ -466,6 +473,7 @@ class Table {
|
||||
|
||||
resetRound() {
|
||||
this.clearTurnTimer();
|
||||
this.roundStartsAt = null;
|
||||
for (const seat of this.seats) {
|
||||
if (!seat.userId) {
|
||||
continue;
|
||||
@@ -484,7 +492,7 @@ class Table {
|
||||
}
|
||||
}
|
||||
|
||||
const tables = Array.from({ length: 3 }, (_, index) => new Table(index + 1, 7));
|
||||
const tables = Array.from({ length: 3 }, (_, index) => new Table(index + 1, 4));
|
||||
|
||||
export function listTables() {
|
||||
return tables.map((table) => table.snapshot());
|
||||
|
||||
Reference in New Issue
Block a user