2018-07-23 11:44:34 +00:00
|
|
|
import { macroName } from "./utils";
|
|
|
|
import point from "./point";
|
2018-07-23 20:14:32 +02:00
|
|
|
import attributes from "./attributes";
|
2018-07-23 11:44:34 +00:00
|
|
|
import * as hooklib from "hooks";
|
2018-07-23 11:12:06 +00:00
|
|
|
|
2018-07-23 11:44:34 +00:00
|
|
|
function part(id) {
|
2018-07-23 20:14:32 +02:00
|
|
|
this.attributes = new attributes();
|
2018-07-23 11:12:06 +00:00
|
|
|
this.points = {};
|
|
|
|
this.paths = {};
|
|
|
|
this.snippets = {};
|
|
|
|
this.id = id;
|
2018-07-23 11:44:34 +00:00
|
|
|
this.render = id.substr(0, 1) === "_" ? false : true;
|
|
|
|
this.points.origin = new point(0, 0);
|
|
|
|
for (let k in hooklib) this[k] = hooklib[k];
|
2018-07-23 11:12:06 +00:00
|
|
|
|
2018-07-23 20:14:32 +02:00
|
|
|
return this;
|
|
|
|
}
|
2018-07-23 11:12:06 +00:00
|
|
|
|
2018-07-23 20:14:32 +02:00
|
|
|
part.prototype.macroRunner = function(args) {
|
|
|
|
let self = this;
|
|
|
|
let data = args;
|
|
|
|
let method = function(key, data) {
|
|
|
|
let macro = macroName(key);
|
|
|
|
if (typeof self[macro] === "function") {
|
|
|
|
self[macro](data);
|
|
|
|
}
|
2018-07-23 11:44:34 +00:00
|
|
|
};
|
2018-07-23 17:35:06 +00:00
|
|
|
|
2018-07-23 20:14:32 +02:00
|
|
|
return method;
|
|
|
|
};
|
2018-07-23 11:12:06 +00:00
|
|
|
|
|
|
|
export default part;
|