blueshell
Version:
A Behavior Tree implementation in modern Javascript
40 lines • 1.34 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.RepeatWhen = void 0;
const Base_1 = require("../Base");
const Decorator_1 = require("../Decorator");
const Parent_1 = require("../Parent");
/**
* Given a conditional, have the child Node repeat handling of the event.
* 1/12/16
* @author Joshua Chaitin-Pollak
*/
class RepeatWhen extends Decorator_1.Decorator {
constructor(desc, child, conditional) {
super('RepeatWhen-' + desc, child);
this.conditional = conditional;
}
/**
* Executes the conditional with the given state, event, and child result.
* Child is repeated depending on result of conditional.
* @override
* @param state The state when the event occured.
* @param event The event to handle.
*/
decorateResult(res, state, event) {
if (this.conditional(state, event, res)) {
// publish the tree before we reset so we can see the result
Base_1.Action.treePublisher.publishResult(state, event, false);
(0, Parent_1.clearEventSeenRecursive)(this, state);
return this.handleEvent(state, event);
}
else {
return res;
}
}
get symbol() {
return '↻';
}
}
exports.RepeatWhen = RepeatWhen;
//# sourceMappingURL=RepeatWhen.js.map