more documentation
This commit is contained in:
parent
b419e6ce16
commit
f5725cbfca
2 changed files with 40 additions and 3 deletions
|
@ -1,42 +1,73 @@
|
||||||
|
/**
|
||||||
|
* A queue for handling the draft order of pattern parts
|
||||||
|
* Unlike most queues, traversing this queue is non-destructive
|
||||||
|
* so that the queue can be traversed many times.
|
||||||
|
* The goal is to allow the queue to be manipulated while being traversed
|
||||||
|
* @class
|
||||||
|
* @param {Pattern} pattern the pattern that will use the queue
|
||||||
|
*/
|
||||||
export function PatternDraftQueue(pattern) {
|
export function PatternDraftQueue(pattern) {
|
||||||
|
// save the config resolver
|
||||||
this.__configResolver = pattern.__configResolver
|
this.__configResolver = pattern.__configResolver
|
||||||
|
// get the draft order in its current state
|
||||||
this.queue = this.__resolveDraftOrder()
|
this.queue = this.__resolveDraftOrder()
|
||||||
|
// start at 0
|
||||||
this.start()
|
this.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Go back to the beginning of the queue */
|
||||||
PatternDraftQueue.prototype.start = function () {
|
PatternDraftQueue.prototype.start = function () {
|
||||||
this.queueIndex = 0
|
this.queueIndex = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a part to end of the queue. Useful for queueing up parts a draft time
|
||||||
|
* @param {string} partName the name to the part to add
|
||||||
|
*/
|
||||||
PatternDraftQueue.prototype.addPart = function (partName) {
|
PatternDraftQueue.prototype.addPart = function (partName) {
|
||||||
if (!this.contains(partName)) this.queue.push(partName)
|
if (!this.contains(partName)) this.queue.push(partName)
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether the queue has a next part without moving the queue index
|
||||||
|
* @return {Boolean} whether there is a next part in the queue
|
||||||
|
*/
|
||||||
PatternDraftQueue.prototype.hasNext = function () {
|
PatternDraftQueue.prototype.hasNext = function () {
|
||||||
return this.queueIndex < this.queue.length
|
return this.queueIndex < this.queue.length
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the next part in the queue without moving the queue index
|
||||||
|
* @return {string} the next part in the queue
|
||||||
|
*/
|
||||||
PatternDraftQueue.prototype.peek = function () {
|
PatternDraftQueue.prototype.peek = function () {
|
||||||
return this.queue[this.queueIndex]
|
return this.queue[this.queueIndex]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the next part in the queue and move the queue index
|
||||||
|
* @return {string} the next part in the queue
|
||||||
|
*/
|
||||||
PatternDraftQueue.prototype.next = function () {
|
PatternDraftQueue.prototype.next = function () {
|
||||||
const next = this.peek()
|
const next = this.peek()
|
||||||
this.queueIndex++
|
this.queueIndex++
|
||||||
return next
|
return next
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether a part is already queued
|
||||||
|
* @param {string} partName the name of the part
|
||||||
|
* @return {boolean} whether the part is in the queue
|
||||||
|
*/
|
||||||
PatternDraftQueue.prototype.contains = function (partName) {
|
PatternDraftQueue.prototype.contains = function (partName) {
|
||||||
return this.queue.indexOf(partName) !== -1
|
return this.queue.indexOf(partName) !== -1
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolves the draft order based on the configuation
|
* Resolves the draft order based on the configuation
|
||||||
*
|
|
||||||
* @private
|
* @private
|
||||||
* @param {object} graph - The object of resolved dependencies, used to call itself recursively
|
* @return A list of parts in the order they should be drafted
|
||||||
* @return {Pattern} this - The Pattern instance
|
|
||||||
*/
|
*/
|
||||||
PatternDraftQueue.prototype.__resolveDraftOrder = function () {
|
PatternDraftQueue.prototype.__resolveDraftOrder = function () {
|
||||||
const partDistances = this.__configResolver.__mutated.partDistance
|
const partDistances = this.__configResolver.__mutated.partDistance
|
||||||
|
|
|
@ -920,6 +920,7 @@ Pattern.prototype.__pack = function () {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.settings[0].layout === true) {
|
if (this.settings[0].layout === true) {
|
||||||
|
// some plugins will add a width constraint to the settings, but we can safely pass undefined if not
|
||||||
let size = pack(bins, { inPlace: true, maxWidth: this.settings[0].maxWidth })
|
let size = pack(bins, { inPlace: true, maxWidth: this.settings[0].maxWidth })
|
||||||
for (let bin of bins) {
|
for (let bin of bins) {
|
||||||
this.autoLayout.stacks[bin.id] = { move: {} }
|
this.autoLayout.stacks[bin.id] = { move: {} }
|
||||||
|
@ -950,6 +951,11 @@ Pattern.prototype.__pack = function () {
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the configuration for the config resolver and sets it on the pattern
|
||||||
|
* @private
|
||||||
|
* @return {Pattern} this - The Pattern instance
|
||||||
|
*/
|
||||||
Pattern.prototype.__resolveConfig = function () {
|
Pattern.prototype.__resolveConfig = function () {
|
||||||
this.config = this.__configResolver.asConfig()
|
this.config = this.__configResolver.asConfig()
|
||||||
return this
|
return this
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue