Skip to content

Commit

Permalink
Merge pull request #164 from 6RiverSystems/fix/while-running-check
Browse files Browse the repository at this point in the history
fix: while running check
  • Loading branch information
tdeignan1 committed Sep 27, 2023
2 parents bac5dfc + 163aaa1 commit 8b32952
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
6 changes: 5 additions & 1 deletion lib/nodes/decorators/While.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class While<S extends BlueshellState, E> extends Decorator<S, E> {
protected decorateCall(handleEvent: (state: S, event: E) => ResultCode, state: S, event: E) {
const storage: WhileNodeStorage = this.getNodeStorage(state);

if (storage.running || this.conditional(state, event)) {
if (storage.running !== undefined || this.conditional(state, event)) {
if (storage.beganAtLeastOneLoop) {
Action.treePublisher.publishResult(state, event, false);
clearEventSeenRecursive(this.child, state);
Expand Down Expand Up @@ -70,6 +70,10 @@ export class While<S extends BlueshellState, E> extends Decorator<S, E> {
}
}

protected onEvent(state: S, event: E): ResultCode {
return this.handleChild(state, event);
}

get symbol(): string {
return '↻';
}
Expand Down
10 changes: 5 additions & 5 deletions test/nodes/decorators/While.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ describe('While', function () {

it('latches', function () {
const testAction = new TestAction('testAction', [
{ rc: rc.RUNNING, inc: false },
{ rc: rc.SUCCESS, inc: true },
{ rc: rc.RUNNING, inc: true },
{ rc: rc.SUCCESS, inc: false },
]);

const uut = new decorators.While<TestState, number>(
Expand All @@ -129,17 +129,17 @@ describe('While', function () {

let result = uut.handleEvent(state, 0);
assert.strictEqual(rc.RUNNING, result);
assert.strictEqual(state.counter, 0);
assert.strictEqual(state.counter, 1);
assert.strictEqual(testAction.eventCount, 1);

result = uut.handleEvent(state, 0);
assert.strictEqual(rc.RUNNING, result);
assert.strictEqual(state.counter, 1);
assert.strictEqual(state.counter, 2);
assert.strictEqual(testAction.eventCount, 3);

result = uut.handleEvent(state, 0);
assert.strictEqual(rc.RUNNING, result);
assert.strictEqual(state.counter, 2);
assert.strictEqual(state.counter, 3);
assert.strictEqual(testAction.eventCount, 5);

result = uut.handleEvent(state, 0);
Expand Down

0 comments on commit 8b32952

Please sign in to comment.