diff --git a/src/app.ts b/src/app.ts new file mode 100644 index 0000000..5f75f12 --- /dev/null +++ b/src/app.ts @@ -0,0 +1,32 @@ +import type { ScreenName } from "./types"; +import { openDB, getProgress } from "./storage/db"; +import { initWelcomeScreen } from "./ui/screens"; + +let db: IDBDatabase; + +export function showScreen(name: ScreenName): void { + document.querySelectorAll(".screen").forEach((el) => { + el.classList.remove("screen--active"); + }); + const target = document.getElementById(`screen-${name}`); + if (target) { + target.classList.add("screen--active"); + } +} + +export function getDB(): IDBDatabase { + return db; +} + +export async function initApp(): Promise { + db = await openDB(); + const progress = await getProgress(db); + if (progress && progress.selectedCharacter) { + // Returning user — skip welcome, go to forest + showScreen("forest"); + } else { + // First time — show welcome + initWelcomeScreen(db, showScreen); + showScreen("welcome"); + } +} diff --git a/src/companion/characters.ts b/src/companion/characters.ts new file mode 100644 index 0000000..742a5e9 --- /dev/null +++ b/src/companion/characters.ts @@ -0,0 +1,35 @@ +import type { CompanionType } from "../types"; + +export interface CompanionDefinition { + type: CompanionType; + name: string; + emoji: string; + personality: string; +} + +export const companions: CompanionDefinition[] = [ + { + type: "fee", + name: "Lila", + emoji: "🧚", + personality: "Sanft, ermutigend, ein bisschen vertraeumt", + }, + { + type: "einhorn", + name: "Stella", + emoji: "🦄", + personality: "Froehlich, enthusiastisch, feiert jeden kleinen Erfolg", + }, + { + type: "fuchs", + name: "Finn", + emoji: "🦊", + personality: "Ruhig, weise, humorvoll", + }, + { + type: "eule", + name: "Elsa", + emoji: "🦉", + personality: "Geduldig, warm, grossmuetterlich", + }, +]; diff --git a/src/main.ts b/src/main.ts index 461e88e..cba4f8f 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,3 +1,4 @@ import "./styles/main.css"; +import { initApp } from "./app"; -console.log("Zauberwald loaded"); +document.addEventListener("DOMContentLoaded", initApp); diff --git a/src/ui/screens.ts b/src/ui/screens.ts new file mode 100644 index 0000000..0a0350f --- /dev/null +++ b/src/ui/screens.ts @@ -0,0 +1,8 @@ +import type { ScreenName } from "../types"; + +export function initWelcomeScreen( + _db: IDBDatabase, + _navigateTo: (screen: ScreenName) => void, +): void { + // Implemented in Task 2 +}