Allow saving and restoring save games
This commit is contained in:
parent
7a28a7e314
commit
01fea03112
2 changed files with 44 additions and 0 deletions
|
@ -73,6 +73,34 @@ export class Game
|
||||||
return this.state.board;
|
return this.state.board;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dumps the state of the game.
|
||||||
|
*
|
||||||
|
* @returns {IState}
|
||||||
|
* The JSON string representing the state.
|
||||||
|
*/
|
||||||
|
dump()
|
||||||
|
{
|
||||||
|
return {
|
||||||
|
turnCount: this.state.turnCount,
|
||||||
|
board: {
|
||||||
|
...this.state.board
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads the game from the specified {@link data `data`}.
|
||||||
|
*
|
||||||
|
* @param {IState} data
|
||||||
|
* The data to load.
|
||||||
|
*/
|
||||||
|
load(data)
|
||||||
|
{
|
||||||
|
this.state.turnCount = data.turnCount;
|
||||||
|
Object.assign(this.state.board, data.board);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes the game.
|
* Initializes the game.
|
||||||
*/
|
*/
|
||||||
|
|
16
packages/game/src/js/types.d.ts
vendored
16
packages/game/src/js/types.d.ts
vendored
|
@ -12,3 +12,19 @@ type Row = CellOwner[];
|
||||||
* Represents a game board.
|
* Represents a game board.
|
||||||
*/
|
*/
|
||||||
type Board = Row[];
|
type Board = Row[];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents the state of a game.
|
||||||
|
*/
|
||||||
|
interface IState
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The number of rounds that have been played.
|
||||||
|
*/
|
||||||
|
turnCount: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The board of the game.
|
||||||
|
*/
|
||||||
|
board: Board;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue