Skip to content

Commit

Permalink
Merge pull request #25 from nikkorn/bind-blackboard-calls
Browse files Browse the repository at this point in the history
Bind blackboard calls
  • Loading branch information
nikkorn authored Nov 25, 2019
2 parents 3f4734b + 23fc087 commit 89ad3db
Show file tree
Hide file tree
Showing 12 changed files with 30 additions and 48 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# ![logo](https://github.com/nikkorn/mistreevous/raw/master/icons/icon-small.png) Mistreevous
# ![logo](https://github.com/nikkorn/mistreevous/raw/master/icons/icon-small.png) Mistreevous
[![npm version](https://badge.fury.io/js/mistreevous.svg)](https://badge.fury.io/js/mistreevous)

A tool to declaratively define and generate behaviour trees in JavaScript. Behaviour trees are used to create complex AI via the modular heirarchical composition of individual tasks.

Expand Down
14 changes: 7 additions & 7 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1464,7 +1464,7 @@ function Action(decorators, actionName) {
// - The finished state of this action node.
// - A promise to return a finished node state.
// - Undefined if the node should remain in the running state.
const updateResult = action();
const updateResult = action.call(board);

if (updateResult instanceof Promise) {
updateResult.then(result => {
Expand Down Expand Up @@ -1583,7 +1583,7 @@ function Condition(decorators, condition) {
this.onUpdate = function (board) {
// Call the condition function to determine the state of this node, but it must exist in the blackboard.
if (typeof board[condition] === "function") {
this.setState(!!board[condition]() ? __WEBPACK_IMPORTED_MODULE_1__state__["a" /* default */].SUCCEEDED : __WEBPACK_IMPORTED_MODULE_1__state__["a" /* default */].FAILED);
this.setState(!!board[condition].call(board) ? __WEBPACK_IMPORTED_MODULE_1__state__["a" /* default */].SUCCEEDED : __WEBPACK_IMPORTED_MODULE_1__state__["a" /* default */].FAILED);
} else {
throw `cannot update condition node as function '${condition}' is not defined in the blackboard`;
}
Expand Down Expand Up @@ -2228,7 +2228,7 @@ function While(condition) {
this.isSatisfied = board => {
// Call the condition function to determine whether this guard is satisfied.
if (typeof board[condition] === "function") {
return !!board[condition]();
return !!board[condition].call(board);
} else {
throw `cannot evaluate node guard as function '${condition}' is not defined in the blackboard`;
}
Expand Down Expand Up @@ -2282,7 +2282,7 @@ function Until(condition) {
this.isSatisfied = board => {
// Call the condition function to determine whether this guard is satisfied.
if (typeof board[condition] === "function") {
return !!!board[condition]();
return !!!board[condition].call(board);
} else {
throw `cannot evaluate node guard as function '${condition}' is not defined in the blackboard`;
}
Expand Down Expand Up @@ -2330,7 +2330,7 @@ function Entry(functionName) {
this.callBlackboardFunction = board => {
// Call the blackboard function if it exists.
if (typeof board[functionName] === "function") {
board[functionName]();
board[functionName].call(board);
} else {
throw `cannot call entry decorator function '${functionName}' is not defined in the blackboard`;
}
Expand Down Expand Up @@ -2380,7 +2380,7 @@ function Exit(functionName) {
this.callBlackboardFunction = (board, isSuccess, isAborted) => {
// Call the blackboard function if it exists.
if (typeof board[functionName] === "function") {
board[functionName]({ succeeded: isSuccess, aborted: isAborted });
board[functionName].call(board, { succeeded: isSuccess, aborted: isAborted });
} else {
throw `cannot call exit decorator function '${functionName}' is not defined in the blackboard`;
}
Expand Down Expand Up @@ -2428,7 +2428,7 @@ function Step(functionName) {
this.callBlackboardFunction = board => {
// Call the blackboard function if it exists.
if (typeof board[functionName] === "function") {
board[functionName]();
board[functionName].call(board);
} else {
throw `cannot call entry decorator function '${functionName}' is not defined in the blackboard`;
}
Expand Down
2 changes: 1 addition & 1 deletion dist/mistreevous.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Type definitions for Mistreevous 0.0.6
// Type definitions for Mistreevous 1.0.0
// Project: Mistreevous
// Definitions by: nikolas howard <https://github.com/nikkorn>
declare module "Mistreevous" {
Expand Down
43 changes: 12 additions & 31 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mistreevous",
"version": "0.0.6",
"version": "1.0.0",
"description": "A tool to build behaviour trees in JavaScript",
"main": "dist/index.js",
"types": "dist/mistreevous.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion src/decorators/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default function Entry(functionName) {
this.callBlackboardFunction = (board) => {
// Call the blackboard function if it exists.
if (typeof board[functionName] === "function") {
board[functionName]();
board[functionName].call(board);
} else {
throw `cannot call entry decorator function '${functionName}' is not defined in the blackboard`;
}
Expand Down
2 changes: 1 addition & 1 deletion src/decorators/exit.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default function Exit(functionName) {
this.callBlackboardFunction = (board, isSuccess, isAborted) => {
// Call the blackboard function if it exists.
if (typeof board[functionName] === "function") {
board[functionName]({ succeeded: isSuccess, aborted: isAborted });
board[functionName].call(board, { succeeded: isSuccess, aborted: isAborted });
} else {
throw `cannot call exit decorator function '${functionName}' is not defined in the blackboard`;
}
Expand Down
2 changes: 1 addition & 1 deletion src/decorators/guards/until.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default function Until(condition) {
this.isSatisfied = (board) => {
// Call the condition function to determine whether this guard is satisfied.
if (typeof board[condition] === "function") {
return !!!(board[condition]());
return !!!(board[condition].call(board));
} else {
throw `cannot evaluate node guard as function '${condition}' is not defined in the blackboard`;
}
Expand Down
2 changes: 1 addition & 1 deletion src/decorators/guards/while.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default function While(condition) {
this.isSatisfied = (board) => {
// Call the condition function to determine whether this guard is satisfied.
if (typeof board[condition] === "function") {
return !!(board[condition]());
return !!(board[condition].call(board));
} else {
throw `cannot evaluate node guard as function '${condition}' is not defined in the blackboard`;
}
Expand Down
2 changes: 1 addition & 1 deletion src/decorators/step.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default function Step(functionName) {
this.callBlackboardFunction = (board) => {
// Call the blackboard function if it exists.
if (typeof board[functionName] === "function") {
board[functionName]();
board[functionName].call(board);
} else {
throw `cannot call entry decorator function '${functionName}' is not defined in the blackboard`;
}
Expand Down
2 changes: 1 addition & 1 deletion src/nodes/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default function Action(decorators, actionName) {
// - The finished state of this action node.
// - A promise to return a finished node state.
// - Undefined if the node should remain in the running state.
const updateResult = action();
const updateResult = action.call(board);

if (updateResult instanceof Promise) {
updateResult.then(
Expand Down
2 changes: 1 addition & 1 deletion src/nodes/condition.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default function Condition(decorators, condition) {
this.onUpdate = function(board) {
// Call the condition function to determine the state of this node, but it must exist in the blackboard.
if (typeof board[condition] === "function") {
this.setState(!!(board[condition]()) ? State.SUCCEEDED : State.FAILED);
this.setState(!!(board[condition].call(board)) ? State.SUCCEEDED : State.FAILED);
} else {
throw `cannot update condition node as function '${condition}' is not defined in the blackboard`;
}
Expand Down

0 comments on commit 89ad3db

Please sign in to comment.