2023-02-23 18:22:22 +02:00
|
|
|
export function PatternDraftQueue(pattern) {
|
|
|
|
this.__configResolver = pattern.__configResolver
|
|
|
|
this.queue = this.__resolveDraftOrder()
|
|
|
|
this.start()
|
|
|
|
}
|
|
|
|
|
|
|
|
PatternDraftQueue.prototype.start = function () {
|
|
|
|
this.queueIndex = 0
|
|
|
|
}
|
|
|
|
|
|
|
|
PatternDraftQueue.prototype.addPart = function (partName) {
|
2023-02-23 19:15:20 +02:00
|
|
|
if (!this.contains(partName)) this.queue.push(partName)
|
2023-02-23 18:22:22 +02:00
|
|
|
return this
|
|
|
|
}
|
|
|
|
|
|
|
|
PatternDraftQueue.prototype.hasNext = function () {
|
|
|
|
return this.queueIndex < this.queue.length
|
|
|
|
}
|
|
|
|
|
|
|
|
PatternDraftQueue.prototype.peek = function () {
|
|
|
|
return this.queue[this.queueIndex]
|
|
|
|
}
|
|
|
|
|
|
|
|
PatternDraftQueue.prototype.next = function () {
|
|
|
|
const next = this.peek()
|
|
|
|
this.queueIndex++
|
|
|
|
return next
|
|
|
|
}
|
|
|
|
|
2023-02-23 19:15:20 +02:00
|
|
|
PatternDraftQueue.prototype.contains = function (partName) {
|
|
|
|
return this.queue.indexOf(partName) !== -1
|
|
|
|
}
|
|
|
|
|
2023-02-23 18:22:22 +02:00
|
|
|
/**
|
|
|
|
* Resolves the draft order based on the configuation
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {object} graph - The object of resolved dependencies, used to call itself recursively
|
|
|
|
* @return {Pattern} this - The Pattern instance
|
|
|
|
*/
|
|
|
|
PatternDraftQueue.prototype.__resolveDraftOrder = function () {
|
|
|
|
const partDistances = this.__configResolver.__mutated.partDistance
|
|
|
|
return Object.keys(this.__configResolver.parts).sort(
|
|
|
|
(p1, p2) => partDistances[p2] - partDistances[p1]
|
|
|
|
)
|
|
|
|
}
|