From a56e20464db28289c52012dfe1b614c15a395dd1 Mon Sep 17 00:00:00 2001 From: joostdecock Date: Sun, 4 Sep 2022 19:03:18 +0200 Subject: [PATCH] chore(sandy): Ported to v3 --- designs/sandy/config/index.js | 46 ------------------------ designs/sandy/src/curved-waistband.mjs | 4 +-- designs/sandy/src/index.mjs | 26 ++++++-------- designs/sandy/src/shared.mjs | 4 +-- designs/sandy/src/skirt.mjs | 29 +++++++++++++-- designs/sandy/src/straight-waistband.mjs | 2 +- designs/sandy/src/waistband.mjs | 15 +++++--- tests/designs/config.mjs | 28 ++++++++------- 8 files changed, 66 insertions(+), 88 deletions(-) delete mode 100644 designs/sandy/config/index.js diff --git a/designs/sandy/config/index.js b/designs/sandy/config/index.js deleted file mode 100644 index 6dd2fc2c81a..00000000000 --- a/designs/sandy/config/index.js +++ /dev/null @@ -1,46 +0,0 @@ -import pkg from '../package.json' assert { type: 'json' } -import configHelpers from '@freesewing/config-helpers' - -const { version } = pkg -const { elastics, pctBasedOn } = configHelpers - -export default { - name: 'sandy', - version: version, - design: 'Erica Alcusa Sáez', - code: ['Erica Alcusa Sáez', 'Joost De Cock'], - department: 'bottoms', - type: 'pattern', - difficulty: 3, - optionGroups: { - fit: ['waistbandPosition', 'waistbandShape'], - style: ['lengthBonus', 'circleRatio', 'waistbandWidth', 'waistbandOverlap', 'gathering'], - construction: ['seamlessFullCircle', 'hemWidth'], - }, - measurements: ['waist', 'waistToFloor', 'waistToHips', 'hips'], - dependencies: { - waistband: 'skirt', - }, - options: { - // Constants - minimumOverlap: 15, // Lower than this and we don't draw a button - - // Bool - seamlessFullCircle: { bool: false }, - - // Percentages - waistbandWidth: { pct: 4, min: 1, max: 8, snap: elastics, ...pctBasedOn('waistToFloor') }, - waistbandPosition: { pct: 50, min: 0, max: 100 }, - lengthBonus: { pct: 50, min: 10, max: 100 }, - circleRatio: { pct: 50, min: 20, max: 100 }, - waistbandOverlap: { pct: 3, min: 0, max: 15 }, - gathering: { pct: 0, min: 0, max: 200 }, - hemWidth: { pct: 2, min: 1, max: 10 }, - - // Lists - waistbandShape: { - list: ['straight', 'curved'], - dflt: 'straight', - }, - }, -} diff --git a/designs/sandy/src/curved-waistband.mjs b/designs/sandy/src/curved-waistband.mjs index be8cdf8db75..fffa3e31ebf 100644 --- a/designs/sandy/src/curved-waistband.mjs +++ b/designs/sandy/src/curved-waistband.mjs @@ -1,6 +1,6 @@ -import draftRingSector from './shared' +import { draftRingSector } from './shared.mjs' -export default function (part) { +export function draftCurvedWaistband(part) { /** * The curved waistband is just a ring sector with external * and intenal radius and angle calculated from measurements diff --git a/designs/sandy/src/index.mjs b/designs/sandy/src/index.mjs index c8c6a09d41f..b1232a3726d 100644 --- a/designs/sandy/src/index.mjs +++ b/designs/sandy/src/index.mjs @@ -1,19 +1,13 @@ -import freesewing from '@freesewing/core' -import plugins from '@freesewing/plugin-bundle' -import config from '../config' -// Parts -import draftSkirt from './skirt' -import draftWaistband from './waistband' +import { Design } from '@freesewing/core' +import { data } from '../data.mjs' +import { skirt } from './skirt.mjs' +import { waistband } from './waistband.mjs' -// Create design -const Sandy = new freesewing.Design(config, plugins) - -// Attach draft methods to prototype -Sandy.prototype.draftSkirt = (part) => draftSkirt(part) -Sandy.prototype.draftWaistband = (part) => draftWaistband(part) +// Setup our new design +const Sandy = new Design({ + data, + parts: [skirt, waistband], +}) // Named exports -export { config, Sandy } - -// Default export -export default Sandy +export { skirt, waistband, Sandy } diff --git a/designs/sandy/src/shared.mjs b/designs/sandy/src/shared.mjs index 2e9826dd4cf..ee13eb7f5b2 100644 --- a/designs/sandy/src/shared.mjs +++ b/designs/sandy/src/shared.mjs @@ -1,4 +1,4 @@ -const draftRingSector = (part, rot, an, radIn, radEx, rotate = false) => { +export const draftRingSector = (part, rot, an, radIn, radEx, rotate = false) => { const { utils, Point, points, Path } = part.shorthand() const roundExtended = (radius, angle = 90) => { @@ -103,5 +103,3 @@ const draftRingSector = (part, rot, an, radIn, radEx, rotate = false) => { .curve(points.ex1CFlipped, points.ex2CFlipped, points.ex2Flipped) .close() } - -export default draftRingSector diff --git a/designs/sandy/src/skirt.mjs b/designs/sandy/src/skirt.mjs index 10b97c839e7..a242634b7de 100644 --- a/designs/sandy/src/skirt.mjs +++ b/designs/sandy/src/skirt.mjs @@ -1,6 +1,9 @@ -import draftRingSector from './shared' +import { draftRingSector } from './shared.mjs' +import { pctBasedOn } from '@freesewing/core' +import { pluginBundle } from '@freesewing/plugin-bundle' +import { elastics } from '@freesewing/snapseries' -export default function (part) { +function sandySkirt(part) { const { utils, store, @@ -208,3 +211,25 @@ export default function (part) { return part } + +export const skirt = { + name: 'sandy.skirt', + measurements: ['waist', 'waistToFloor', 'waistToHips', 'hips'], + plugins: pluginBundle, + options: { + minimumOverlap: 15, // Lower than this and we don't draw a button + seamlessFullCircle: { bool: false }, + waistbandWidth: { pct: 4, min: 1, max: 8, snap: elastics, ...pctBasedOn('waistToFloor') }, + waistbandPosition: { pct: 50, min: 0, max: 100 }, + lengthBonus: { pct: 50, min: 10, max: 100 }, + circleRatio: { pct: 50, min: 20, max: 100 }, + waistbandOverlap: { pct: 3, min: 0, max: 15 }, + gathering: { pct: 0, min: 0, max: 200 }, + hemWidth: { pct: 2, min: 1, max: 10 }, + waistbandShape: { + list: ['straight', 'curved'], + dflt: 'straight', + }, + }, + draft: sandySkirt, +} diff --git a/designs/sandy/src/straight-waistband.mjs b/designs/sandy/src/straight-waistband.mjs index 1cbd43a96b9..ef85bff44b6 100644 --- a/designs/sandy/src/straight-waistband.mjs +++ b/designs/sandy/src/straight-waistband.mjs @@ -1,4 +1,4 @@ -export default function (part) { +export function draftStraightWaistband(part) { /** * The straight waistband is just a rectangle with the width * of double the waistband width, since it will be folded diff --git a/designs/sandy/src/waistband.mjs b/designs/sandy/src/waistband.mjs index 7c64a5848be..1475cfe3ee4 100644 --- a/designs/sandy/src/waistband.mjs +++ b/designs/sandy/src/waistband.mjs @@ -1,9 +1,14 @@ -import straightWaistband from './straight-waistband' -import curvedWaistband from './curved-waistband' +import { draftStraightWaistband } from './straight-waistband.mjs' +import { draftCurvedWaistband } from './curved-waistband.mjs' -export default (part) => { +const sandyWaistband = (part) => { const { options } = part.shorthand() - if (options.waistbandShape === 'curved') return curvedWaistband(part) - else return straightWaistband(part) + if (options.waistbandShape === 'curved') return draftCurvedWaistband(part) + else return draftStraightWaistband(part) +} + +export const waistband = { + name: 'sandy.waistband', + draft: sandyWaistband, } diff --git a/tests/designs/config.mjs b/tests/designs/config.mjs index bdd5564674b..a056f604c5c 100644 --- a/tests/designs/config.mjs +++ b/tests/designs/config.mjs @@ -64,22 +64,24 @@ export const testPatternConfig = (Pattern) => { // Config tests for non-utility patterns only if (family !== 'utilities') { it(` - 'design' should be set and be a string of reasonable length`, () => { - if (Array.isArray(meta.design)) { - for (const person of meta.design) { - expect(typeof person).to.equal('string') - expect(person.length > 2).to.be.true - expect(person.length < 80).to.be.true - } - } else { - expect(typeof meta.design).to.equal('string') - expect(meta.design.length > 2).to.be.true - expect(meta.design.length < 80).to.be.true + const people = Array.isArray(meta.design) + ? meta.design + : [ meta.design ] + for (const person of people) { + expect(typeof person).to.equal('string') + expect(person.length > 2).to.be.true + expect(person.length < 80).to.be.true } }) it(` - 'code' should be set and be a string of reasonable length`, () => { - expect(typeof meta.code).to.equal('string') - expect(meta.code.length > 2).to.be.true - expect(meta.code.length < 80).to.be.true + const people = Array.isArray(meta.code) + ? meta.design + : [ meta.design ] + for (const person of people) { + expect(typeof person).to.equal('string') + expect(person.length > 2).to.be.true + expect(person.length < 80).to.be.true + } }) it(` - 'department' should be set and be a string of reasonable length`, () => { expect(typeof meta.code).to.equal('string')