UNPKG

blueshell

Version:

A Behavior Tree implementation in modern Javascript

44 lines 1.32 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ResultSwap = void 0; const Decorator_1 = require("../Decorator"); /** * Swaps one result from a child node for another. * This can be used to mask `FAILURE` * * For example, you can use this to have a Sequene continue operation if a child returns `FAILURE`. * * 1/21/16 * @author Joshua Chaitin-Pollak */ class ResultSwap extends Decorator_1.Decorator { /** * @constructor * @param _inResult The result to swap out (mask). * @param _outResult The result to return when the child returns `_inResult'. * @param child The child Node of the decorator. * @param desc Optional description of the Node. */ constructor(_inResult, _outResult, child, desc = `ResultSwap_${_inResult}-${_outResult}-${child.name}`) { super(desc, child); this._inResult = _inResult; this._outResult = _outResult; } /** * Performs the swap from the child Node. * @override * @param state * @param event */ decorateResult(res) { if (res === this._inResult) { res = this._outResult; } return res; } get symbol() { return '↬'; } } exports.ResultSwap = ResultSwap; //# sourceMappingURL=ResultSwap.js.map