UNPKG

malwoden

Version:

![alt text](./coverage/badge-lines.svg) ![alt text](./coverage/badge-statements.svg) ![alt text](./coverage/badge-functions.svg) ![alt text](./coverage/badge-branches.svg)

65 lines 2.03 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Builder = void 0; var struct_1 = require("../struct"); /** * Builder represents a base class used to create a new kind of map. * It is meant to be inherited from, with individual specialized builders * providing additional information as they generate the map. This basic Builder * class can still be used for it's snapshot functionality when playing with custom * map generation. * * A builder's type should generally be either a number or numeric enum. */ var Builder = /** @class */ (function () { /** * Creates a new Builder * @param config.width - The map width * @param config.height - The map height */ function Builder(config) { this.snapshots = []; this.map = new struct_1.Table(config.width, config.height); } /** * Returns the internal map. * @returns - Table<T> */ Builder.prototype.getMap = function () { return this.map; }; /** * Takes a snapshot of the current map state. These can * be retrieved through getSnapshots() */ Builder.prototype.takeSnapshot = function () { this.snapshots.push(this.map.clone()); }; /** * Returns previously captured snapshots. * @returns - Table<T>[] */ Builder.prototype.getSnapshots = function () { return this.snapshots; }; /** * Clear previously captured snapshots. */ Builder.prototype.clearSnapshots = function () { this.snapshots = []; }; /** * Sets the map values to match a given table. A shallow copy is made * from the given table. * @param table */ Builder.prototype.copyFrom = function (table) { if (this.map.isSameSize(table) === false) { throw new Error("Cannot copy between builders of different sizes"); } this.map = table.clone(); }; return Builder; }()); exports.Builder = Builder; //# sourceMappingURL=builder.js.map