1
0
Fork 0

fix(core): Issue with hiding dependencies

This commit is contained in:
joostdecock 2022-09-11 18:00:41 +02:00
parent 32890819bf
commit 48b366c57e
10 changed files with 165 additions and 167 deletions

View file

@ -21,6 +21,7 @@ export function Part() {
// Enumerable properties
this.render = true // FIXME: Replace render with hide
this.hide = false // FIXME: Replace render with hide
this.attributes = new Attributes()
this.points = {}
this.paths = {}
@ -323,7 +324,9 @@ Part.prototype.shorthand = function () {
const optionsProxy = {
get: function (options, name) {
if (typeof options[name] === 'undefined')
self.context.store.log.warning(`Tried to access \`options.${name}\` but it is \`undefined\``)
self.context.store.log.warning(
`Tried to access \`options.${name}\` but it is \`undefined\``
)
return Reflect.get(...arguments)
},
set: (options, name, value) => (self.context.settings.options[name] = value),

View file

@ -13,9 +13,7 @@ import {
} from './utils.mjs'
export function Path(debug = false) {
// Non-enumerable properties
addNonEnumProp(this, 'render', true) // FIXME: replace with hide
//addNonEnumProp(this, 'topLeft', false)
//addNonEnumProp(this, 'bottomRight', false)
//addNonEnumProp(this, 'attributes', new Attributes())
@ -28,6 +26,7 @@ export function Path(debug = false) {
this.attributes = new Attributes()
this.topLeft = false
this.bottomRight = false
this.render = true
}
/** Adds the log method for a path not created through the proxy **/
@ -632,9 +631,7 @@ Path.prototype.divide = function () {
if (!op.to.sitsRoughlyOn(current))
paths.push(new Path(this.debug).withLog(this.log).move(current).line(op.to))
} else if (op.type === 'curve') {
paths.push(
new Path(this.debug).withLog(this.log).move(current).curve(op.cp1, op.cp2, op.to)
)
paths.push(new Path(this.debug).withLog(this.log).move(current).curve(op.cp1, op.cp2, op.to))
} else if (op.type === 'close') {
paths.push(new Path(this.debug).withLog(this.log).move(current).line(start))
}
@ -646,15 +643,13 @@ Path.prototype.divide = function () {
/** Finds intersections between this path and an X value */
Path.prototype.intersectsX = function (x) {
if (typeof x !== 'number')
this.log.error('Called `Path.intersectsX(x)` but `x` is not a number')
if (typeof x !== 'number') this.log.error('Called `Path.intersectsX(x)` but `x` is not a number')
return this.intersectsAxis(x, 'x')
}
/** Finds intersections between this path and an Y value */
Path.prototype.intersectsY = function (y) {
if (typeof y !== 'number')
this.log.error('Called `Path.intersectsX(y)` but `y` is not a number')
if (typeof y !== 'number') this.log.error('Called `Path.intersectsX(y)` but `y` is not a number')
return this.intersectsAxis(y, 'y')
}
@ -781,9 +776,7 @@ Path.prototype.split = function (point) {
firstHalf.push(new Path(this.debug).withLog(this.log).move(path.ops[0].to).line(point))
pi++
secondHalf = divided.slice(pi)
secondHalf.unshift(
new Path(this.debug).withLog(this.log).move(point).line(path.ops[1].to)
)
secondHalf.unshift(new Path(this.debug).withLog(this.log).move(point).line(path.ops[1].to))
}
} else if (path.ops[1].type === 'curve') {
if (path.ops[0].to.sitsRoughlyOn(point)) {

View file

@ -239,7 +239,9 @@ Pattern.prototype.draft = function () {
try {
const result = this.__parts[partName].draft(this.parts[partName].shorthand())
if (typeof result === 'undefined') {
this.store.log.error(`Result of drafting part ${partName} was undefined. Did you forget to return the part?`)
this.store.log.error(
`Result of drafting part ${partName} was undefined. Did you forget to return the part?`
)
} else this.parts[partName] = result
} catch (err) {
this.store.log.error([`Unable to draft part \`${partName}\``, err])
@ -657,26 +659,27 @@ Pattern.prototype.__resolveParts = function (count = 0) {
}
}
for (const [name, part] of Object.entries(this.__parts)) {
// Hide when hideAll is set
if (part.hideAll) part.hide = true
// Inject (from)
if (part.from) {
if (part.hideDependencies || part.hideAll) {
part.from.hide = true
part.from.hideAll = true
}
this.__parts[part.from.name] = part.from
this.__inject[name] = part.from.name
if (typeof this.__parts[part.from.name] === 'undefined') {
if (part.hideDependencies || part.hideAll) {
this.__parts[part.from.name].hide = true
this.__parts[part.from.name].hideAll = true
}
//this.config = addPartConfig(this.__parts[part.from.name], this.config, this.store)
}
}
// Simple dependency (after)
if (part.after) {
if (Array.isArray(part.after)) {
for (const dep of part.after) {
if (part.hideDependencies) dep.hide = true
this.__parts[dep.name] = dep
this.__addDependency(name, part, dep)
}
} else {
if (part.hideDependencies) part.after.hide = true
this.__parts[part.after.name] = part.after
this.__addDependency(name, part, part.after)
}
@ -729,18 +732,16 @@ Pattern.prototype.__resolveDependencies = function (graph = false) {
* configured dependencies.
*/
Pattern.prototype.needs = function (partName) {
// If only is unset, all parts are needed
if (
typeof this.settings.only === 'undefined' ||
this.settings.only === false ||
( Array.isArray(this.settings.only) && this.settings.only.length === 0 )
) return true
(Array.isArray(this.settings.only) && this.settings.only.length === 0)
)
return true
// Make only to always be an array
const only = typeof this.settings.only === 'string'
? [ this.settings.only ]
: this.settings.only
const only = typeof this.settings.only === 'string' ? [this.settings.only] : this.settings.only
// Walk the only parts, checking each one for a match in its dependencies
for (const part of only) {
@ -777,7 +778,6 @@ Pattern.prototype.isHidden = function (partName) {
if (Array.isArray(this.settings.only)) {
if (this.settings.only.includes(partName)) return false
}
if (this.__parts?.[partName]?.hide) return true
if (this.__parts?.[partName]?.hideAll) return true

View file

@ -548,7 +548,6 @@ export const addPartConfig = (part, config, store) => {
config = addPartOptions(part, config, store)
config = addPartMeasurements(part, config, store)
config = addPartOptionalMeasurements(part, config, store)
//config = addPartDependencies(part, config, store)
config = addPartPlugins(part, config, store)
return config