Skip to content

Commit

Permalink
Can use Sequence as queue. Bumped to version 3.0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
drpepper committed Jul 11, 2023
1 parent 6cb0da8 commit 0e14481
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "booyah",
"version": "3.0.6",
"version": "3.0.7",
"description": "HTML5 game engine",
"scripts": {
"build": "tsc",
Expand Down
5 changes: 5 additions & 0 deletions src/chip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1005,6 +1005,11 @@ export class Sequence extends Composite {
} else {
this._chipActivationInfos.push(chip);
}

if (this._state !== "inactive" && !this._currentChip) {
// Pick up with the next chip
this._switchChip();
}
}

/** Skips to the next chip */
Expand Down
28 changes: 28 additions & 0 deletions tests/chip.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,34 @@ describe("Sequence", () => {
parent.tick(makeFrameInfo());
expect(counter).toBe(3);
});

test("can be used as a queue", () => {
const children = [new MockChip()];
const parent = new chip.Sequence(children, {
terminateOnCompletion: false,
});

parent.activate(makeFrameInfo(), makeChipContext(), makeSignal());

// Run 1st child, then terminate it
parent.tick(makeFrameInfo());
children[0].terminate();

parent.tick(makeFrameInfo());

// Add another child
children.push(new MockChip());
parent.addChildChip(children.at(-1)!);
parent.tick(makeFrameInfo());

// Both children should be ticked once
expect(children[0]._onActivate).toBeCalledTimes(1);
expect(children[0]._onTick).toBeCalledTimes(1);
expect(children[0]._onTerminate).toBeCalledTimes(1);
expect(children[1]._onActivate).toBeCalledTimes(1);
expect(children[1]._onTick).toBeCalledTimes(1);
expect(children[1]._onTerminate).toBeCalledTimes(0);
});
});

describe("StateMachine", () => {
Expand Down

0 comments on commit 0e14481

Please sign in to comment.