Skip to content

An AI skill that turns books into animated, narrated, interactive web experiences

fix(engine): a picture book's last scene marks it done and offers the next chapter

yzr198b68616149
diff --git a/engine/engine.js b/engine/engine.js
index f8c4c09..cb6d40b 100644
--- a/engine/engine.js
+++ b/engine/engine.js
@@ -1864,7 +1864,19 @@ function beatDone() {
const b = BEATS[P.i];
if (b.ask) P.waiting = true;
else if (P.i < BEATS.length - 1) start(P.i + 1, true);
- else { P.done = true; setPlaying(false); }
+ else { P.done = true; setPlaying(false); filmDone(); }
+}
+// A chapter that ends on its last frame, with no closing card of questions (a picture book), is finished there: it
+// counts as done, and CHAPTER.next is offered over that frame. Seeking or replaying clears the button with the cards.
+function filmDone() {
+ progress(p => { p.done = [...new Set([...(p.done || []), CHAPTER.number])]; });
+ if (!CHAPTER.next) return;
+ const next = h('button', 'btn go', translate('nextChapter'));
+ next.onclick = () => { location.href = CHAPTER.next; };
+ const c = card({ x: 0, y: 770, w: 0, cls: 'side' }, 'next');
+ Object.assign(c.style, { left: 'auto', right: '40px', width: 'auto' });
+ c.append(h('div', 'acts', [next]));
+ next.focus({ preventScroll: true });
}
let last = performance.now();
function frame(now) {
diff --git a/site/elementary-algebra/lib/engine.js b/site/elementary-algebra/lib/engine.js
index f8c4c09..cb6d40b 100644
--- a/site/elementary-algebra/lib/engine.js
+++ b/site/elementary-algebra/lib/engine.js
@@ -1864,7 +1864,19 @@ function beatDone() {
const b = BEATS[P.i];
if (b.ask) P.waiting = true;
else if (P.i < BEATS.length - 1) start(P.i + 1, true);
- else { P.done = true; setPlaying(false); }
+ else { P.done = true; setPlaying(false); filmDone(); }
+}
+// A chapter that ends on its last frame, with no closing card of questions (a picture book), is finished there: it
+// counts as done, and CHAPTER.next is offered over that frame. Seeking or replaying clears the button with the cards.
+function filmDone() {
+ progress(p => { p.done = [...new Set([...(p.done || []), CHAPTER.number])]; });
+ if (!CHAPTER.next) return;
+ const next = h('button', 'btn go', translate('nextChapter'));
+ next.onclick = () => { location.href = CHAPTER.next; };
+ const c = card({ x: 0, y: 770, w: 0, cls: 'side' }, 'next');
+ Object.assign(c.style, { left: 'auto', right: '40px', width: 'auto' });
+ c.append(h('div', 'acts', [next]));
+ next.focus({ preventScroll: true });
}
let last = performance.now();
function frame(now) {
diff --git a/site/joke-collection/lib/engine.js b/site/joke-collection/lib/engine.js
index f8c4c09..cb6d40b 100644
--- a/site/joke-collection/lib/engine.js
+++ b/site/joke-collection/lib/engine.js
@@ -1864,7 +1864,19 @@ function beatDone() {
const b = BEATS[P.i];
if (b.ask) P.waiting = true;
else if (P.i < BEATS.length - 1) start(P.i + 1, true);
- else { P.done = true; setPlaying(false); }
+ else { P.done = true; setPlaying(false); filmDone(); }
+}
+// A chapter that ends on its last frame, with no closing card of questions (a picture book), is finished there: it
+// counts as done, and CHAPTER.next is offered over that frame. Seeking or replaying clears the button with the cards.
+function filmDone() {
+ progress(p => { p.done = [...new Set([...(p.done || []), CHAPTER.number])]; });
+ if (!CHAPTER.next) return;
+ const next = h('button', 'btn go', translate('nextChapter'));
+ next.onclick = () => { location.href = CHAPTER.next; };
+ const c = card({ x: 0, y: 770, w: 0, cls: 'side' }, 'next');
+ Object.assign(c.style, { left: 'auto', right: '40px', width: 'auto' });
+ c.append(h('div', 'acts', [next]));
+ next.focus({ preventScroll: true });
}
let last = performance.now();
function frame(now) {
diff --git a/site/little-red-riding-hood/lib/engine.js b/site/little-red-riding-hood/lib/engine.js
index f8c4c09..cb6d40b 100644
--- a/site/little-red-riding-hood/lib/engine.js
+++ b/site/little-red-riding-hood/lib/engine.js
@@ -1864,7 +1864,19 @@ function beatDone() {
const b = BEATS[P.i];
if (b.ask) P.waiting = true;
else if (P.i < BEATS.length - 1) start(P.i + 1, true);
- else { P.done = true; setPlaying(false); }
+ else { P.done = true; setPlaying(false); filmDone(); }
+}
+// A chapter that ends on its last frame, with no closing card of questions (a picture book), is finished there: it
+// counts as done, and CHAPTER.next is offered over that frame. Seeking or replaying clears the button with the cards.
+function filmDone() {
+ progress(p => { p.done = [...new Set([...(p.done || []), CHAPTER.number])]; });
+ if (!CHAPTER.next) return;
+ const next = h('button', 'btn go', translate('nextChapter'));
+ next.onclick = () => { location.href = CHAPTER.next; };
+ const c = card({ x: 0, y: 770, w: 0, cls: 'side' }, 'next');
+ Object.assign(c.style, { left: 'auto', right: '40px', width: 'auto' });
+ c.append(h('div', 'acts', [next]));
+ next.focus({ preventScroll: true });
}
let last = performance.now();
function frame(now) {
diff --git a/site/math-notebook/lib/engine.js b/site/math-notebook/lib/engine.js
index f8c4c09..cb6d40b 100644
--- a/site/math-notebook/lib/engine.js
+++ b/site/math-notebook/lib/engine.js
@@ -1864,7 +1864,19 @@ function beatDone() {
const b = BEATS[P.i];
if (b.ask) P.waiting = true;
else if (P.i < BEATS.length - 1) start(P.i + 1, true);
- else { P.done = true; setPlaying(false); }
+ else { P.done = true; setPlaying(false); filmDone(); }
+}
+// A chapter that ends on its last frame, with no closing card of questions (a picture book), is finished there: it
+// counts as done, and CHAPTER.next is offered over that frame. Seeking or replaying clears the button with the cards.
+function filmDone() {
+ progress(p => { p.done = [...new Set([...(p.done || []), CHAPTER.number])]; });
+ if (!CHAPTER.next) return;
+ const next = h('button', 'btn go', translate('nextChapter'));
+ next.onclick = () => { location.href = CHAPTER.next; };
+ const c = card({ x: 0, y: 770, w: 0, cls: 'side' }, 'next');
+ Object.assign(c.style, { left: 'auto', right: '40px', width: 'auto' });
+ c.append(h('div', 'acts', [next]));
+ next.focus({ preventScroll: true });
}
let last = performance.now();
function frame(now) {
diff --git a/site/physics-notebook/lib/engine.js b/site/physics-notebook/lib/engine.js
index f8c4c09..cb6d40b 100644
--- a/site/physics-notebook/lib/engine.js
+++ b/site/physics-notebook/lib/engine.js
@@ -1864,7 +1864,19 @@ function beatDone() {
const b = BEATS[P.i];
if (b.ask) P.waiting = true;
else if (P.i < BEATS.length - 1) start(P.i + 1, true);
- else { P.done = true; setPlaying(false); }
+ else { P.done = true; setPlaying(false); filmDone(); }
+}
+// A chapter that ends on its last frame, with no closing card of questions (a picture book), is finished there: it
+// counts as done, and CHAPTER.next is offered over that frame. Seeking or replaying clears the button with the cards.
+function filmDone() {
+ progress(p => { p.done = [...new Set([...(p.done || []), CHAPTER.number])]; });
+ if (!CHAPTER.next) return;
+ const next = h('button', 'btn go', translate('nextChapter'));
+ next.onclick = () => { location.href = CHAPTER.next; };
+ const c = card({ x: 0, y: 770, w: 0, cls: 'side' }, 'next');
+ Object.assign(c.style, { left: 'auto', right: '40px', width: 'auto' });
+ c.append(h('div', 'acts', [next]));
+ next.focus({ preventScroll: true });
}
let last = performance.now();
function frame(now) {
diff --git a/site/science/lib/engine.js b/site/science/lib/engine.js
index f8c4c09..cb6d40b 100644
--- a/site/science/lib/engine.js
+++ b/site/science/lib/engine.js
@@ -1864,7 +1864,19 @@ function beatDone() {
const b = BEATS[P.i];
if (b.ask) P.waiting = true;
else if (P.i < BEATS.length - 1) start(P.i + 1, true);
- else { P.done = true; setPlaying(false); }
+ else { P.done = true; setPlaying(false); filmDone(); }
+}
+// A chapter that ends on its last frame, with no closing card of questions (a picture book), is finished there: it
+// counts as done, and CHAPTER.next is offered over that frame. Seeking or replaying clears the button with the cards.
+function filmDone() {
+ progress(p => { p.done = [...new Set([...(p.done || []), CHAPTER.number])]; });
+ if (!CHAPTER.next) return;
+ const next = h('button', 'btn go', translate('nextChapter'));
+ next.onclick = () => { location.href = CHAPTER.next; };
+ const c = card({ x: 0, y: 770, w: 0, cls: 'side' }, 'next');
+ Object.assign(c.style, { left: 'auto', right: '40px', width: 'auto' });
+ c.append(h('div', 'acts', [next]));
+ next.focus({ preventScroll: true });
}
let last = performance.now();
function frame(now) {
diff --git a/site/three-little-pigs/lib/engine.js b/site/three-little-pigs/lib/engine.js
index f8c4c09..cb6d40b 100644
--- a/site/three-little-pigs/lib/engine.js
+++ b/site/three-little-pigs/lib/engine.js
@@ -1864,7 +1864,19 @@ function beatDone() {
const b = BEATS[P.i];
if (b.ask) P.waiting = true;
else if (P.i < BEATS.length - 1) start(P.i + 1, true);
- else { P.done = true; setPlaying(false); }
+ else { P.done = true; setPlaying(false); filmDone(); }
+}
+// A chapter that ends on its last frame, with no closing card of questions (a picture book), is finished there: it
+// counts as done, and CHAPTER.next is offered over that frame. Seeking or replaying clears the button with the cards.
+function filmDone() {
+ progress(p => { p.done = [...new Set([...(p.done || []), CHAPTER.number])]; });
+ if (!CHAPTER.next) return;
+ const next = h('button', 'btn go', translate('nextChapter'));
+ next.onclick = () => { location.href = CHAPTER.next; };
+ const c = card({ x: 0, y: 770, w: 0, cls: 'side' }, 'next');
+ Object.assign(c.style, { left: 'auto', right: '40px', width: 'auto' });
+ c.append(h('div', 'acts', [next]));
+ next.focus({ preventScroll: true });
}
let last = performance.now();
function frame(now) {