1
0
Fork 0
freesewing/lib/part.ts

42 lines
1,000 B
TypeScript
Raw Normal View History

2018-07-12 12:53:49 +00:00
import { Point } from './point'
2018-07-14 16:04:39 +00:00
import { Path } from './path'
import { Snippet } from './snippet'
2018-07-14 16:04:39 +00:00
import { Attributes } from './attributes'
import hooklib from 'hooks'
2018-07-10 19:29:09 +02:00
2018-07-12 12:53:49 +00:00
export class Part {
id: string;
render: boolean;
points: { [index: string]: Point; } = {};
2018-07-14 16:04:39 +00:00
paths: { [index: string]: Path; } = {};
snippets: { [index: string]: Snippet; } = {};
2018-07-14 16:04:39 +00:00
attributes = new Attributes();
// Expose constructors for macros
point: Point = Point;
path: Path = Path;
attr: Attribute = Attributes;
2018-07-11 12:45:02 +00:00
[propName: string]: any;
2018-07-10 19:29:09 +02:00
2018-07-12 12:53:49 +00:00
constructor(id: string) {
2018-07-10 19:29:09 +02:00
this.id = id;
2018-07-12 12:53:49 +00:00
this.render = (id.substr(0,1) === '_') ? false : true;
2018-07-16 15:20:50 +00:00
this.points.origin = new Point(0,0);
for(let k in hooklib) this[k] = hooklib[k];
2018-07-10 19:29:09 +02:00
return this;
}
2018-07-19 14:43:45 +00:00
macroRunner(args?) {
let self = this;
let data = args;
let method = function (key, data) {
let macro = `_macro_${key}`;
if(typeof self[macro] === 'function') {
self[macro](data);
}
}
2018-07-19 14:43:45 +00:00
return method;
}
2018-07-10 19:29:09 +02:00
}