feat(01-05): forest screen with level map and complete app flow

- Add forest overview screen with 6-level map showing locked/current/completed states
- Create src/forest/scene.ts with getLevelStatus, renderLevelMap, initForestScreen
- Wire complete flow: welcome -> forest -> lesson -> forest with progress updates
- Add forest CSS with level card styles and continue button

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-29 11:15:18 +02:00
co-authored by Claude Opus 4.6
parent d04e09a5a3
commit 5bac8501bf
4 changed files with 225 additions and 37 deletions
+53 -36
View File
@@ -1,6 +1,7 @@
import type { ScreenName, KeyboardLayout } from "./types";
import type { ScreenName } from "./types";
import { openDB, getProgress, saveProgress } from "./storage/db";
import { initWelcomeScreen, initLessonScreen } from "./ui/screens";
import { initForestScreen } from "./forest/scene";
let db: IDBDatabase;
let lessonCleanup: (() => void) | null = null;
@@ -19,46 +20,56 @@ export function getDB(): IDBDatabase {
return db;
}
export async function startLesson(
level: number,
layout: KeyboardLayout,
): Promise<void> {
async function handleLessonComplete(completedLevel: number): Promise<void> {
// Update progress after lesson completion
const progress = await getProgress(db);
if (!progress) return;
// Add level to completedLevels if not already there
if (!progress.completedLevels.includes(completedLevel)) {
progress.completedLevels.push(completedLevel);
}
// Advance to next level if this was the current level (LEVL-02, LEVL-03)
if (completedLevel === progress.currentLevel) {
progress.currentLevel = completedLevel + 1;
}
// Increment session count
progress.totalSessions++;
// Add today's date if not already recorded
const today = new Date().toISOString().split("T")[0]!;
if (!progress.sessionDates.includes(today)) {
progress.sessionDates.push(today);
}
await saveProgress(db, progress);
// Re-init forest screen with updated progress, then navigate
await initForestScreen(db, startLessonFromForest);
showScreen("forest");
}
function startLessonFromForest(level: number): void {
// Clean up previous lesson if any
if (lessonCleanup) {
lessonCleanup();
lessonCleanup = null;
}
showScreen("lesson");
// Get layout from progress (already loaded)
getProgress(db).then((progress) => {
const layout = progress?.selectedLayout ?? "de";
lessonCleanup = initLessonScreen(db, level, layout, async (completedLevel: number) => {
// Update progress after lesson completion
const progress = await getProgress(db);
if (!progress) return;
showScreen("lesson");
// Add level to completedLevels if not already there
if (!progress.completedLevels.includes(completedLevel)) {
progress.completedLevels.push(completedLevel);
}
// Advance to next level if this was the current level (LEVL-02, LEVL-03)
if (completedLevel === progress.currentLevel) {
progress.currentLevel = completedLevel + 1;
}
// Increment session count
progress.totalSessions++;
// Add today's date if not already recorded
const today = new Date().toISOString().split("T")[0]!;
if (!progress.sessionDates.includes(today)) {
progress.sessionDates.push(today);
}
await saveProgress(db, progress);
// Navigate to forest (per D-07: skip reward in Phase 1)
showScreen("forest");
lessonCleanup = initLessonScreen(
db,
level,
layout,
handleLessonComplete,
);
});
}
@@ -66,11 +77,17 @@ export async function initApp(): Promise<void> {
db = await openDB();
const progress = await getProgress(db);
if (progress && progress.selectedCharacter) {
// Returning user -- go to forest
// Returning user -- init forest and go there
await initForestScreen(db, startLessonFromForest);
showScreen("forest");
} else {
// First time -- show welcome
initWelcomeScreen(db, showScreen);
// First time -- show welcome, then forest after setup
initWelcomeScreen(db, async (screen: ScreenName) => {
showScreen(screen);
if (screen === "forest") {
await initForestScreen(db, startLessonFromForest);
}
});
showScreen("welcome");
}
}