Skip to content

Commit

Permalink
move whether to save games and use virtual robots into env
Browse files Browse the repository at this point in the history
  • Loading branch information
xXDMOGXx committed Nov 19, 2024
1 parent 579224b commit de268c9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -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
19 changes: 11 additions & 8 deletions src/server/api/game-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -181,13 +182,15 @@ export class ComputerGameManager extends GameManager {
public async handleMessage(message: Message, id: string): Promise<void> {
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
Expand Down
3 changes: 2 additions & 1 deletion src/server/utils/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

0 comments on commit de268c9

Please sign in to comment.