From de268c9190288c1468d90000f2d2c976167e6cd7 Mon Sep 17 00:00:00 2001 From: xXDMOGXx <83487906+xXDMOGXx@users.noreply.github.com> Date: Mon, 18 Nov 2024 21:47:24 -0600 Subject: [PATCH] move whether to save games and use virtual robots into env --- .env | 2 ++ src/server/api/game-manager.ts | 19 +++++++++++-------- src/server/utils/env.ts | 3 ++- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/.env b/.env index 567b9daf..7d0f21b9 100644 --- a/.env +++ b/.env @@ -2,3 +2,5 @@ # Set to "production" for a production server and environment, or "development" for local server NODE_ENV="development" +ENABLE_SAVES=true +USE_VIRTUAL_ROBOTS=false diff --git a/src/server/api/game-manager.ts b/src/server/api/game-manager.ts index b1dcd5a2..ffdd1269 100644 --- a/src/server/api/game-manager.ts +++ b/src/server/api/game-manager.ts @@ -18,6 +18,7 @@ import { import { SaveManager } from "./save-manager"; import { materializePath } from "../robot/path-materializer"; import { executor } from "./api"; +import { DO_SAVES } from "../utils/env"; export abstract class GameManager { protected gameInterruptedReason: GameInterruptedReason | undefined = @@ -114,7 +115,7 @@ export class HumanGameManager extends GameManager { await executor.execute(command); console.log("executor done"); - if (ids) { + if (ids && DO_SAVES) { if (currentSave?.host === ids[0]) { SaveManager.saveGame( ids[0], @@ -181,13 +182,15 @@ export class ComputerGameManager extends GameManager { public async handleMessage(message: Message, id: string): Promise { if (message instanceof MoveMessage) { this.chess.makeMove(message.move); - SaveManager.saveGame( - id, - "ai", - this.hostSide, - this.difficulty, - this.chess.pgn, - ); + if (DO_SAVES) { + SaveManager.saveGame( + id, + "ai", + this.hostSide, + this.difficulty, + this.chess.pgn, + ); + } if (this.chess.isGameFinished()) { // Game is naturally finished; we're done diff --git a/src/server/utils/env.ts b/src/server/utils/env.ts index e68fe073..96f9d051 100644 --- a/src/server/utils/env.ts +++ b/src/server/utils/env.ts @@ -4,4 +4,5 @@ config(); export const IS_DEVELOPMENT = process.env.NODE_ENV === "development"; export const IS_PRODUCTION = !IS_DEVELOPMENT; -export const USE_VIRTUAL_ROBOTS = true; +export const DO_SAVES = process.env.ENABLE_SAVES === "true"; +export const USE_VIRTUAL_ROBOTS = process.env.USE_VIRTUAL_ROBOTS === "true";