feat(02-05): add companion greeting to forest and avatar to lesson screen
- Add forest-greeting companion area in HTML with avatar + text - Add lesson-companion area in HTML above letter area - Wire getGreeting() call for returning users in app.ts - Show companion avatar in lesson screen via getProgress lookup - Fix pre-existing noUncheckedIndexedAccess errors in fallbacks.ts (Rule 3) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
+23
@@ -2,6 +2,8 @@ import type { ScreenName } from "./types";
|
||||
import { openDB, getProgress, saveProgress } from "./storage/db";
|
||||
import { initWelcomeScreen, initLessonScreen } from "./ui/screens";
|
||||
import { initForestScreen } from "./forest/scene";
|
||||
import { getGreeting } from "./companion/companion";
|
||||
import { companions } from "./companion/characters";
|
||||
|
||||
let db: IDBDatabase;
|
||||
let lessonCleanup: (() => void) | null = null;
|
||||
@@ -89,6 +91,27 @@ export async function initApp(): Promise<void> {
|
||||
// Returning user -- init forest and go there
|
||||
await initForestScreen(db, startLessonFromForest);
|
||||
showScreen("forest");
|
||||
|
||||
// Show companion greeting (per COMP-01, D-14)
|
||||
const companion = companions.find(
|
||||
(c) => c.type === progress.selectedCharacter,
|
||||
);
|
||||
if (companion) {
|
||||
const greetingEl = document.getElementById("forest-greeting")!;
|
||||
const avatarEl = document.getElementById(
|
||||
"forest-greeting-avatar",
|
||||
) as HTMLImageElement;
|
||||
const textEl = document.getElementById("forest-greeting-text")!;
|
||||
|
||||
avatarEl.src = companion.avatarUrl;
|
||||
avatarEl.alt = companion.name;
|
||||
greetingEl.style.display = "flex";
|
||||
|
||||
// Fetch greeting async (shows immediately with avatar, text fills in)
|
||||
getGreeting(progress.selectedCharacter, db).then((text) => {
|
||||
textEl.textContent = text;
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// First time -- show welcome, then forest after setup
|
||||
initWelcomeScreen(db, async (screen: ScreenName) => {
|
||||
|
||||
Reference in New Issue
Block a user