@gamepark/rules-api
Version:
API to implement the rules of a board game
47 lines • 1.52 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.GameMemory = void 0;
/**
* Utility class to manipulate the memory in a {@link MaterialGame}.
*/
var GameMemory = /** @class */ (function () {
/**
* @constructor
* @param {MaterialGame} game Current state of the game
*/
function GameMemory(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
*/
GameMemory.prototype.memorize = function (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)
*/
GameMemory.prototype.remind = function (key) {
return this.game.memory[key];
};
/**
* Delete a value from the memory
* @param key Key of the value to delete
*/
GameMemory.prototype.forget = function (key) {
delete this.game.memory[key];
};
return GameMemory;
}());
exports.GameMemory = GameMemory;
//# sourceMappingURL=GameMemory.js.map