Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions animations/deck.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,8 @@
return this.items.length;
}

get busy() {
return this.player.busy;
get currentStepCompletion() {
return this.player.currentStepCompletion;
}

async show(i, forward) {
Expand Down Expand Up @@ -388,7 +388,7 @@
}

async next() {
if (this.player.busy) return this.player.interrupt();
if (this.player.currentStepCompletion) return this.player.interrupt();
if (this.index >= this.count - 1) return;
this.index += 1;
await this.show(this.index, true);
Expand Down
24 changes: 15 additions & 9 deletions animations/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,11 @@
this.svg = svg;
this.onStep = onStep || (() => {});
this.skip = false;
this.busy = null;
// The promise that the current step's animation completes; null when no
// step is animating.
this.currentStepCompletion = null;
// How many step animations have started; next() uses it to tell them apart.
this.animationCount = 0;
this.speed = 1;
this.autoplay = null;
// states[i] is the picture once step i has finished. A step starts
Expand Down Expand Up @@ -438,14 +442,16 @@
}

async next() {
if (this.busy) return this.interrupt();
if (this.currentStepCompletion) return this.interrupt();
if (this.index >= this.count - 1) return;
this.index += 1;
this.onStep(this.index);
const run = this.play(this.index);
this.busy = run;
await run;
if (this.busy === run) this.busy = null;
// Number each animation, so one that finishes after a newer step has
// started leaves the newer step's currentStepCompletion alone.
const animationNumber = ++this.animationCount;
this.currentStepCompletion = this.play(this.index);
await this.currentStepCompletion;
if (this.animationCount === animationNumber) this.currentStepCompletion = null;
}

prev() {
Expand Down Expand Up @@ -474,11 +480,11 @@

// Finishes the running animation at once, on its end state.
async interrupt() {
if (!this.busy) return;
if (!this.currentStepCompletion) return;
this.skip = true;
await this.busy;
await this.currentStepCompletion;
this.skip = false;
this.busy = null;
this.currentStepCompletion = null;
}

tween(ms, fn) {
Expand Down
1 change: 0 additions & 1 deletion animations/lending/scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@
const sol = (text) => ({ text, style: "sol" });
const balance = (text) => ({ text, style: "balance" });
const field = (text) => ({ text });
const note = (text) => ({ text, style: "note" });

// In the order the chapter's figures list them.
const HANDLERS = [
Expand Down
Loading