UNPKG

blueshell

Version:

A Behavior Tree implementation in modern Javascript

33 lines 1.22 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Retry = void 0; const RepeatWhen_1 = require("./RepeatWhen"); const models_1 = require("../../models"); class Retry extends RepeatWhen_1.RepeatWhen { constructor(name, child, numRepeats) { super(`Retry-${name}-${numRepeats}`, child, (state, event, res) => { // Get the node storage const nodeStorage = this.getNodeStorage(state); if (!nodeStorage.repeats) { nodeStorage.repeats = 0; } if (res === models_1.rc.FAILURE && (this.numRepeats < 0 || nodeStorage.repeats < this.numRepeats)) { nodeStorage.repeats++; return true; } else { if (res === models_1.rc.SUCCESS) { nodeStorage.repeats = 0; } return false; } }); this.numRepeats = numRepeats; } // override getNodeStorage to explicitly return RetryNodeStorage so consumers don't need to cast types getNodeStorage(state) { return super.getNodeStorage(state); } } exports.Retry = Retry; //# sourceMappingURL=Retry.js.map