1
0
Fork 0

wip: Handle backwards compatibility for passing parts as array

This was broken by some earlier changes, but not it's ok again
This commit is contained in:
joostdecock 2022-08-15 10:48:35 +02:00
parent 7f684d8c17
commit 681a1fc657
2 changed files with 10 additions and 4 deletions

View file

@ -13,8 +13,12 @@ export default function Design(config, plugins = false, conditionalPlugins = fal
if (Array.isArray(config.parts)) {
const parts = {}
for (const part of config.parts) {
parts[part.name] = part
config = addPartConfig(parts[part.name], config)
if (typeof part === 'object') {
parts[part.name] = part
config = addPartConfig(parts[part.name], config)
} else if (typeof part === 'string') {
parts[part] = part
} else throw("Part should be passed as a name of part config object")
}
config.parts = parts
}

View file

@ -360,6 +360,8 @@ Pattern.prototype.draft = function () {
* Handles pattern sampling
*/
Pattern.prototype.sample = function () {
// Late-stage initialization
this.init()
if (this.settings.sample.type === 'option') {
return this.sampleOption(this.settings.sample.option)
} else if (this.settings.sample.type === 'measurement') {
@ -756,8 +758,8 @@ Pattern.prototype.resolveDependencies = function (graph = this.dependencies) {
}
// Include parts outside the dependency graph
if (Array.isArray(this.config.parts)) {
for (let part of this.config.parts) {
if (typeof this.config.parts === 'object') {
for (const part of Object.values(this.config.parts)) {
if (typeof part === 'string' && typeof this.dependencies[part] === 'undefined') this.dependencies[part] = []
}
}