UNPKG

behaviortree

Version:

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

30 lines (29 loc) 880 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 Decorator_1 = __importDefault(require("../Decorator")); class LoopDecorator extends Decorator_1.default { constructor() { super(...arguments); this.nodeType = 'LoopDecorator'; } setConfig({ loop = Infinity }) { this.config = { loop }; } decorate(run) { let i = 0; let result = constants_1.FAILURE; while (i++ < this.config.loop) { result = run(); if (result === constants_1.FAILURE) return constants_1.FAILURE; } return result; } } exports.default = LoopDecorator;