Skip to content

Commit 1e2a599

Browse files
committed
Fixing selector and sequence nodes
1 parent 3f8de9a commit 1e2a599

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

src/Node/SelectorNode.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ export default class SelectorNode implements ParentBehaviorTreeNodeInterface {
2222
*/
2323
private enumerator?: NodeEnumerator;
2424

25-
public constructor(public readonly name: string, private readonly keepState: boolean) {
25+
public constructor(public readonly name: string, private readonly keepState: boolean = false) {
2626
}
2727

2828
public init(): void {
2929
this.enumerator = new NodeEnumerator(this.children);
3030
}
3131

3232
public async tick(state: StateData): Promise<BehaviorTreeStatus> {
33-
if (!this.enumerator && this.keepState) {
33+
if (!this.enumerator || !this.keepState) {
3434
this.init();
3535
}
3636

src/Node/SequenceNode.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ export default class SequenceNode implements ParentBehaviorTreeNodeInterface {
2222
*/
2323
private enumerator?: NodeEnumerator;
2424

25-
public constructor(public readonly name: string, private readonly keepState: boolean) {
25+
public constructor(public readonly name: string, private readonly keepState: boolean = false) {
2626
}
2727

2828
public init(): void {
2929
this.enumerator = new NodeEnumerator(this.children);
3030
}
3131

3232
public async tick(state: StateData): Promise<BehaviorTreeStatus> {
33-
if (!this.enumerator && this.keepState) {
33+
if (!this.enumerator || !this.keepState) {
3434
this.init();
3535
}
3636

test/Node/SelectorNodeTest.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import SelectorNode from "../../src/Node/SelectorNode";
77

88
let testObject: SelectorNode;
99

10-
function init(): void {
11-
testObject = new SelectorNode("some-selector");
10+
function init(keepState: boolean = false): void {
11+
testObject = new SelectorNode("some-selector", keepState);
1212
}
1313

1414
test("runs the first node if it succeeds", async (assert) => {
@@ -84,7 +84,7 @@ test("fails when all children fail", async (assert) => {
8484
});
8585

8686
test("only evaluates the current node", async (assert) => {
87-
init();
87+
init(true);
8888
const state = new StateData();
8989
const mockChild1 = TypeMoq.Mock.ofType<BehaviorTreeNodeInterface>();
9090
mockChild1.setup(async (m) => await m.tick(state))

test/Node/SequenceNodeTest.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import SequenceNode from "../../src/Node/SequenceNode";
77

88
let testObject: SequenceNode;
99

10-
function init(): void {
11-
testObject = new SequenceNode("some-sequence");
10+
function init(keepState: boolean = false): void {
11+
testObject = new SequenceNode("some-sequence", keepState);
1212
}
1313

1414
test("can run all children in order", async (assert) => {
@@ -91,7 +91,7 @@ test("when second child fails, then entire sequence fails", async (assert) => {
9191
});
9292

9393
test("only evaluates the current node", async (assert) => {
94-
init();
94+
init(true);
9595
const state = new StateData();
9696
const mockChild1 = TypeMoq.Mock.ofType<BehaviorTreeNodeInterface>();
9797
mockChild1.setup(async (m) => await m.tick(state))

0 commit comments

Comments
 (0)