38 lines
892 B
TypeScript
38 lines
892 B
TypeScript
import { PatternConfig, PatternOption } from './types'
|
|
import { Part } from './part'
|
|
import { Renderer } from './renderer'
|
|
import { Option } from './option'
|
|
|
|
export class Pattern {
|
|
config: PatternConfig;
|
|
parts: {
|
|
[index: string]: Part;
|
|
}
|
|
options: {[propName: string]: number};
|
|
|
|
constructor(config: PatternConfig) {
|
|
this.config = config;
|
|
|
|
this.parts = {};
|
|
for (let id of config.parts) {
|
|
this.parts[id] = new Part(id);
|
|
}
|
|
|
|
this.options = {};
|
|
for (let conf of config.options) {
|
|
if(conf.type === 'percentage') this.options[conf.id] = conf.val/100;
|
|
else this.options[conf.id] = conf.val;
|
|
}
|
|
|
|
return this;
|
|
}
|
|
|
|
draft(config: object): void {
|
|
throw Error('You have to implement the draft() method in your Pattern instance.');
|
|
}
|
|
|
|
render(pattern: Pattern): string {
|
|
let r = new Renderer();
|
|
return r.render(pattern);
|
|
}
|
|
}
|