1
0
Fork 0
freesewing/packages/brian/src/index.js

68 lines
2 KiB
JavaScript
Raw Normal View History

import freesewing from "freesewing";
2018-08-11 14:13:40 +02:00
import pluginBundle from "@freesewing/plugin-bundle";
import config from "../config/config";
import { version } from "../package.json";
import base from "./base";
2018-07-24 10:16:31 +00:00
import back from "./back";
2018-08-03 17:44:55 +02:00
import front from "./front";
import sleevecap from "./sleevecap";
2018-08-06 16:19:12 +02:00
import sleeve from "./sleeve";
2018-07-26 13:43:45 +00:00
const Brian = function(settings = false) {
// Make this a new freesewing.Pattern instance
freesewing.Pattern.call(this, { version: version, ...config });
// Load plugins
this.with(pluginBundle);
// Merge settings passed to the constructor
if (settings !== false) this.mergeSettings(settings);
2018-12-11 18:50:52 +01:00
return this;
};
// Setup inheritance
Brian.prototype = Object.create(freesewing.Pattern.prototype);
Brian.prototype.constructor = Brian;
// Draft method
Brian.prototype._draft = function() {
this.parts.base = this.draftBase(this.createPart());
if (!this.needs("base", true)) this.parts.base.render = false;
if (this.needs(["back", "front", "sleeve", "sleevecap"])) {
this.parts.back = this.draftBack(this.createPart().copy(this.parts.base));
}
if (this.needs(["front", "sleeve", "sleevecap"])) {
this.parts.front = this.draftFront(this.createPart().copy(this.parts.back));
}
if (this.needs(["sleeve", "sleevecap"])) {
this.parts.sleevecap = this.draftSleevecap(this.createPart());
// Don't render sleevecap unless specifically requested
if (!this.needs("sleevecap", true)) this.parts.sleevecap.render = false;
}
if (this.needs("sleeve")) {
this.parts.sleeve = this.draftSleeve(
this.createPart().copy(this.parts.sleevecap)
);
}
return this;
};
// Per-part draft methods
Brian.prototype.draftBase = function(part) {
return base.draft(part);
};
Brian.prototype.draftBack = function(part) {
return back.draft(part);
};
Brian.prototype.draftFront = function(part) {
return front.draft(part);
};
Brian.prototype.draftSleevecap = function(part) {
return sleevecap.draft(part);
};
Brian.prototype.draftSleeve = function(part) {
return sleeve.draft(part);
};
export default Brian;