@erikyuzwa/rogue-punk
Version:
a JavaScript library to help you build your roguelike adventures
29 lines (28 loc) • 870 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Repository = void 0;
const Utility_1 = require("./Utility");
class Repository {
constructor(name, konstructor) {
this.name = name;
this.templates = {};
this.konstructor = konstructor;
this.randomTemplates = {};
}
define(name, template, options) {
this.templates.name = template;
}
create(name) {
if (!this.templates.name) {
throw new Error("No template named '" + name + "' in repository '" + this.name + "'");
}
const template = Object.create(this.templates.name);
return new this.konstructor(template);
}
;
createRandom() {
return this.create((0, Utility_1.getRandomElement)(Object.keys(this.randomTemplates)));
}
;
}
exports.Repository = Repository;