wip: Work on editor
This commit is contained in:
parent
922bd04130
commit
94b8efa4a2
31 changed files with 677 additions and 614 deletions
|
@ -1,5 +1,5 @@
|
|||
// Dependencies
|
||||
import { defaultConfig as config } from '../config/index.mjs'
|
||||
import { defaultConfig } from '../config/index.mjs'
|
||||
import { degreeMeasurements } from '@freesewing/config'
|
||||
|
||||
/*
|
||||
|
@ -16,46 +16,9 @@ export function designMeasurements(Design, measies = {}) {
|
|||
|
||||
return measurements
|
||||
}
|
||||
/**
|
||||
* Helper method to determine whether all required measurements for a design are present
|
||||
*
|
||||
* @param {object} Design - The FreeSewing design (or a plain object holding measurements)
|
||||
* @param {object} measurements - An object holding the user's measurements
|
||||
* @return {array} result - An array where the first element is true when we
|
||||
* have all measurements, and false if not. The second element is a list of
|
||||
* missing measurements.
|
||||
*/
|
||||
export function hasRequiredMeasurements(Design, measurements = {}) {
|
||||
/*
|
||||
* If design is just a plain object holding measurements, we restructure it as a Design
|
||||
* AS it happens, this method is smart enough to test for this, so we call it always
|
||||
*/
|
||||
Design = structureMeasurementsAsDesign(Design)
|
||||
|
||||
/*
|
||||
* Walk required measuremnets, and keep track of what's missing
|
||||
*/
|
||||
const missing = []
|
||||
for (const m of Design.patternConfig?.measurements || []) {
|
||||
if (typeof measurements[m] === 'undefined') missing.push(m)
|
||||
}
|
||||
|
||||
/*
|
||||
* Return true or false, plus a list of missing measurements
|
||||
*/
|
||||
return [missing.length === 0, missing]
|
||||
}
|
||||
/**
|
||||
* Helper method to determine whether a measurement uses degrees
|
||||
*
|
||||
* @param {string} name - The name of the measurement
|
||||
* @return {bool} isDegree - True if the measurment is a degree measurement
|
||||
*/
|
||||
export function isDegreeMeasurement(name) {
|
||||
return degreeMeasurements.indexOf(name) !== -1
|
||||
}
|
||||
/*
|
||||
* Helper method to check whether measururements are missing
|
||||
* Helper method to check whether measurements are missing
|
||||
*
|
||||
* Note that this does not actually check the settings against
|
||||
* the chosen design, but rather relies on the missing measurements
|
||||
|
@ -63,22 +26,12 @@ export function isDegreeMeasurement(name) {
|
|||
* so we do it only once.
|
||||
*
|
||||
* @param {object} state - The Editor state
|
||||
* @param {object} config - The Editor configuration
|
||||
* @return {bool} missing - True if there are missing measurments, false if not
|
||||
*/
|
||||
export function missingMeasurements(state, config) {
|
||||
export function missingMeasurements(state) {
|
||||
return (
|
||||
!config.measurementsFreeViews.includes(state.view) &&
|
||||
!defaultConfig.measurementsFreeViews.includes(state.view) &&
|
||||
state._.missingMeasurements &&
|
||||
state._.missingMeasurements.length > 0
|
||||
)
|
||||
}
|
||||
/*
|
||||
* This takes a POJO of measurements, and turns it into a structure that matches a design object
|
||||
*
|
||||
* @param {object} measurements - The POJO of measurments
|
||||
* @return {object} design - The measurements structured as a design object
|
||||
*/
|
||||
export function structureMeasurementsAsDesign(measurements) {
|
||||
return measurements.patternConfig ? measurements : { patternConfig: { measurements } }
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue