Merge branch 'develop' into i18n3
This commit is contained in:
commit
1264a07afe
194 changed files with 2838 additions and 1691 deletions
|
@ -27,6 +27,7 @@ import {
|
|||
lineIntersectsCurve,
|
||||
linesIntersect,
|
||||
mergeI18n,
|
||||
mergeOptions,
|
||||
pctBasedOn,
|
||||
pointOnBeam,
|
||||
pointOnCurve,
|
||||
|
@ -72,6 +73,7 @@ export {
|
|||
lineIntersectsCurve,
|
||||
linesIntersect,
|
||||
mergeI18n,
|
||||
mergeOptions,
|
||||
pctBasedOn,
|
||||
pointOnBeam,
|
||||
pointOnCurve,
|
||||
|
|
|
@ -314,7 +314,11 @@ Pattern.prototype.__init = function () {
|
|||
// Merges default options with user provided ones
|
||||
this.__loadOptionDefaults()
|
||||
|
||||
this.store.log.info(`Pattern initialized. Draft order is: ${this.config.draftOrder.join(', ')}`)
|
||||
this.store.log.info(
|
||||
`Pattern initialized. Draft order is: ${this.config.draftOrder
|
||||
.map((item) => `\`${item}\``)
|
||||
.join(', ')}`
|
||||
)
|
||||
|
||||
this.__runHooks('postInit')
|
||||
this.__initialized = true
|
||||
|
@ -372,7 +376,7 @@ Pattern.prototype.__runHooks = function (hookName, data = false) {
|
|||
if (data === false) data = this
|
||||
let hooks = this.plugins.hooks[hookName]
|
||||
if (hooks.length > 0) {
|
||||
this.store.log.debug(`Running \`${hookName}\` hooks`)
|
||||
this.store.log.debug(`🪝 Running \`${hookName}\` hooks`)
|
||||
for (let hook of hooks) {
|
||||
hook.method(data, hook.data)
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { PatternDraftQueue } from './pattern-draft-queue.mjs'
|
||||
import { Part } from '../part.mjs'
|
||||
import { __macroName } from '../utils.mjs'
|
||||
import { __macroName, mergeOptions } from '../utils.mjs'
|
||||
|
||||
/**
|
||||
* A class to handle drafting a pattern
|
||||
|
@ -26,9 +26,9 @@ PatternDrafter.prototype.draft = function () {
|
|||
this.pattern.setStores[set] = this.pattern.__createSetStore()
|
||||
this.__useSet(set)
|
||||
|
||||
this.activeStore.log.debug(`Initialized store for set ${set}`)
|
||||
this.activeStore.log.debug(`🗃️ Initialized store for set \`${set}\``)
|
||||
this.pattern.__runHooks('preSetDraft')
|
||||
this.activeStore.log.debug(`📐 Drafting pattern for set ${set}`)
|
||||
this.activeStore.log.debug(`📐 Drafting pattern for set \`${set}\``)
|
||||
|
||||
// Create parts container
|
||||
this.pattern.parts[set] = {}
|
||||
|
@ -69,7 +69,7 @@ PatternDrafter.prototype.draftPartForSet = function (partName, set) {
|
|||
const configPart = this.pattern.config.parts?.[partName]
|
||||
if (typeof configPart?.draft !== 'function') {
|
||||
this.activeStore.log.error(
|
||||
`Unable to draft pattern part __${partName}__. Part.draft() is not callable`
|
||||
`Unable to draft pattern part \`${partName}\`. Part.draft() is not callable`
|
||||
)
|
||||
return
|
||||
}
|
||||
|
@ -84,7 +84,7 @@ PatternDrafter.prototype.draftPartForSet = function (partName, set) {
|
|||
|
||||
if (typeof result === 'undefined') {
|
||||
this.activeStore.log.error(
|
||||
`Result of drafting part ${partName} was undefined. Did you forget to return the part?`
|
||||
`Result of drafting part \`${partName}\` was undefined. Did you forget to return the part?`
|
||||
)
|
||||
} else {
|
||||
// hide if necessary
|
||||
|
@ -95,7 +95,7 @@ PatternDrafter.prototype.draftPartForSet = function (partName, set) {
|
|||
}
|
||||
return result
|
||||
} catch (err) {
|
||||
this.activeStore.log.error([`Unable to draft part \`${partName}\` (set ${set})`, err])
|
||||
this.activeStore.log.error([`Unable to draft part \`${partName}\` (set \`${set}\`)`, err])
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -112,14 +112,14 @@ PatternDrafter.prototype.__createPartForSet = function (partName, set = 0) {
|
|||
throw new Error('malicious attempt at altering Object.prototype. Stopping action')
|
||||
}
|
||||
// Create parts
|
||||
this.activeStore.log.debug(`📦 Creating part \`${partName}\` (set ${set})`)
|
||||
this.activeStore.log.debug(`📦 Creating part \`${partName}\` (set \`${set}\`)`)
|
||||
this.pattern.parts[set][partName] =
|
||||
this.pattern.parts[set][partName] || this.__createPartWithContext(partName, set)
|
||||
|
||||
// Handle inject/inheritance
|
||||
const parent = this.pattern.config.inject[partName]
|
||||
if (typeof parent === 'string') {
|
||||
this.activeStore.log.debug(`Creating part \`${partName}\` from part \`${parent}\``)
|
||||
this.activeStore.log.debug(`🪆 Creating part \`${partName}\` from part \`${parent}\``)
|
||||
try {
|
||||
this.pattern.parts[set][partName].__inject(this.pattern.parts[set][parent])
|
||||
} catch (err) {
|
||||
|
@ -174,18 +174,26 @@ PatternDrafter.prototype.__createPartWithContext = function (name, set) {
|
|||
PatternDrafter.prototype.__loadAbsoluteOptionsSet = function (set) {
|
||||
for (const optionName in this.pattern.settings[set].options) {
|
||||
const option = this.pattern.config.options[optionName]
|
||||
if (
|
||||
typeof option !== 'undefined' &&
|
||||
typeof option.snap !== 'undefined' &&
|
||||
option.toAbs instanceof Function
|
||||
) {
|
||||
this.pattern.settings[set].absoluteOptions[optionName] = this.__snappedPercentageOption(
|
||||
optionName,
|
||||
set
|
||||
)
|
||||
this.pattern.setStores[set].log.debug(
|
||||
`🧲 Snapped __${optionName}__ to \`${this.pattern.settings[set].absoluteOptions[optionName]}\` for set __${set}__`
|
||||
)
|
||||
if (typeof option !== 'undefined' && option.toAbs instanceof Function) {
|
||||
if (typeof option.snap !== 'undefined') {
|
||||
this.pattern.settings[set].absoluteOptions[optionName] = this.__snappedPercentageOption(
|
||||
optionName,
|
||||
set
|
||||
)
|
||||
this.pattern.setStores[set].log.debug(
|
||||
`🧲 Snapped __${optionName}__ to \`${this.pattern.settings[set].absoluteOptions[optionName]}\` for set __${set}__`
|
||||
)
|
||||
} else {
|
||||
const abs = option.toAbs(
|
||||
this.pattern.settings[set].options[optionName],
|
||||
this.pattern.settings[set],
|
||||
mergeOptions(this.pattern.settings[set], this.pattern.config.options)
|
||||
)
|
||||
this.pattern.settings[set].absoluteOptions[optionName] = abs
|
||||
this.pattern.setStores[set].log.debug(
|
||||
`🧮 Absolute value of \`${optionName}\` option is \`${abs}\` for set __${set}__`
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -202,7 +210,11 @@ PatternDrafter.prototype.__loadAbsoluteOptionsSet = function (set) {
|
|||
*/
|
||||
PatternDrafter.prototype.__snappedPercentageOption = function (optionName, set) {
|
||||
const conf = this.pattern.config.options[optionName]
|
||||
const abs = conf.toAbs(this.pattern.settings[set].options[optionName], this.pattern.settings[set])
|
||||
const abs = conf.toAbs(
|
||||
this.pattern.settings[set].options[optionName],
|
||||
this.pattern.settings[set],
|
||||
mergeOptions(this.pattern.settings[set], this.pattern.config.options)
|
||||
)
|
||||
// Handle units-specific config - Side-step immutability for the snap conf
|
||||
let snapConf = conf.snap
|
||||
if (!Array.isArray(snapConf) && snapConf.metric && snapConf.imperial)
|
||||
|
|
|
@ -46,7 +46,7 @@ export function Store(methods = []) {
|
|||
|
||||
for (const [path, method] of methods) {
|
||||
if (avoid.indexOf(path) !== -1) {
|
||||
this.log.warning(`You cannot overwrite store.${path}()`)
|
||||
this.log.warning(`You cannot overwrite \`store.${path}()\``)
|
||||
} else set(this, path, method)
|
||||
}
|
||||
|
||||
|
@ -66,9 +66,9 @@ export function Store(methods = []) {
|
|||
Store.prototype.extend = function (methods) {
|
||||
for (const [path, method] of methods) {
|
||||
if (avoid.indexOf(path) !== -1) {
|
||||
this.log.warning(`You cannot overwrite store.${path}()`)
|
||||
this.log.warning(`You cannot overwrite \`store.${path}()\``)
|
||||
} else {
|
||||
this.log.info(`Extending store with ${path}`)
|
||||
this.log.info(`Extending store with \`${path}\``)
|
||||
set(this, path, (...args) => method(this, ...args))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -469,6 +469,29 @@ export function mergeI18n(designs, options) {
|
|||
return i18n
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to merge passed in options with default options from the pattern config
|
||||
*
|
||||
* @param {object} settings - The settings passed to the pattern
|
||||
* @param {object} optionsConfig - The pattern's options config
|
||||
* @return {object} result - An object with the merged options and their values
|
||||
*/
|
||||
export function mergeOptions(settings, optionsConfig) {
|
||||
const merged = typeof settings.options === 'undefined' ? {} : { ...settings.option }
|
||||
for (const [key, option] of Object.entries(optionsConfig)) {
|
||||
if (typeof option === 'object') {
|
||||
if (typeof option.pct !== 'undefined') merged[key] = option.pct / 100
|
||||
else if (typeof option.mm !== 'undefined') merged[key] = option.mm
|
||||
else if (typeof option.deg !== 'undefined') merged[key] = option.deg
|
||||
else if (typeof option.count !== 'undefined') merged[key] = option.count
|
||||
else if (typeof option.bool !== 'undefined') merged[key] = option.bool
|
||||
else if (typeof option.dflt !== 'undefined') merged[key] = option.dflt
|
||||
} else merged[key] = option
|
||||
}
|
||||
|
||||
return merged
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to calculate abolute option value based on a measurement
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue