blueshell
Version:
A Behavior Tree implementation in modern Javascript
33 lines • 1.29 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.IfElseWithNodeCondition = void 0;
const IfElse_1 = require("./IfElse");
const models_1 = require("../models");
class IfElseWithNodeCondition extends IfElse_1.IfElse {
constructor(name, conditionNode, consequent, alternative) {
super(name, () => this.conditionResult, consequent, alternative);
this.conditionNode = conditionNode;
// below variable is used to communicate the result of running the conditionNode between
// onEvent() and the callback passed to IfElse in the super() call
this.conditionResult = false;
}
getChildren() {
return [this.conditionNode, ...super.getChildren()];
}
onEvent(state, event) {
const res = this.conditionNode.handleEvent(state, event);
if (res === models_1.rc.SUCCESS) {
this.conditionResult = true;
return super.onEvent(state, event);
}
else if (res === models_1.rc.FAILURE) {
this.conditionResult = false;
return super.onEvent(state, event);
}
else {
return res;
}
}
}
exports.IfElseWithNodeCondition = IfElseWithNodeCondition;
//# sourceMappingURL=IfElseWithNodeCondition.js.map