feat(core): Added pattern.getCutList() method
This commit is contained in:
parent
792021b60f
commit
6acb9f976a
3 changed files with 31 additions and 0 deletions
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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)
|
||||
});
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue