feat(01-04): wire lesson screen UI with keyboard and falling letters
- Lesson screen HTML with letter-area and keyboard containers - initLessonScreen: renders keyboard, shows letters, handles keypress - Correct key dissolves letter with animation, advances to next - Wrong key does nothing (per D-03), correct key stays highlighted - startLesson in app.ts: manages lesson lifecycle and cleanup - onComplete: updates progress, unlocks next level, saves to IndexedDB - CSS: floating letter animation, dissolve effect on correct press Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
+49
-5
@@ -1,8 +1,9 @@
|
||||
import type { ScreenName } from "./types";
|
||||
import { openDB, getProgress } from "./storage/db";
|
||||
import { initWelcomeScreen } from "./ui/screens";
|
||||
import type { ScreenName, KeyboardLayout } from "./types";
|
||||
import { openDB, getProgress, saveProgress } from "./storage/db";
|
||||
import { initWelcomeScreen, initLessonScreen } from "./ui/screens";
|
||||
|
||||
let db: IDBDatabase;
|
||||
let lessonCleanup: (() => void) | null = null;
|
||||
|
||||
export function showScreen(name: ScreenName): void {
|
||||
document.querySelectorAll(".screen").forEach((el) => {
|
||||
@@ -18,14 +19,57 @@ export function getDB(): IDBDatabase {
|
||||
return db;
|
||||
}
|
||||
|
||||
export async function startLesson(
|
||||
level: number,
|
||||
layout: KeyboardLayout,
|
||||
): Promise<void> {
|
||||
// Clean up previous lesson if any
|
||||
if (lessonCleanup) {
|
||||
lessonCleanup();
|
||||
lessonCleanup = null;
|
||||
}
|
||||
|
||||
showScreen("lesson");
|
||||
|
||||
lessonCleanup = initLessonScreen(db, level, layout, async (completedLevel: number) => {
|
||||
// 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);
|
||||
|
||||
// Navigate to forest (per D-07: skip reward in Phase 1)
|
||||
showScreen("forest");
|
||||
});
|
||||
}
|
||||
|
||||
export async function initApp(): Promise<void> {
|
||||
db = await openDB();
|
||||
const progress = await getProgress(db);
|
||||
if (progress && progress.selectedCharacter) {
|
||||
// Returning user — skip welcome, go to forest
|
||||
// Returning user -- go to forest
|
||||
showScreen("forest");
|
||||
} else {
|
||||
// First time — show welcome
|
||||
// First time -- show welcome
|
||||
initWelcomeScreen(db, showScreen);
|
||||
showScreen("welcome");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user