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:
+14
-6
@@ -3,8 +3,8 @@ import { companions } from "./companion/characters";
|
|||||||
import { getGreeting } from "./companion/companion";
|
import { getGreeting } from "./companion/companion";
|
||||||
import { renderInlineMarkdown } from "./utils/markdown";
|
import { renderInlineMarkdown } from "./utils/markdown";
|
||||||
import { initRewardScreen, startPreGeneration } from "./forest/reward";
|
import { initRewardScreen, startPreGeneration } from "./forest/reward";
|
||||||
import { initForestScreen, renderForestScene } from "./forest/scene";
|
import { initForestScreen, renderForestScene, SLOTS_PER_PAGE } from "./forest/scene";
|
||||||
import { getProgress, openDB, saveProgress } from "./storage/db";
|
import { getForestElements, getProgress, openDB, saveProgress } from "./storage/db";
|
||||||
import type { ScreenName } from "./types";
|
import type { ScreenName } from "./types";
|
||||||
import { initParentScreen, showParentCodePrompt } from "./ui/parent";
|
import { initParentScreen, showParentCodePrompt } from "./ui/parent";
|
||||||
import { initLessonScreen, initWelcomeScreen } from "./ui/screens";
|
import { initLessonScreen, initWelcomeScreen } from "./ui/screens";
|
||||||
@@ -119,11 +119,19 @@ async function handleLessonComplete(
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
async () => {
|
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);
|
await initForestScreen(db, startLessonFromForest);
|
||||||
const prog = await getProgress(db);
|
await renderForestScene(db, newPage, elementId);
|
||||||
const page = prog?.currentForestPage ?? 0;
|
|
||||||
await renderForestScene(db, page, elementId);
|
|
||||||
showScreen("forest");
|
showScreen("forest");
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import type { CompanionType, ForestElement } from "../types";
|
|||||||
import { playRewardSound } from "../audio/sounds";
|
import { playRewardSound } from "../audio/sounds";
|
||||||
import { speakText } from "../audio/speech";
|
import { speakText } from "../audio/speech";
|
||||||
import { renderInlineMarkdown } from "../utils/markdown";
|
import { renderInlineMarkdown } from "../utils/markdown";
|
||||||
|
import { SLOTS_PER_PAGE } from "./scene";
|
||||||
|
|
||||||
// --- Element types for random selection ---
|
// --- Element types for random selection ---
|
||||||
|
|
||||||
@@ -176,7 +177,7 @@ export async function initRewardScreen(
|
|||||||
|
|
||||||
// 4. Determine grid position for new element
|
// 4. Determine grid position for new element
|
||||||
const existing = await getForestElements(db);
|
const existing = await getForestElements(db);
|
||||||
const slotIndex = existing.length % 12;
|
const slotIndex = existing.length % SLOTS_PER_PAGE;
|
||||||
const col = slotIndex % 4;
|
const col = slotIndex % 4;
|
||||||
const row = Math.floor(slotIndex / 4);
|
const row = Math.floor(slotIndex / 4);
|
||||||
// Add small random offset for natural feel
|
// Add small random offset for natural feel
|
||||||
|
|||||||
Reference in New Issue
Block a user