diff --git a/animations/deck.js b/animations/deck.js index b7f6aab6..f5599435 100644 --- a/animations/deck.js +++ b/animations/deck.js @@ -318,8 +318,8 @@ return this.items.length; } - get busy() { - return this.player.busy; + get currentStepCompletion() { + return this.player.currentStepCompletion; } async show(i, forward) { @@ -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); diff --git a/animations/engine.js b/animations/engine.js index 3658f70e..9988d3d5 100644 --- a/animations/engine.js +++ b/animations/engine.js @@ -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 @@ -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() { @@ -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) { diff --git a/animations/lending/scene.js b/animations/lending/scene.js index b9da8bdf..c398287b 100644 --- a/animations/lending/scene.js +++ b/animations/lending/scene.js @@ -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 = [