(blackboard = null, { indexes = [], introspector, rerun, registryLookUp = (x) => x } = {})
| 12 | } |
| 13 | |
| 14 | run(blackboard = null, { indexes = [], introspector, rerun, registryLookUp = (x) => x } = {}) { |
| 15 | if (!rerun) this.blueprint.start(blackboard) |
| 16 | let overallResult = this.START_CASE |
| 17 | let currentIndex = indexes.shift() || 0 |
| 18 | while (currentIndex < this.numNodes) { |
| 19 | const node = registryLookUp(this.blueprint.nodes[currentIndex]) |
| 20 | const result = node.run(blackboard, { indexes, introspector, rerun, registryLookUp }) |
| 21 | if (result === RUNNING) { |
| 22 | this.wasRunning = true |
| 23 | overallResult = [currentIndex, ...indexes] |
| 24 | break |
| 25 | } else if (typeof result === 'object') { |
| 26 | // array |
| 27 | overallResult = [...indexes, currentIndex, ...result] |
| 28 | break |
| 29 | } else if (result === this.OPT_OUT_CASE) { |
| 30 | overallResult = result |
| 31 | break |
| 32 | } else { |
| 33 | this.wasRunning = false |
| 34 | rerun = false |
| 35 | ++currentIndex |
| 36 | } |
| 37 | } |
| 38 | const isRunning = overallResult === RUNNING || typeof overallResult === 'object' |
| 39 | if (!isRunning) { |
| 40 | this.blueprint.end(blackboard) |
| 41 | } |
| 42 | if (introspector) { |
| 43 | const debugResult = isRunning ? RUNNING : overallResult |
| 44 | introspector.wrapLast(Math.min(currentIndex + 1, this.numNodes), this, debugResult, blackboard) |
| 45 | } |
| 46 | return overallResult |
| 47 | } |
| 48 | } |
nothing calls this directly
no test coverage detected