2018-07-10 19:29:09 +02:00
|
|
|
import { PatternConfig, PatternOption } from './types'
|
2018-07-12 12:53:49 +00:00
|
|
|
import { Part } from './part'
|
|
|
|
import { Option } from './option'
|
2018-07-10 12:20:53 +00:00
|
|
|
|
2018-07-12 12:53:49 +00:00
|
|
|
export class Pattern {
|
2018-07-10 12:20:53 +00:00
|
|
|
config: PatternConfig;
|
2018-07-10 19:29:09 +02:00
|
|
|
parts: {[propName: string]: Part};
|
2018-07-12 07:37:52 +00:00
|
|
|
options: {[propName: string]: number};
|
2018-07-10 12:20:53 +00:00
|
|
|
|
|
|
|
constructor(config: PatternConfig) {
|
|
|
|
this.config = config;
|
|
|
|
|
2018-07-10 19:29:09 +02:00
|
|
|
this.parts = {};
|
|
|
|
for (let id of config.parts) {
|
|
|
|
this.parts[id] = new Part(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.options = {};
|
|
|
|
for (let conf of config.options) {
|
2018-07-12 07:37:52 +00:00
|
|
|
if(conf.type === 'percentage') this.options[conf.id] = conf.val/100;
|
|
|
|
else this.options[conf.id] = conf.val;
|
2018-07-10 19:29:09 +02:00
|
|
|
}
|
|
|
|
|
2018-07-10 12:20:53 +00:00
|
|
|
return this;
|
|
|
|
}
|
2018-07-10 19:29:09 +02:00
|
|
|
|
|
|
|
draft(config: object): void {
|
|
|
|
throw Error('You have to implement the draft() method in your Pattern instance.');
|
|
|
|
}
|
2018-07-10 12:20:53 +00:00
|
|
|
}
|