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'
|
2018-07-15 08:36:19 +00:00
|
|
|
import { Svg } from './svg'
|
2018-07-12 12:53:49 +00:00
|
|
|
import { Option } from './option'
|
2018-07-15 08:36:19 +00:00
|
|
|
import themes from './themes'
|
|
|
|
import { Theme } from './themes/theme'
|
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-15 08:36:19 +00:00
|
|
|
svg: Svg = new Svg();
|
2018-07-14 16:04:39 +00:00
|
|
|
parts: {
|
|
|
|
[index: string]: Part;
|
|
|
|
}
|
2018-07-12 07:37:52 +00:00
|
|
|
options: {[propName: string]: number};
|
2018-07-15 08:36:19 +00:00
|
|
|
themes: {[index:string]: Theme} = themes;
|
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-14 16:04:39 +00:00
|
|
|
|
2018-07-15 08:36:19 +00:00
|
|
|
render(): string {
|
|
|
|
let svg = new Svg();
|
|
|
|
return svg.render(this);
|
2018-07-14 16:04:39 +00:00
|
|
|
}
|
2018-07-10 12:20:53 +00:00
|
|
|
}
|