Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
uses: actions/setup-node@v2.1.4
- uses: bahmutov/npm-install@v1
- name: nextjs cache
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: ${{ github.workspace }}/.next/cache
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "everdell",
"version": "0.1.0",
"engines": {
"node": "16.x"
"node": "22.x"
},
"private": true,
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/components/gameBoard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ export const GameBoard: React.FC<{
<div className={styles.game_board_meadow}>
<Meadow meadowCards={gameState.meadowCards} />
</div>
<GameLog logs={gameState.gameLog} gameStateJSON={gameStateJSON} />
<GameLog logs={gameState.getGameLog()} gameStateJSON={gameStateJSON} />
</div>
{gameState.gameOptions.newleaf?.station ? (
<>
Expand Down
2 changes: 1 addition & 1 deletion src/model/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class Game {
return cloneDeep({
gameId: this.gameId,
gameSecret: "",
gameState: this.gameState.toJSON(includePrivate),
gameState: this.gameState.toJSON({ includePrivate, isRoot: true }),
// Deprecated, remove after 3/1/21
gameOptions: this.gameOptionsDeprecated,
...(includePrivate
Expand Down
4 changes: 2 additions & 2 deletions src/model/gameState.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2192,14 +2192,14 @@ describe("GameState", () => {
player.nextSeason();
player.nextSeason();
});
expect(gameState.gameLog).eql([
expect(gameState.getGameLog()).eql([
{ entry: [{ type: "text", text: "Game created with 2 players." }] },
{ entry: [{ type: "text", text: "Dealing cards to each player." }] },
{ entry: [{ type: "text", text: "Dealing cards to the Meadow." }] },
]);
gameState = gameState.next({ inputType: GameInputType.GAME_END });
gameState = gameState.next({ inputType: GameInputType.GAME_END });
expect(gameState.gameLog).eql([
expect(gameState.getGameLog()).eql([
{ entry: [{ type: "text", text: "Game created with 2 players." }] },
{ entry: [{ type: "text", text: "Dealing cards to each player." }] },
{ entry: [{ type: "text", text: "Dealing cards to the Meadow." }] },
Expand Down
36 changes: 28 additions & 8 deletions src/model/gameState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ import { VisitorStack, intialVisitorStack } from "./visitor";
const MEADOW_SIZE = 8;
const STATION_SIZE = 3;
const STARTING_PLAYER_HAND_SIZE = 5;
const MAX_GAME_LOG_BUFFER = 500;
const MAX_GAME_LOG_BUFFER = 100;

const PRINT_GAME_LOGS = false;

Expand Down Expand Up @@ -142,7 +142,7 @@ export const gameTextToDebugStr = (gameText: GameText): string => {
export class GameState {
readonly gameStateId: number;
readonly gameOptions: GameOptions;
readonly gameLog: GameLogEntry[];
private gameLog: GameLogEntry[];

// GameInputs that need to be shown to the user.
readonly pendingGameInputs: GameInputMultiStep[];
Expand Down Expand Up @@ -235,6 +235,14 @@ export class GameState {
return this._activePlayerId;
}

getGameLog(): GameLogEntry[] {
return this.gameLog;
}

setGameLog(gameLog: GameLogEntry[]): void {
this.gameLog = gameLog;
}

addGameLogFromTrainCarTile(
name: TrainCarTileName,
args: Parameters<typeof toGameText>[0]
Expand Down Expand Up @@ -331,7 +339,13 @@ export class GameState {
});
}

toJSON(includePrivate: boolean): GameStateJSON {
toJSON({
includePrivate,
isRoot,
}: {
includePrivate: boolean;
isRoot: boolean;
}): GameStateJSON {
return cloneDeep({
...{
gameStateId: this.gameStateId,
Expand All @@ -344,7 +358,6 @@ export class GameState {
playedGameInputs: [],
deck: this.deck.toJSON(includePrivate),
discardPile: this.discardPile.toJSON(includePrivate),
gameLog: this.gameLog,
gameOptions: this.gameOptions,
riverDestinationMap: this.riverDestinationMap
? this.riverDestinationMap.toJSON(includePrivate)
Expand All @@ -360,13 +373,14 @@ export class GameState {
: null,
stationCards: this.stationCards,
gameStateJSONForUndo: null,
gameLog: isRoot ? this.gameLog.slice(-MAX_GAME_LOG_BUFFER) : [],
},
...(includePrivate
? {
pendingGameInputs: this.pendingGameInputs,
playedGameInputs: this.playedGameInputs,
gameStateJSONForUndo: this.gameStateForUndo
? this.gameStateForUndo.toJSON(true)
? this.gameStateForUndo.toJSON({ includePrivate, isRoot: false })
: null,
}
: {}),
Expand Down Expand Up @@ -522,12 +536,12 @@ export class GameState {
}

clone(): GameState {
const gameStateJSON = this.toJSON(true /* includePrivate */);
const gameStateJSON = this.toJSON({ includePrivate: true, isRoot: true });
return GameState.fromJSON(gameStateJSON);
}

private cloneAndIncrementGameStateId(): GameState {
const gameStateJSON = this.toJSON(true /* includePrivate */);
const gameStateJSON = this.toJSON({ includePrivate: true, isRoot: true });
gameStateJSON.gameStateId += 1;
return GameState.fromJSON(gameStateJSON);
}
Expand Down Expand Up @@ -1337,7 +1351,13 @@ export class GameState {
if (!this.gameStateForUndo) {
throw new Error("Unable to undo");
}
return this.gameStateForUndo;
const nextState = this.gameStateForUndo;
nextState.setGameLog(this.gameLog.slice(-MAX_GAME_LOG_BUFFER));
nextState.addGameLog([
this.getActivePlayer(),
" undid their last action.",
]);
return nextState;
}
if (this.gameOptions.allowUndo && !skipUndo) {
this.gameStateForUndo = this.clone();
Expand Down