UNPKG

@gamepark/rules-api

Version:

API to implement the rules of a board game

43 lines 1.24 kB
/** * Utility class to manipulate the memory in a {@link MaterialGame}. */ export class GameMemory { game; /** * @constructor * @param {MaterialGame} game Current state of the game */ constructor(game) { this.game = game; } /** * Save a new value inside the memory * @param key The key to index the memorized value * @param value Any JSON serializable value to store, or a function that takes previous stored value and returns the new value to store */ memorize(key, value) { if (typeof value === 'function') { this.game.memory[key] = value(this.game.memory[key]); } else { this.game.memory[key] = value; } return this.game.memory[key]; } /** * Get a value stored in the memory * @param key The key to index the memorized value * @returns the value stored (or undefined is nothing was stored under this key yet) */ remind(key) { return this.game.memory[key]; } /** * Delete a value from the memory * @param key Key of the value to delete */ forget(key) { delete this.game.memory[key]; } } //# sourceMappingURL=GameMemory.js.map