diff --git a/packages/core/src/part.js b/packages/core/src/part.js index 653d251a532..8b3dc8e2dac 100644 --- a/packages/core/src/part.js +++ b/packages/core/src/part.js @@ -194,6 +194,8 @@ Part.prototype.shorthand = function () { paperless, events: this.context.events, raise: this.context.raise, + addCut: this.addCut, + removeCut: this.removeCut, } if (this.context.settings.debug) { diff --git a/packages/core/src/pattern.js b/packages/core/src/pattern.js index 7a353395e35..2b16ea2ad31 100644 --- a/packages/core/src/pattern.js +++ b/packages/core/src/pattern.js @@ -59,6 +59,7 @@ export default function Pattern(config = { options: {} }) { this.height = 0 // Will be set after render this.is = '' // Will be set when drafting/sampling this.autoLayout = { parts: {} } // Will hold auto-generated layout + this.cutList = {} // Will hold the cutlist this.store = new Store(this.raise) // Store for sharing data across parts this.parts = {} // Parts container @@ -191,6 +192,7 @@ Pattern.prototype.runHooks = function (hookName, data = false) { Pattern.prototype.draft = function () { if (this.is !== 'sample') { this.is = 'draft' + this.cutList = {} this.raise.debug(`Drafting pattern`) } // Handle snap for pct options @@ -229,6 +231,7 @@ Pattern.prototype.draft = function () { } try { this.parts[partName] = this[method](this.parts[partName]) + if (this.parts[partName].render ) this.cutList[partName] = this.parts[partName].cut } catch (err) { this.raise.error([`Unable to draft part \`${partName}\``, err]) } @@ -669,6 +672,13 @@ Pattern.prototype.wants = function (partName) { return true } +/** + * Returns the cutList property + */ +Pattern.prototype.getCutList = function () { + return this.cutList +} + /** Returns props required to render this pattern through * an external renderer (eg. a React component) */ @@ -692,6 +702,7 @@ Pattern.prototype.getRenderProps = function () { warning: this.events.warning, error: this.events.error, } + props.cutList = this.cutList props.parts = {} for (let p in this.parts) { if (this.parts[p].render) { diff --git a/packages/core/tests/pattern.test.js b/packages/core/tests/pattern.test.js index 9dba8cc1b9f..f9c9b64e112 100644 --- a/packages/core/tests/pattern.test.js +++ b/packages/core/tests/pattern.test.js @@ -711,4 +711,22 @@ it("Should handle a list snapped option", () => { expect(freesewing.utils.round(pattern.parts.front.paths.line_10.ops[1].to.x)).to.equal(33.72); }); +it("Should retrieve the cutList", () => { + const Test = new freesewing.Design({ + name: "test", + parts: ['front'], + }) + Test.prototype.draftFront = function(part) { + part.addCut(4, 'lining', true) + + return part + }; + const pattern = new Test() + expect(JSON.stringify(pattern.getCutList())).to.equal(JSON.stringify({})) + pattern.draft() + console.log(pattern.parts.front.cut) + const list = `{"front":{"grain":90,"materials":{"lining":{"cut":4,"identical":true}}}}` + expect(JSON.stringify(pattern.getCutList())).to.equal(list) +}); +