Can select map on private lobbies

This commit is contained in:
evanpelle
2024-10-16 20:34:57 -07:00
parent d92dc9eba6
commit 206f6d3333
6 changed files with 55 additions and 14 deletions
+12 -3
View File
@@ -1,4 +1,4 @@
import {ClientMessage, ClientMessageSchema, Intent, ServerStartGameMessage, ServerStartGameMessageSchema, ServerTurnMessageSchema, Turn} from "../core/Schemas";
import {ClientMessage, ClientMessageSchema, GameConfig, Intent, ServerStartGameMessage, ServerStartGameMessageSchema, ServerTurnMessageSchema, Turn} from "../core/Schemas";
import {Config} from "../core/configuration/Config";
import {Client} from "./Client";
import WebSocket from 'ws';
@@ -23,13 +23,21 @@ export class GameServer {
private endTurnIntervalID
constructor(
public readonly id: string,
public readonly createdAt: number,
public readonly isPublic: boolean,
private config: Config,
private gameConfig: GameConfig,
) { }
public updateGameConfig(gameConfig: GameConfig): void {
if (gameConfig.gameMap != null) {
this.gameConfig.gameMap = gameConfig.gameMap
}
}
public addClient(client: Client, lastTurn: number) {
console.log(`game ${this.id} adding client ${client.id}`)
slog('client_joined_game', `client ${client.id} (re)joining game ${this.id}`, {
@@ -93,7 +101,8 @@ export class GameServer {
ws.send(JSON.stringify(ServerStartGameMessageSchema.parse(
{
type: "start",
turns: this.turns.slice(lastTurn)
turns: this.turns.slice(lastTurn),
config: this.gameConfig
}
)))
}
@@ -137,7 +146,7 @@ export class GameServer {
if (!this.isPublic) {
if (this._hasStarted) {
if (this.clients.length == 0) {
console.log(`game ${this.id} is finisehd`)
console.log()
return GamePhase.Finished
} else {
return GamePhase.Active