UNPKG

behaviortree

Version:

A JavaScript implementation of Behavior Trees. They are useful for implementing AIs. For Browsers and NodeJS.

27 lines (26 loc) 984 B
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const constants_1 = require("./constants"); const Parallel_1 = __importDefault(require("./Parallel")); const helper_1 = require("./helper"); /** * The Parallel node runs all of its children in parallel and is running as long as one of the children is * still running. */ class ParallelSelector extends Parallel_1.default { constructor() { super(...arguments); this.nodeType = 'ParallelSelector'; } calcResult(results) { if (results.includes(constants_1.FAILURE)) { return constants_1.FAILURE; } const running = !!results.find((x) => (0, helper_1.isRunning)(x)); return running ? { total: constants_1.RUNNING, state: results } : constants_1.SUCCESS; } } exports.default = ParallelSelector;