feat(05-02): fix reward flow and call sites for paginated forest

- Import SLOTS_PER_PAGE in reward.ts; replace hardcoded 12 with it
- Import SLOTS_PER_PAGE and getForestElements in app.ts
- Zurueck zum Wald callback navigates to page containing new element
- currentForestPage updated in progress before initForestScreen
This commit is contained in:
2026-03-29 23:02:51 +02:00
parent 13b8df5db0
commit 8f888439f2
2 changed files with 16 additions and 7 deletions
+14 -6
View File
@@ -3,8 +3,8 @@ import { companions } from "./companion/characters";
import { getGreeting } from "./companion/companion";
import { renderInlineMarkdown } from "./utils/markdown";
import { initRewardScreen, startPreGeneration } from "./forest/reward";
import { initForestScreen, renderForestScene } from "./forest/scene";
import { getProgress, openDB, saveProgress } from "./storage/db";
import { initForestScreen, renderForestScene, SLOTS_PER_PAGE } from "./forest/scene";
import { getForestElements, getProgress, openDB, saveProgress } from "./storage/db";
import type { ScreenName } from "./types";
import { initParentScreen, showParentCodePrompt } from "./ui/parent";
import { initLessonScreen, initWelcomeScreen } from "./ui/screens";
@@ -119,11 +119,19 @@ async function handleLessonComplete(
);
},
async () => {
// "Zurück zum Wald" -- show forest with new element animated
// "Zurück zum Wald" -- navigate to page containing the new element
const elements = await getForestElements(db);
const newPage = Math.max(0, Math.ceil(elements.length / SLOTS_PER_PAGE) - 1);
// Update progress with new page before initForestScreen reads it
const latestProgress = await getProgress(db);
if (latestProgress) {
latestProgress.currentForestPage = newPage;
await saveProgress(db, latestProgress);
}
await initForestScreen(db, startLessonFromForest);
const prog = await getProgress(db);
const page = prog?.currentForestPage ?? 0;
await renderForestScene(db, page, elementId);
await renderForestScene(db, newPage, elementId);
showScreen("forest");
},
);
+2 -1
View File
@@ -23,6 +23,7 @@ import type { CompanionType, ForestElement } from "../types";
import { playRewardSound } from "../audio/sounds";
import { speakText } from "../audio/speech";
import { renderInlineMarkdown } from "../utils/markdown";
import { SLOTS_PER_PAGE } from "./scene";
// --- Element types for random selection ---
@@ -176,7 +177,7 @@ export async function initRewardScreen(
// 4. Determine grid position for new element
const existing = await getForestElements(db);
const slotIndex = existing.length % 12;
const slotIndex = existing.length % SLOTS_PER_PAGE;
const col = slotIndex % 4;
const row = Math.floor(slotIndex / 4);
// Add small random offset for natural feel