From 806e65d474c3a4cdb9acefae65d33808cf5213a9 Mon Sep 17 00:00:00 2001 From: Evan Date: Fri, 6 Dec 2024 17:23:36 -0800 Subject: [PATCH] double multiplayer game spawn time --- src/client/GameRunner.ts | 9 ++++----- src/core/configuration/Config.ts | 6 +++--- src/core/configuration/DefaultConfig.ts | 6 +++--- src/core/configuration/DevConfig.ts | 5 +++++ src/server/Server.ts | 2 +- 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/client/GameRunner.ts b/src/client/GameRunner.ts index f0419c66d..ab9081af7 100644 --- a/src/client/GameRunner.ts +++ b/src/client/GameRunner.ts @@ -5,7 +5,7 @@ import { EventBus } from "../core/EventBus"; import { Config, getConfig } from "../core/configuration/Config"; import { createRenderer, GameRenderer } from "./graphics/GameRenderer"; import { InputHandler, MouseUpEvent, ZoomEvent, DragEvent, MouseDownEvent } from "./InputHandler" -import { ClientID, ClientIntentMessageSchema, ClientJoinMessageSchema, ClientLeaveMessageSchema, ClientMessageSchema, GameID, Intent, ServerMessage, ServerMessageSchema, ServerSyncMessage, Turn } from "../core/Schemas"; +import { ClientID, ClientIntentMessageSchema, ClientJoinMessageSchema, ClientMessageSchema, GameID, Intent, ServerMessage, ServerMessageSchema, ServerSyncMessage, Turn } from "../core/Schemas"; import { loadTerrainMap, TerrainMapImpl } from "../core/game/TerrainMapLoader"; import { and, bfs, dist, manhattanDist } from "../core/Util"; import { WinCheckExecution } from "../core/execution/WinCheckExecution"; @@ -36,7 +36,7 @@ export function joinLobby(lobbyConfig: LobbyConfig, onjoin: () => void): () => v const clientID = uuidv4() const playerID = uuidv4() const eventBus = new EventBus() - const config = getConfig() + const config = getConfig(lobbyConfig.isLocal) const transport = new Transport(lobbyConfig.isLocal, eventBus, lobbyConfig.gameID, lobbyConfig.ip, clientID, playerID, config, lobbyConfig.playerName) const onconnect = () => { @@ -54,7 +54,7 @@ export function joinLobby(lobbyConfig: LobbyConfig, onjoin: () => void): () => v gameID: lobbyConfig.gameID, ip: lobbyConfig.ip, } - createClientGame(gameConfig, eventBus, transport).then(r => r.start()) + createClientGame(config, gameConfig, eventBus, transport).then(r => r.start()) }; } transport.connect(onconnect, onmessage) @@ -65,8 +65,7 @@ export function joinLobby(lobbyConfig: LobbyConfig, onjoin: () => void): () => v } -export async function createClientGame(gameConfig: GameConfig, eventBus: EventBus, transport: Transport): Promise { - const config = getConfig() +export async function createClientGame(config: Config, gameConfig: GameConfig, eventBus: EventBus, transport: Transport): Promise { const terrainMap = await loadTerrainMap(gameConfig.map) diff --git a/src/core/configuration/Config.ts b/src/core/configuration/Config.ts index a5fd68024..9628190da 100644 --- a/src/core/configuration/Config.ts +++ b/src/core/configuration/Config.ts @@ -1,7 +1,7 @@ import { Gold, Player, PlayerID, PlayerInfo, TerraNullius, Tick, Tile, Unit, UnitInfo, UnitType } from "../game/Game"; import { Colord, colord } from "colord"; import { devConfig } from "./DevConfig"; -import { defaultConfig } from "./DefaultConfig"; +import { DefaultConfig } from "./DefaultConfig"; import { GameID } from "../Schemas"; export enum GameEnv { @@ -9,14 +9,14 @@ export enum GameEnv { Prod } -export function getConfig(): Config { +export function getConfig(isLocal: boolean): Config { // TODO: 'prod' not found in prod env if (process.env.GAME_ENV == 'dev') { console.log('Using dev config') return devConfig } else { console.log('Using prod config') - return defaultConfig + return new DefaultConfig(isLocal) } } diff --git a/src/core/configuration/DefaultConfig.ts b/src/core/configuration/DefaultConfig.ts index 7b19ef888..1e717f3cd 100644 --- a/src/core/configuration/DefaultConfig.ts +++ b/src/core/configuration/DefaultConfig.ts @@ -8,6 +8,8 @@ import { pastelTheme } from "./PastelTheme"; export class DefaultConfig implements Config { + constructor(private isLocal: boolean) { } + maxUnitCost(): number { return 99_999_999 } @@ -141,7 +143,7 @@ export class DefaultConfig implements Config { return 500 } numSpawnPhaseTurns(): number { - return 100 + return this.isLocal ? 100 : 200 } numBots(): number { return 400 @@ -282,5 +284,3 @@ export class DefaultConfig implements Config { return adjustment } } - -export const defaultConfig = new DefaultConfig() \ No newline at end of file diff --git a/src/core/configuration/DevConfig.ts b/src/core/configuration/DevConfig.ts index c5f4be13a..61ec6f708 100644 --- a/src/core/configuration/DevConfig.ts +++ b/src/core/configuration/DevConfig.ts @@ -2,6 +2,11 @@ import { Player, PlayerInfo, UnitInfo, UnitType } from "../game/Game"; import { DefaultConfig } from "./DefaultConfig"; export const devConfig = new class extends DefaultConfig { + + constructor() { + super(true) + } + unitInfo(type: UnitType): UnitInfo { const info = super.unitInfo(type) const oldCost = info.cost diff --git a/src/server/Server.ts b/src/server/Server.ts index 42e72d7e1..9baddec04 100644 --- a/src/server/Server.ts +++ b/src/server/Server.ts @@ -21,7 +21,7 @@ const wss = new WebSocketServer({ server }); // Serve static files from the 'out' directory app.use(express.static(path.join(__dirname, '../../out'))); app.use(express.json()) -const gm = new GameManager(getConfig()) +const gm = new GameManager(getConfig(false)) // New GET endpoint to list lobbies app.get('/lobbies', (req, res) => {