@erikyuzwa/rogue-punk
Version:
a JavaScript library to help you build your roguelike adventures
25 lines (24 loc) • 729 B
JavaScript
import { getRandomElement } from './Utility';
export 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(getRandomElement(Object.keys(this.randomTemplates)));
}
;
}