This commit is contained in:
1 parent
3f8984bb09
commit
97b2fa58a5
6 files changed
+1196
-180
No files matched your search
@@ -2,151 +2,131 @@
|
||||
"recipient": "Mama",
|
||||
"eventDate": "vandaag",
|
||||
"title": "Mama's Geheime Leeshoek",
|
||||
"subtitle": "Lees de acht boeken, vind het geheimwoord en open de lade.",
|
||||
"subtitle": "Open de vier boeken, vind het geheimwoord en open de lade.",
|
||||
"books": [
|
||||
{
|
||||
"id": "zilveren-maan",
|
||||
"title": "De Zilveren Maan",
|
||||
"author": "L. van der Ster",
|
||||
"color": "#183748",
|
||||
"id": "achter-de-kaft",
|
||||
"kind": "quiz",
|
||||
"title": "Achter de Kaft",
|
||||
"author": "B. van Leeuwen",
|
||||
"color": "#1d3a4a",
|
||||
"color2": "#2f5f75",
|
||||
"ink": "#f6e8c6",
|
||||
"emblem": "moon",
|
||||
"intro": "Een nachtboek vol sterren, met een maan die nooit ondergaat.",
|
||||
"quote": "Sommige verhalen lees je het liefst met de lichten uit.",
|
||||
"question": "Je kruipt met een boek onder een deken. Wat ga je doen?",
|
||||
"options": ["Lezen", "Slapen", "Koken"],
|
||||
"emblem": "book",
|
||||
"intro": "Een boek over boeken: over wat je ziet voordat je begint te lezen.",
|
||||
"quote": "Soms begint een verhaal al op de achterkant.",
|
||||
"question": "Hoe noem je de korte tekst op de achterkant van een boek, die je nieuwsgierig moet maken?",
|
||||
"options": ["Flaptekst", "Colofon", "Leeslint"],
|
||||
"answer": 0,
|
||||
"letter": "L",
|
||||
"hint": "Het begint met dezelfde letter als 'lamp'.",
|
||||
"fact": "Precies: lezen. Elke bladzijde is een klein uitstapje.",
|
||||
"done": "De Zilveren Maan is gelezen. De letter L schuift op zijn plek."
|
||||
"letter": "B",
|
||||
"hint": "Je leest hem vaak achterop, vlak voor je een boek koopt.",
|
||||
"fact": "Een flaptekst. Soms verkoopt hij het boek al vóór de eerste bladzijde.",
|
||||
"done": "Achter de Kaft is gelezen. De letter B schuift op zijn plek."
|
||||
},
|
||||
{
|
||||
"id": "laatste-hoofdstuk",
|
||||
"title": "Het Laatste Hoofdstuk",
|
||||
"author": "E. Moreau",
|
||||
"id": "ezelsoren",
|
||||
"kind": "quiz",
|
||||
"title": "Ezelsoren",
|
||||
"author": "O. de Boer",
|
||||
"color": "#4a1f2b",
|
||||
"color2": "#7d3548",
|
||||
"ink": "#f6e3cd",
|
||||
"emblem": "feather",
|
||||
"intro": "Een roman die eindigt waar elk verhaal eigenlijk pas begint.",
|
||||
"quote": "Het einde is soms het begin van iets mooiers.",
|
||||
"question": "Hoe heet het stuk na het einde van een verhaal, waarin de afloop nog even napruttelt?",
|
||||
"options": ["Proloog", "Epiloog", "Inhoudstafel"],
|
||||
"answer": 1,
|
||||
"letter": "E",
|
||||
"hint": "Het is het tegenovergestelde van een proloog.",
|
||||
"fact": "Een epiloog. Soms is het mooiste hoofdstuk het allerlaatste.",
|
||||
"done": "Het Laatste Hoofdstuk is uit. De letter E ligt klaar."
|
||||
"intro": "Een klein boek over grote leesgewoonten en de sporen die een verhaal achterlaat.",
|
||||
"quote": "Een omgevouwen hoekje is een liefdesverklaring aan een bladzijde.",
|
||||
"question": "Een boek met omgevouwen hoekjes als bladwijzer noem je in het Engels 'dog-eared'. Wat betekent dat?",
|
||||
"options": ["Met ezelsoren", "Met een hondenriem", "Ongelezen"],
|
||||
"answer": 0,
|
||||
"letter": "O",
|
||||
"hint": "Denk aan de puntjes van een pagina die je omvouwt.",
|
||||
"fact": "Ezelsoren. Een teken dat een boek goed gelezen is.",
|
||||
"done": "Ezelsoren is gelezen. De letter O ligt klaar."
|
||||
},
|
||||
{
|
||||
"id": "bladzijden-van-glas",
|
||||
"title": "Bladzijden van Glas",
|
||||
"author": "M. de Winter",
|
||||
"color": "#23404f",
|
||||
"color2": "#3d6f82",
|
||||
"ink": "#eaf4f4",
|
||||
"emblem": "key",
|
||||
"intro": "Een spannend verhaal dat je liever niet op papier wilt lezen.",
|
||||
"quote": "Elke bladzijde glinstert een beetje gevaar.",
|
||||
"question": "Hoe noem je een boek dat je op een scherm leest?",
|
||||
"options": ["Luisterboek", "E-book", "Prentenboek"],
|
||||
"answer": 1,
|
||||
"letter": "E",
|
||||
"hint": "De 'e' staat voor elektronisch.",
|
||||
"fact": "Een e-book. Handig, maar niets verslaat de geur van papier.",
|
||||
"done": "Bladzijden van Glas is dichtgeslagen. De letter E is gevonden."
|
||||
},
|
||||
{
|
||||
"id": "tuin-van-woorden",
|
||||
"title": "De Tuin van Woorden",
|
||||
"author": "S. Veldman",
|
||||
"id": "geheugenpaleis",
|
||||
"kind": "memory",
|
||||
"title": "Het Geheugenpaleis",
|
||||
"author": "E. Verhalen",
|
||||
"color": "#2e4a30",
|
||||
"color2": "#557c4c",
|
||||
"ink": "#f2edcd",
|
||||
"emblem": "leaf",
|
||||
"intro": "Een bundel over taal die groeit als een tuin in de lente.",
|
||||
"quote": "Woorden zijn zaadjes. Geduld is de regen.",
|
||||
"question": "Iemand die een boek schrijft, noem je een...",
|
||||
"options": ["Lezer", "Schrijver", "Vertaler"],
|
||||
"answer": 1,
|
||||
"letter": "S",
|
||||
"hint": "Zonder deze persoon geen verhaal.",
|
||||
"fact": "Een schrijver. Elke tuin begint met één zaadje.",
|
||||
"done": "De Tuin van Woorden is gelezen. De letter S schiet wortel."
|
||||
"emblem": "owl",
|
||||
"intro": "Een boek over herinneringen, en over twee dezelfde symbolen die elkaar weten te vinden.",
|
||||
"quote": "Herinneringen zijn de bladwijzers van je leven.",
|
||||
"prompt": "Vind alle zes paren. Twee dezelfde symbolen horen bij elkaar.",
|
||||
"pairs": [
|
||||
{ "id": "maan", "label": "Maan", "emblem": "moon" },
|
||||
{ "id": "sleutel", "label": "Sleutel", "emblem": "key" },
|
||||
{ "id": "veer", "label": "Veer", "emblem": "feather" },
|
||||
{ "id": "blad", "label": "Blad", "emblem": "leaf" },
|
||||
{ "id": "schip", "label": "Schip", "emblem": "ship" },
|
||||
{ "id": "ster", "label": "Ster", "emblem": "star" }
|
||||
],
|
||||
"letter": "E",
|
||||
"hint": "Onthoud de plek van elk symbool. Er is geen tijdsdruk.",
|
||||
"fact": "Alle paren gevonden. Je geheugen is een echte boekenkast.",
|
||||
"done": "Het Geheugenpaleis is gelezen. De letter E is gevonden."
|
||||
},
|
||||
{
|
||||
"id": "kaartenkamer",
|
||||
"title": "De Kaartenkamer",
|
||||
"author": "H. Lindeboom",
|
||||
"id": "boekenkast",
|
||||
"kind": "shelf",
|
||||
"title": "De Boekenkast",
|
||||
"author": "K. Rekker",
|
||||
"color": "#6a4318",
|
||||
"color2": "#9c6c2c",
|
||||
"ink": "#fbf0d4",
|
||||
"emblem": "ship",
|
||||
"intro": "Een zeeverhaal vol geheime kaarten en verre kusten.",
|
||||
"quote": "Wie leest, zeilt zonder ooit de deur uit te gaan.",
|
||||
"question": "Hoe heet een onderdeel van een boek met een eigen titel en nummer?",
|
||||
"options": ["Hoofdstuk", "Boekrug", "Bladwijzer"],
|
||||
"answer": 0,
|
||||
"letter": "H",
|
||||
"hint": "Je zegt vaak: 'Ik ben bij het derde ...'.",
|
||||
"fact": "Een hoofdstuk. Elk hoofdstuk is een eiland op zich.",
|
||||
"done": "De Kaartenkamer is uit. De letter H is binnengevaren."
|
||||
},
|
||||
{
|
||||
"id": "het-omslag",
|
||||
"title": "Het Omslag",
|
||||
"author": "O. Ferrand",
|
||||
"color": "#3c2a4f",
|
||||
"color2": "#64497e",
|
||||
"ink": "#f2e6f5",
|
||||
"emblem": "star",
|
||||
"intro": "Een boek over boeken, en over de verhalen die ze verbergen.",
|
||||
"quote": "Oordeel niet naar het omslag, maar bewonder het gerust.",
|
||||
"question": "Wat zit er om de bladzijden van een boek heen?",
|
||||
"options": ["Omslag", "Leesbril", "Boekenlegger"],
|
||||
"answer": 0,
|
||||
"letter": "O",
|
||||
"hint": "Je ziet het als het boek dicht op tafel ligt.",
|
||||
"fact": "Het omslag. Soms koop je een boek gewoon omdat het mooi is.",
|
||||
"done": "Het Omslag is gesloten. De letter O glanst op zijn plek."
|
||||
},
|
||||
{
|
||||
"id": "alles-weten",
|
||||
"title": "Alles Weten",
|
||||
"author": "E. de Vries",
|
||||
"color": "#1f4a46",
|
||||
"color2": "#3d7d70",
|
||||
"ink": "#e9f6ee",
|
||||
"emblem": "owl",
|
||||
"intro": "Een dik naslagwerk voor nieuwsgierige avonden.",
|
||||
"quote": "Nieuwsgierigheid is een zeer leesbare eigenschap.",
|
||||
"question": "Welk boek staat vol weetjes, vaak op alfabetische volgorde?",
|
||||
"options": ["Roman", "Encyclopedie", "Dichtbundel"],
|
||||
"answer": 1,
|
||||
"letter": "E",
|
||||
"hint": "Vroeger stond er een hele kast vol van deze boeken.",
|
||||
"fact": "Een encyclopedie. Nieuwsgierigheid is een prima leesgewoonte.",
|
||||
"done": "Alles Weten is gelezen. De letter E staat erbij."
|
||||
},
|
||||
{
|
||||
"id": "warme-kamer",
|
||||
"title": "De Warme Kamer",
|
||||
"author": "K. Meijer",
|
||||
"color": "#5b2d32",
|
||||
"color2": "#8d4f51",
|
||||
"ink": "#f9e7d7",
|
||||
"emblem": "teacup",
|
||||
"intro": "Een cozy verhaal voor lange middagen met thee en regen.",
|
||||
"quote": "Een warm boek is een huis dat altijd open is.",
|
||||
"question": "Hoe noem je de stevige buitenkant van een boek?",
|
||||
"options": ["Kaft", "Rug", "Flap"],
|
||||
"answer": 0,
|
||||
"emblem": "key",
|
||||
"intro": "Een kast vol boeken, maar elk boek zoekt nog zijn eigen plek.",
|
||||
"quote": "Een goede kast is een landkaart van wie je bent.",
|
||||
"prompt": "Zet elk boek in het rek waar het thuishoort.",
|
||||
"shelves": [
|
||||
{ "id": "verhalen", "label": "Verhalen", "hint": "Romans en vertellingen" },
|
||||
{ "id": "keuken", "label": "Keuken", "hint": "Recepten en smaken" },
|
||||
{ "id": "reizen", "label": "Reizen", "hint": "Kaarten en verre oorden" },
|
||||
{ "id": "gedichten", "label": "Gedichten", "hint": "Rijm en gevoel" }
|
||||
],
|
||||
"items": [
|
||||
{
|
||||
"id": "zomerroman",
|
||||
"label": "Zomerroman",
|
||||
"shelf": "verhalen",
|
||||
"color": "#4a1f2b",
|
||||
"color2": "#7d3548",
|
||||
"ink": "#f6e3cd",
|
||||
"emblem": "feather"
|
||||
},
|
||||
{
|
||||
"id": "kookboek",
|
||||
"label": "Kookboek",
|
||||
"shelf": "keuken",
|
||||
"color": "#6a4318",
|
||||
"color2": "#9c6c2c",
|
||||
"ink": "#fbf0d4",
|
||||
"emblem": "teacup"
|
||||
},
|
||||
{
|
||||
"id": "reisgids",
|
||||
"label": "Reisgids",
|
||||
"shelf": "reizen",
|
||||
"color": "#1d3a4a",
|
||||
"color2": "#2f5f75",
|
||||
"ink": "#f6e8c6",
|
||||
"emblem": "ship"
|
||||
},
|
||||
{
|
||||
"id": "dichtbundel",
|
||||
"label": "Dichtbundel",
|
||||
"shelf": "gedichten",
|
||||
"color": "#2e4a30",
|
||||
"color2": "#557c4c",
|
||||
"ink": "#f2edcd",
|
||||
"emblem": "star"
|
||||
}
|
||||
],
|
||||
"letter": "K",
|
||||
"hint": "Het rijmt op 'kracht'.",
|
||||
"fact": "De kaft. Een boek met een mooie kaft mag gezien worden.",
|
||||
"done": "De Warme Kamer is uit. De letter K maakt het woord compleet."
|
||||
"hint": "Kijk naar het onderwerp van elk boek. De rekken vertellen je genoeg.",
|
||||
"fact": "Alles staat op zijn plek. Een kast waarin je wilt blijven lezen.",
|
||||
"done": "De Boekenkast is gelezen. De letter K maakt het woord compleet."
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -24,12 +24,17 @@ DEFAULT_CODE = "VUL-JE-CADEAUBONCODE-IN"
|
||||
MAX_BODY_BYTES = 16 * 1024
|
||||
PUBLIC_BOOK_FIELDS = (
|
||||
"id",
|
||||
"kind",
|
||||
"title",
|
||||
"author",
|
||||
"intro",
|
||||
"quote",
|
||||
"question",
|
||||
"options",
|
||||
"prompt",
|
||||
"pairs",
|
||||
"shelves",
|
||||
"items",
|
||||
"hint",
|
||||
"color",
|
||||
"color2",
|
||||
@@ -58,20 +63,58 @@ def load_game(path: Path) -> dict[str, Any]:
|
||||
raise ValueError("Elke boek-id moet uniek zijn.")
|
||||
|
||||
for book in books:
|
||||
answer = book.get("answer")
|
||||
options = book.get("options")
|
||||
if not isinstance(options, list) or not options:
|
||||
raise ValueError(f"Boek {book['id']} heeft geen antwoordopties.")
|
||||
if (
|
||||
isinstance(answer, bool)
|
||||
or not isinstance(answer, int)
|
||||
or not 0 <= answer < len(options)
|
||||
):
|
||||
raise ValueError(f"Boek {book['id']} heeft een ongeldig antwoord.")
|
||||
kind = book.get("kind")
|
||||
if kind not in ("quiz", "memory", "shelf"):
|
||||
raise ValueError(f"Boek {book['id']} heeft een onbekend soort opdracht.")
|
||||
|
||||
for field in ("letter", "fact", "done", "hint"):
|
||||
if not isinstance(book.get(field), str) or not book[field]:
|
||||
raise ValueError(f"Boek {book['id']} mist '{field}'.")
|
||||
|
||||
if kind == "quiz":
|
||||
answer = book.get("answer")
|
||||
options = book.get("options")
|
||||
if not isinstance(options, list) or len(options) < 2:
|
||||
raise ValueError(f"Boek {book['id']} heeft geen antwoordopties.")
|
||||
if (
|
||||
isinstance(answer, bool)
|
||||
or not isinstance(answer, int)
|
||||
or not 0 <= answer < len(options)
|
||||
):
|
||||
raise ValueError(f"Boek {book['id']} heeft een ongeldig antwoord.")
|
||||
|
||||
if kind == "memory":
|
||||
pairs = book.get("pairs")
|
||||
if not isinstance(pairs, list) or len(pairs) < 2:
|
||||
raise ValueError(f"Boek {book['id']} heeft te weinig memoryparen.")
|
||||
pair_ids = [pair.get("id") for pair in pairs]
|
||||
if len(pair_ids) != len(set(pair_ids)):
|
||||
raise ValueError(f"Boek {book['id']} heeft dubbele memoryparen.")
|
||||
for pair in pairs:
|
||||
for field in ("id", "label", "emblem"):
|
||||
if not isinstance(pair.get(field), str) or not pair[field]:
|
||||
raise ValueError(f"Memorypaar in {book['id']} mist '{field}'.")
|
||||
|
||||
if kind == "shelf":
|
||||
shelves = book.get("shelves")
|
||||
items = book.get("items")
|
||||
if not isinstance(shelves, list) or not shelves:
|
||||
raise ValueError(f"Boek {book['id']} heeft geen rekken.")
|
||||
if not isinstance(items, list) or not items:
|
||||
raise ValueError(f"Boek {book['id']} heeft geen boeken om te plaatsen.")
|
||||
shelf_ids = {shelf.get("id") for shelf in shelves}
|
||||
if len(shelf_ids) != len(shelves):
|
||||
raise ValueError(f"Boek {book['id']} heeft dubbele rekken.")
|
||||
item_ids = [item.get("id") for item in items]
|
||||
if len(item_ids) != len(set(item_ids)):
|
||||
raise ValueError(f"Boek {book['id']} heeft dubbele boeken.")
|
||||
for item in items:
|
||||
if item.get("shelf") not in shelf_ids:
|
||||
raise ValueError(f"Boek {book['id']} verwijst naar een onbekend rek.")
|
||||
for field in ("id", "label", "shelf", "emblem"):
|
||||
if not isinstance(item.get(field), str) or not item[field]:
|
||||
raise ValueError(f"Boek in {book['id']} mist '{field}'.")
|
||||
|
||||
return game
|
||||
|
||||
|
||||
@@ -86,7 +129,7 @@ def public_config(game: dict[str, Any]) -> dict[str, Any]:
|
||||
"title": os.environ.get("GAME_TITLE", game.get("title", "Mama's Geheime Leeshoek")),
|
||||
"subtitle": os.environ.get(
|
||||
"GAME_SUBTITLE",
|
||||
game.get("subtitle", "Lees de acht boeken en open de geheime lade."),
|
||||
game.get("subtitle", "Open de vier boeken en open de geheime lade."),
|
||||
),
|
||||
"books": [public_book(book) for book in game["books"]],
|
||||
}
|
||||
@@ -130,7 +173,7 @@ class GameRequestHandler(SimpleHTTPRequestHandler):
|
||||
|
||||
def do_POST(self) -> None:
|
||||
path = urlparse(self.path).path
|
||||
if path not in ("/api/solve", "/api/reveal"):
|
||||
if path not in ("/api/solve", "/api/complete", "/api/reveal"):
|
||||
self.send_json(HTTPStatus.NOT_FOUND, {"ok": False, "error": "Onbekend pad."})
|
||||
return
|
||||
|
||||
@@ -144,6 +187,8 @@ class GameRequestHandler(SimpleHTTPRequestHandler):
|
||||
|
||||
if path == "/api/solve":
|
||||
self.handle_solve(payload)
|
||||
elif path == "/api/complete":
|
||||
self.handle_complete(payload)
|
||||
else:
|
||||
self.handle_reveal(payload)
|
||||
|
||||
@@ -159,6 +204,13 @@ class GameRequestHandler(SimpleHTTPRequestHandler):
|
||||
)
|
||||
return
|
||||
|
||||
if book["kind"] != "quiz":
|
||||
self.send_json(
|
||||
HTTPStatus.BAD_REQUEST,
|
||||
{"ok": False, "error": "Dit boek heeft geen quizvraag."},
|
||||
)
|
||||
return
|
||||
|
||||
if (
|
||||
isinstance(answer, bool)
|
||||
or not isinstance(answer, int)
|
||||
@@ -191,6 +243,34 @@ class GameRequestHandler(SimpleHTTPRequestHandler):
|
||||
},
|
||||
)
|
||||
|
||||
def handle_complete(self, payload: dict[str, Any]) -> None:
|
||||
book_id = payload.get("bookId")
|
||||
book = self.data.books.get(book_id) if isinstance(book_id, str) else None
|
||||
|
||||
if book is None:
|
||||
self.send_json(
|
||||
HTTPStatus.NOT_FOUND,
|
||||
{"ok": False, "error": "Dit boek staat niet in de kast."},
|
||||
)
|
||||
return
|
||||
|
||||
if book["kind"] not in ("memory", "shelf"):
|
||||
self.send_json(
|
||||
HTTPStatus.BAD_REQUEST,
|
||||
{"ok": False, "error": "Dit boek heeft geen minigame."},
|
||||
)
|
||||
return
|
||||
|
||||
self.send_json(
|
||||
HTTPStatus.OK,
|
||||
{
|
||||
"ok": True,
|
||||
"letter": book["letter"],
|
||||
"explanation": book["fact"],
|
||||
"done": book["done"],
|
||||
},
|
||||
)
|
||||
|
||||
def handle_reveal(self, payload: dict[str, Any]) -> None:
|
||||
completed = payload.get("completed")
|
||||
if not isinstance(completed, list) or not all(
|
||||
|
||||
@@ -64,6 +64,12 @@
|
||||
<path d="M44 28h4c5 0 8 3 8 8s-3 8-8 8h-4"/>
|
||||
<path d="M22 16c0-3 3-4 3-7M31 16c0-3 3-4 3-7M40 16c0-3 3-4 3-7"/>
|
||||
<path d="M14 55h32"/>
|
||||
</svg>`,
|
||||
book: `
|
||||
<svg viewBox="0 0 64 64" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false">
|
||||
<path d="M32 17c-6-4-14-5-21-3v34c7-2 15-1 21 3 6-4 14-5 21-3V14c-7-2-15-1-21 3Z"/>
|
||||
<path d="M32 17v34"/>
|
||||
<path d="M15 21c5-1 10 0 14 2M49 21c-5-1-10 0-14 2"/>
|
||||
</svg>`
|
||||
};
|
||||
|
||||
@@ -88,10 +94,21 @@
|
||||
dialogAuthor: $("#book-dialog-author"),
|
||||
dialogIntro: $("#book-dialog-intro"),
|
||||
dialogQuote: $("#book-dialog-quote"),
|
||||
quizTask: $("#quiz-task"),
|
||||
memoryTask: $("#memory-task"),
|
||||
shelfTask: $("#shelf-task"),
|
||||
question: $("#book-question"),
|
||||
options: $("#book-options"),
|
||||
memoryPrompt: $("#memory-prompt"),
|
||||
memoryStats: $("#memory-stats"),
|
||||
memoryGrid: $("#memory-grid"),
|
||||
shelfPrompt: $("#shelf-prompt"),
|
||||
shelfHelp: $("#shelf-help"),
|
||||
shelfTray: $("#shelf-tray"),
|
||||
shelfRacks: $("#shelf-racks"),
|
||||
feedback: $("#book-feedback"),
|
||||
hint: $("#book-hint"),
|
||||
minigameRetry: $("#minigame-retry"),
|
||||
stamp: $("#letter-stamp"),
|
||||
stampLetter: $("#stamp-letter"),
|
||||
doneBtn: $("#book-done-btn"),
|
||||
@@ -138,6 +155,14 @@
|
||||
return list[Math.floor(Math.random() * list.length)];
|
||||
}
|
||||
|
||||
function shuffle(list) {
|
||||
for (let index = list.length - 1; index > 0; index -= 1) {
|
||||
const swapIndex = Math.floor(Math.random() * (index + 1));
|
||||
[list[index], list[swapIndex]] = [list[swapIndex], list[index]];
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
function renderEmblem(name) {
|
||||
return EMBLEMS[name] || EMBLEMS.star;
|
||||
}
|
||||
@@ -234,6 +259,16 @@
|
||||
playTone({ freq: 180, endFreq: 140, type: "sine", duration: 0.18, gain: 0.05, delay: 0.08 });
|
||||
}
|
||||
|
||||
function playFlip() {
|
||||
playNoise({ duration: 0.08, gain: 0.05, frequency: 1900 });
|
||||
playTone({ freq: 430, endFreq: 520, type: "sine", duration: 0.07, gain: 0.025 });
|
||||
}
|
||||
|
||||
function playMatch() {
|
||||
playTone({ freq: 587.33, endFreq: 587.33, type: "triangle", duration: 0.12, gain: 0.06 });
|
||||
playTone({ freq: 880, endFreq: 880, type: "sine", duration: 0.18, gain: 0.05, delay: 0.08 });
|
||||
}
|
||||
|
||||
function playUnlock() {
|
||||
playNoise({ duration: 0.07, gain: 0.08, frequency: 2500 });
|
||||
playTone({ freq: 340, endFreq: 120, type: "square", duration: 0.13, gain: 0.05 });
|
||||
@@ -376,7 +411,11 @@
|
||||
letter: "",
|
||||
answerIndex: null,
|
||||
doneText: "",
|
||||
explanation: ""
|
||||
explanation: "",
|
||||
memory: null,
|
||||
shelf: null,
|
||||
minigameDone: false,
|
||||
completing: false
|
||||
};
|
||||
|
||||
state.books.set(meta.id, book);
|
||||
@@ -387,6 +426,10 @@
|
||||
}
|
||||
});
|
||||
|
||||
els.shelves.forEach((shelf) => {
|
||||
shelf.hidden = shelf.children.length === 0;
|
||||
});
|
||||
|
||||
buildSlots();
|
||||
updateProgress();
|
||||
updateSlots();
|
||||
@@ -450,6 +493,7 @@
|
||||
book.answerIndex = saved.answer;
|
||||
book.doneText = saved.done;
|
||||
book.explanation = saved.explanation;
|
||||
book.minigameDone = true;
|
||||
book.element.classList.add("is-solved");
|
||||
book.element.setAttribute(
|
||||
"aria-label",
|
||||
@@ -457,7 +501,7 @@
|
||||
);
|
||||
}
|
||||
|
||||
function renderOptions(book) {
|
||||
function renderQuiz(book) {
|
||||
els.options.replaceChildren();
|
||||
const keys = ["A", "B", "C", "D", "E", "F"];
|
||||
|
||||
@@ -489,7 +533,6 @@
|
||||
button.classList.add("is-correct");
|
||||
}
|
||||
});
|
||||
showSolvedState(book);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -514,6 +557,7 @@
|
||||
return;
|
||||
}
|
||||
|
||||
const kind = book.meta.kind || "quiz";
|
||||
state.currentBookId = id;
|
||||
state.bookReturnFocus = document.activeElement;
|
||||
state.requestSerial += 1;
|
||||
@@ -524,17 +568,45 @@
|
||||
els.dialogAuthor.textContent = book.meta.author;
|
||||
els.dialogIntro.textContent = book.meta.intro;
|
||||
els.dialogQuote.textContent = book.meta.quote;
|
||||
els.question.textContent = book.meta.question;
|
||||
|
||||
els.quizTask.hidden = true;
|
||||
els.memoryTask.hidden = true;
|
||||
els.shelfTask.hidden = true;
|
||||
els.options.replaceChildren();
|
||||
els.memoryGrid.replaceChildren();
|
||||
els.shelfTray.replaceChildren();
|
||||
els.shelfRacks.replaceChildren();
|
||||
|
||||
els.feedback.textContent = "";
|
||||
els.feedback.className = "feedback";
|
||||
els.hint.hidden = true;
|
||||
els.hint.textContent = "";
|
||||
els.minigameRetry.hidden = true;
|
||||
els.stamp.hidden = true;
|
||||
els.stamp.classList.remove("is-visible");
|
||||
els.doneBtn.hidden = true;
|
||||
els.doneBtn.textContent = "Terug naar de kast";
|
||||
|
||||
renderOptions(book);
|
||||
if (kind === "quiz") {
|
||||
els.quizTask.hidden = false;
|
||||
els.question.textContent = book.meta.question;
|
||||
renderQuiz(book);
|
||||
} else if (kind === "memory") {
|
||||
els.memoryTask.hidden = false;
|
||||
els.memoryPrompt.textContent = book.meta.prompt;
|
||||
renderMemory(book);
|
||||
} else if (kind === "shelf") {
|
||||
els.shelfTask.hidden = false;
|
||||
els.shelfPrompt.textContent = book.meta.prompt;
|
||||
renderShelf(book);
|
||||
}
|
||||
|
||||
if (book.solved) {
|
||||
showSolvedState(book);
|
||||
} else if (book.minigameDone) {
|
||||
els.feedback.textContent = "Je hebt de opdracht al voltooid. Rond het boek af om de letter te vinden.";
|
||||
els.minigameRetry.hidden = false;
|
||||
}
|
||||
|
||||
els.bookModal.hidden = false;
|
||||
syncBodyLock();
|
||||
@@ -545,11 +617,447 @@
|
||||
els.doneBtn.focus();
|
||||
return;
|
||||
}
|
||||
const firstOption = $(".option", els.options);
|
||||
(firstOption || els.bookClose).focus();
|
||||
if (book.minigameDone) {
|
||||
els.minigameRetry.focus();
|
||||
return;
|
||||
}
|
||||
|
||||
const focusTarget = kind === "memory"
|
||||
? $(".memory-card", els.memoryGrid)
|
||||
: kind === "shelf"
|
||||
? $(".shelf-item", els.shelfTray)
|
||||
: $(".option", els.options);
|
||||
(focusTarget || els.bookClose).focus();
|
||||
}, 90);
|
||||
}
|
||||
|
||||
function ensureMemory(book) {
|
||||
if (!book.memory) {
|
||||
const deck = [];
|
||||
book.meta.pairs.forEach((pair) => {
|
||||
deck.push({ pairId: pair.id, label: pair.label, emblem: pair.emblem });
|
||||
deck.push({ pairId: pair.id, label: pair.label, emblem: pair.emblem });
|
||||
});
|
||||
book.memory = {
|
||||
deck: shuffle(deck),
|
||||
flipped: [],
|
||||
matched: new Set(),
|
||||
lock: false,
|
||||
timer: null,
|
||||
mistakes: 0,
|
||||
done: false
|
||||
};
|
||||
}
|
||||
|
||||
if (book.solved) {
|
||||
book.meta.pairs.forEach((pair) => book.memory.matched.add(pair.id));
|
||||
book.memory.flipped = [];
|
||||
book.memory.lock = false;
|
||||
book.memory.done = true;
|
||||
if (book.memory.timer) {
|
||||
window.clearTimeout(book.memory.timer);
|
||||
book.memory.timer = null;
|
||||
}
|
||||
}
|
||||
|
||||
return book.memory;
|
||||
}
|
||||
|
||||
function renderMemory(book) {
|
||||
const memory = ensureMemory(book);
|
||||
const total = book.meta.pairs.length;
|
||||
els.memoryStats.textContent = `${memory.matched.size} van ${total} paren gevonden`;
|
||||
els.memoryGrid.replaceChildren();
|
||||
|
||||
memory.deck.forEach((card, index) => {
|
||||
const matched = memory.matched.has(card.pairId);
|
||||
const flipped = memory.flipped.includes(index);
|
||||
const button = document.createElement("button");
|
||||
button.type = "button";
|
||||
button.className = "memory-card";
|
||||
if (matched || flipped) {
|
||||
button.classList.add("is-flipped");
|
||||
}
|
||||
if (matched) {
|
||||
button.classList.add("is-matched");
|
||||
}
|
||||
button.disabled = book.solved;
|
||||
button.dataset.index = String(index);
|
||||
button.setAttribute(
|
||||
"aria-label",
|
||||
matched
|
||||
? `${card.label}, gevonden`
|
||||
: flipped
|
||||
? `${card.label}, omgedraaid`
|
||||
: `Dichte kaart ${index + 1}`
|
||||
);
|
||||
button.setAttribute("aria-pressed", String(matched || flipped));
|
||||
|
||||
const inner = document.createElement("span");
|
||||
inner.className = "memory-inner";
|
||||
|
||||
const back = document.createElement("span");
|
||||
back.className = "memory-face memory-back";
|
||||
const backMark = document.createElement("span");
|
||||
backMark.className = "memory-back-mark";
|
||||
backMark.innerHTML = renderEmblem("book");
|
||||
back.appendChild(backMark);
|
||||
|
||||
const front = document.createElement("span");
|
||||
front.className = "memory-face memory-front";
|
||||
const emblem = document.createElement("span");
|
||||
emblem.className = "memory-emblem";
|
||||
emblem.innerHTML = renderEmblem(card.emblem);
|
||||
const label = document.createElement("span");
|
||||
label.className = "memory-label";
|
||||
label.textContent = card.label;
|
||||
front.append(emblem, label);
|
||||
|
||||
inner.append(back, front);
|
||||
button.appendChild(inner);
|
||||
button.addEventListener("click", () => flipMemoryCard(book, index));
|
||||
els.memoryGrid.appendChild(button);
|
||||
});
|
||||
}
|
||||
|
||||
function flipMemoryCard(book, index) {
|
||||
const memory = ensureMemory(book);
|
||||
if (book.solved || memory.done || memory.lock || memory.flipped.includes(index)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const card = memory.deck[index];
|
||||
if (!card || memory.matched.has(card.pairId)) {
|
||||
return;
|
||||
}
|
||||
|
||||
memory.flipped.push(index);
|
||||
const buttons = $$(".memory-card", els.memoryGrid);
|
||||
const button = buttons[index];
|
||||
if (button) {
|
||||
button.classList.add("is-flipped");
|
||||
button.setAttribute("aria-label", `${card.label}, omgedraaid`);
|
||||
button.setAttribute("aria-pressed", "true");
|
||||
}
|
||||
playFlip();
|
||||
|
||||
if (memory.flipped.length < 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
const [firstIndex, secondIndex] = memory.flipped;
|
||||
const first = memory.deck[firstIndex];
|
||||
const second = memory.deck[secondIndex];
|
||||
if (!first || !second) {
|
||||
memory.flipped = [];
|
||||
return;
|
||||
}
|
||||
|
||||
if (first.pairId === second.pairId) {
|
||||
memory.matched.add(first.pairId);
|
||||
memory.flipped = [];
|
||||
playMatch();
|
||||
[firstIndex, secondIndex].forEach((cardIndex) => {
|
||||
const cardButton = buttons[cardIndex];
|
||||
if (cardButton) {
|
||||
cardButton.classList.add("is-matched");
|
||||
cardButton.setAttribute("aria-label", `${first.label}, gevonden`);
|
||||
}
|
||||
});
|
||||
els.memoryStats.textContent = `${memory.matched.size} van ${book.meta.pairs.length} paren gevonden`;
|
||||
els.feedback.className = "feedback is-correct";
|
||||
els.feedback.textContent = `Gevonden: ${first.label}.`;
|
||||
|
||||
if (memory.matched.size === book.meta.pairs.length) {
|
||||
memory.done = true;
|
||||
book.minigameDone = true;
|
||||
els.memoryStats.textContent = `${book.meta.pairs.length} van ${book.meta.pairs.length} paren gevonden.`;
|
||||
els.feedback.textContent = "Alle paren gevonden. Het boek is bijna uit.";
|
||||
memory.timer = window.setTimeout(() => completeMinigame(book), 550);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
memory.lock = true;
|
||||
memory.mistakes += 1;
|
||||
playWrong();
|
||||
els.feedback.className = "feedback is-error";
|
||||
els.feedback.textContent = "Bijna. Onthoud de plek en probeer opnieuw.";
|
||||
if (memory.mistakes >= 2) {
|
||||
els.hint.textContent = book.meta.hint;
|
||||
els.hint.hidden = false;
|
||||
}
|
||||
|
||||
memory.timer = window.setTimeout(() => {
|
||||
memory.flipped = [];
|
||||
memory.lock = false;
|
||||
if (state.currentBookId === book.id) {
|
||||
$$(".memory-card", els.memoryGrid).forEach((cardButton, cardIndex) => {
|
||||
if (memory.matched.has(memory.deck[cardIndex].pairId)) {
|
||||
return;
|
||||
}
|
||||
cardButton.classList.remove("is-flipped");
|
||||
cardButton.setAttribute("aria-label", `Dichte kaart ${cardIndex + 1}`);
|
||||
cardButton.setAttribute("aria-pressed", "false");
|
||||
});
|
||||
}
|
||||
memory.timer = null;
|
||||
}, 850);
|
||||
}
|
||||
|
||||
function ensureShelf(book) {
|
||||
if (!book.shelf) {
|
||||
book.shelf = {
|
||||
items: shuffle(book.meta.items.map((item) => ({ ...item }))),
|
||||
placed: {},
|
||||
selectedId: null,
|
||||
mistakes: 0,
|
||||
done: false,
|
||||
timer: null
|
||||
};
|
||||
}
|
||||
|
||||
if (book.solved) {
|
||||
book.meta.items.forEach((item) => {
|
||||
book.shelf.placed[item.id] = item.shelf;
|
||||
});
|
||||
book.shelf.selectedId = null;
|
||||
book.shelf.done = true;
|
||||
if (book.shelf.timer) {
|
||||
window.clearTimeout(book.shelf.timer);
|
||||
book.shelf.timer = null;
|
||||
}
|
||||
}
|
||||
|
||||
return book.shelf;
|
||||
}
|
||||
|
||||
function createMiniBook(item, placed) {
|
||||
const element = document.createElement(placed ? "span" : "button");
|
||||
if (!placed) {
|
||||
element.type = "button";
|
||||
}
|
||||
element.className = `shelf-item${placed ? " is-placed" : ""}`;
|
||||
element.style.setProperty("--item-cover", item.color || "#2e4a30");
|
||||
element.style.setProperty("--item-cover-2", item.color2 || "#557c4c");
|
||||
element.style.setProperty("--item-ink", item.ink || "#f7eedb");
|
||||
|
||||
const emblem = document.createElement("span");
|
||||
emblem.className = "mini-emblem";
|
||||
emblem.setAttribute("aria-hidden", "true");
|
||||
emblem.innerHTML = renderEmblem(item.emblem);
|
||||
|
||||
const label = document.createElement("span");
|
||||
label.className = "mini-label";
|
||||
label.textContent = item.label;
|
||||
|
||||
element.append(emblem, label);
|
||||
return element;
|
||||
}
|
||||
|
||||
function renderShelf(book) {
|
||||
const shelf = ensureShelf(book);
|
||||
const placedCount = Object.keys(shelf.placed).length;
|
||||
const total = book.meta.items.length;
|
||||
els.shelfPrompt.textContent = book.meta.prompt;
|
||||
els.shelfHelp.textContent = book.solved || shelf.done
|
||||
? `Alle ${total} boeken staan op hun plek.`
|
||||
: `${placedCount} van ${total} boeken geplaatst. Klik op een boek en daarna op het juiste rek.`;
|
||||
|
||||
els.shelfTray.replaceChildren();
|
||||
shelf.items.forEach((item) => {
|
||||
if (shelf.placed[item.id]) {
|
||||
return;
|
||||
}
|
||||
const button = createMiniBook(item, false);
|
||||
button.dataset.id = item.id;
|
||||
button.dataset.label = item.label;
|
||||
const selected = shelf.selectedId === item.id;
|
||||
button.classList.toggle("is-selected", selected);
|
||||
button.setAttribute("aria-pressed", String(selected));
|
||||
button.setAttribute("aria-label", `${item.label}${selected ? ", geselecteerd" : ""}`);
|
||||
button.addEventListener("click", () => selectShelfItem(book, item.id));
|
||||
els.shelfTray.appendChild(button);
|
||||
});
|
||||
|
||||
els.shelfRacks.replaceChildren();
|
||||
book.meta.shelves.forEach((shelfMeta) => {
|
||||
const placedItem = book.meta.items.find(
|
||||
(item) => shelf.placed[item.id] === shelfMeta.id
|
||||
);
|
||||
const rack = document.createElement("button");
|
||||
rack.type = "button";
|
||||
rack.className = "rack";
|
||||
if (placedItem) {
|
||||
rack.classList.add("is-filled");
|
||||
}
|
||||
if (shelf.selectedId) {
|
||||
rack.classList.add("is-targetable");
|
||||
}
|
||||
rack.disabled = book.solved || shelf.done;
|
||||
rack.setAttribute(
|
||||
"aria-label",
|
||||
placedItem
|
||||
? `${shelfMeta.label}: ${placedItem.label} staat op zijn plek.`
|
||||
: `Plaats het geselecteerde boek in ${shelfMeta.label}.`
|
||||
);
|
||||
|
||||
const label = document.createElement("span");
|
||||
label.className = "rack-label";
|
||||
label.textContent = shelfMeta.label;
|
||||
|
||||
const hint = document.createElement("span");
|
||||
hint.className = "rack-hint";
|
||||
hint.textContent = shelfMeta.hint;
|
||||
|
||||
const slot = document.createElement("span");
|
||||
slot.className = "rack-slot";
|
||||
if (placedItem) {
|
||||
slot.appendChild(createMiniBook(placedItem, true));
|
||||
}
|
||||
|
||||
rack.append(label, hint, slot);
|
||||
rack.addEventListener("click", () => chooseShelf(book, shelfMeta.id));
|
||||
els.shelfRacks.appendChild(rack);
|
||||
});
|
||||
}
|
||||
|
||||
function selectShelfItem(book, itemId) {
|
||||
const shelf = ensureShelf(book);
|
||||
if (book.solved || shelf.done) {
|
||||
return;
|
||||
}
|
||||
|
||||
const item = shelf.items.find((entry) => entry.id === itemId);
|
||||
shelf.selectedId = shelf.selectedId === itemId ? null : itemId;
|
||||
|
||||
$$(".shelf-item", els.shelfTray).forEach((button) => {
|
||||
const selected = button.dataset.id === shelf.selectedId;
|
||||
button.classList.toggle("is-selected", selected);
|
||||
button.setAttribute("aria-pressed", String(selected));
|
||||
button.setAttribute(
|
||||
"aria-label",
|
||||
`${button.dataset.label}${selected ? ", geselecteerd" : ""}`
|
||||
);
|
||||
});
|
||||
$$(".rack", els.shelfRacks).forEach((rack) => {
|
||||
rack.classList.toggle("is-targetable", Boolean(shelf.selectedId));
|
||||
});
|
||||
|
||||
els.feedback.className = "feedback";
|
||||
els.feedback.textContent = shelf.selectedId && item
|
||||
? `Kies een rek voor ${item.label}.`
|
||||
: "Kies een boek en daarna een rek.";
|
||||
playFlip();
|
||||
}
|
||||
|
||||
function chooseShelf(book, shelfId) {
|
||||
const shelf = ensureShelf(book);
|
||||
if (book.solved || shelf.done) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!shelf.selectedId) {
|
||||
els.feedback.className = "feedback is-error";
|
||||
els.feedback.textContent = "Kies eerst een boek uit de stapel.";
|
||||
playWrong();
|
||||
return;
|
||||
}
|
||||
|
||||
const item = shelf.items.find((entry) => entry.id === shelf.selectedId);
|
||||
if (!item) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (item.shelf !== shelfId) {
|
||||
shelf.mistakes += 1;
|
||||
playWrong();
|
||||
els.feedback.className = "feedback is-error";
|
||||
els.feedback.textContent = `${item.label} hoort niet bij dit rek. Kijk naar het onderwerp.`;
|
||||
if (shelf.mistakes >= 2) {
|
||||
els.hint.textContent = book.meta.hint;
|
||||
els.hint.hidden = false;
|
||||
}
|
||||
|
||||
const racks = $$(".rack", els.shelfRacks);
|
||||
const targetIndex = book.meta.shelves.findIndex((entry) => entry.id === shelfId);
|
||||
const rack = racks[targetIndex];
|
||||
if (rack) {
|
||||
rack.classList.remove("is-wrong");
|
||||
void rack.offsetWidth;
|
||||
rack.classList.add("is-wrong");
|
||||
window.setTimeout(() => rack.classList.remove("is-wrong"), 400);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
shelf.placed[item.id] = shelfId;
|
||||
shelf.selectedId = null;
|
||||
playMatch();
|
||||
|
||||
if (Object.keys(shelf.placed).length === book.meta.items.length) {
|
||||
shelf.done = true;
|
||||
book.minigameDone = true;
|
||||
els.feedback.className = "feedback is-correct";
|
||||
els.feedback.textContent = "Alle boeken staan op hun plek. Het boek is bijna uit.";
|
||||
renderShelf(book);
|
||||
shelf.timer = window.setTimeout(() => completeMinigame(book), 550);
|
||||
return;
|
||||
}
|
||||
|
||||
els.feedback.className = "feedback is-correct";
|
||||
els.feedback.textContent = `${item.label} staat goed.`;
|
||||
renderShelf(book);
|
||||
|
||||
const nextItem = $(".shelf-item", els.shelfTray);
|
||||
if (nextItem) {
|
||||
nextItem.focus();
|
||||
}
|
||||
}
|
||||
|
||||
async function completeMinigame(book) {
|
||||
if (!book || book.solved || book.completing) {
|
||||
return;
|
||||
}
|
||||
|
||||
const serial = ++state.requestSerial;
|
||||
state.requestInFlight = true;
|
||||
book.completing = true;
|
||||
const isCurrent = () => serial === state.requestSerial && state.currentBookId === book.id;
|
||||
els.minigameRetry.hidden = true;
|
||||
els.feedback.className = "feedback";
|
||||
els.feedback.textContent = "De laatste bladzijde wordt geschreven...";
|
||||
ensureAudio();
|
||||
|
||||
try {
|
||||
const response = await fetch("/api/complete", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ bookId: book.id })
|
||||
});
|
||||
const data = await response.json().catch(() => ({}));
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(data.error || "De leeshoek is even niet bereikbaar.");
|
||||
}
|
||||
|
||||
book.completing = false;
|
||||
markSolved(book, data, null, isCurrent());
|
||||
} catch (error) {
|
||||
book.completing = false;
|
||||
if (isCurrent()) {
|
||||
els.feedback.className = "feedback is-error";
|
||||
els.feedback.textContent = `${error.message} Het boek is bijna klaar; probeer het nog eens.`;
|
||||
els.minigameRetry.hidden = false;
|
||||
playWrong();
|
||||
}
|
||||
} finally {
|
||||
if (serial === state.requestSerial) {
|
||||
state.requestInFlight = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function answerBook(book, index) {
|
||||
if (book.solved || state.requestInFlight) {
|
||||
return;
|
||||
@@ -653,12 +1161,14 @@
|
||||
setLog(book.doneText || `Juist. De letter ${book.letter} is gevonden.`, "done");
|
||||
|
||||
if (updateDialog) {
|
||||
$$(".option", els.options).forEach((button, index) => {
|
||||
button.disabled = true;
|
||||
if (index === answerIndex) {
|
||||
button.classList.add("is-correct");
|
||||
}
|
||||
});
|
||||
if ((book.meta.kind || "quiz") === "quiz") {
|
||||
$$(".option", els.options).forEach((button, index) => {
|
||||
button.disabled = true;
|
||||
if (index === answerIndex) {
|
||||
button.classList.add("is-correct");
|
||||
}
|
||||
});
|
||||
}
|
||||
showSolvedState(book);
|
||||
window.setTimeout(() => els.doneBtn.focus(), 260);
|
||||
}
|
||||
@@ -686,8 +1196,9 @@
|
||||
playUnlock();
|
||||
}
|
||||
if (wasLocked && announce) {
|
||||
const word = state.order.map((book) => book.letter).join("");
|
||||
setLog(
|
||||
"Alle acht boeken zijn gelezen. De letters vormen LEESHOEK — de lade klikt open!",
|
||||
`Alle ${state.order.length} boeken zijn gelezen. De letters vormen ${word} — de lade klikt open!`,
|
||||
"done"
|
||||
);
|
||||
}
|
||||
@@ -769,6 +1280,17 @@
|
||||
if (els.bookModal.hidden) {
|
||||
return;
|
||||
}
|
||||
|
||||
const book = state.currentBookId ? state.books.get(state.currentBookId) : null;
|
||||
if (book && book.memory) {
|
||||
if (book.memory.timer) {
|
||||
window.clearTimeout(book.memory.timer);
|
||||
book.memory.timer = null;
|
||||
}
|
||||
book.memory.flipped = [];
|
||||
book.memory.lock = false;
|
||||
}
|
||||
|
||||
els.bookModal.hidden = true;
|
||||
state.currentBookId = null;
|
||||
state.requestInFlight = false;
|
||||
@@ -799,12 +1321,22 @@
|
||||
|
||||
function resetGame() {
|
||||
state.books.forEach((book) => {
|
||||
if (book.memory && book.memory.timer) {
|
||||
window.clearTimeout(book.memory.timer);
|
||||
}
|
||||
if (book.shelf && book.shelf.timer) {
|
||||
window.clearTimeout(book.shelf.timer);
|
||||
}
|
||||
book.solved = false;
|
||||
book.attempts = 0;
|
||||
book.letter = "";
|
||||
book.answerIndex = null;
|
||||
book.doneText = "";
|
||||
book.explanation = "";
|
||||
book.memory = null;
|
||||
book.shelf = null;
|
||||
book.minigameDone = false;
|
||||
book.completing = false;
|
||||
book.element.classList.remove("is-solved");
|
||||
book.element.setAttribute(
|
||||
"aria-label",
|
||||
@@ -821,6 +1353,7 @@
|
||||
updateProgress();
|
||||
updateSlots();
|
||||
els.secret.classList.remove("is-complete");
|
||||
els.minigameRetry.hidden = true;
|
||||
els.log.className = "log";
|
||||
setLog("Nieuwe ronde, dezelfde kast. Kies een boek en begin opnieuw.", "done");
|
||||
closeVoucher();
|
||||
@@ -970,7 +1503,7 @@
|
||||
setText("#game-subtitle", config.subtitle);
|
||||
setText(
|
||||
"#voucher-lead",
|
||||
`${config.recipient}, je hebt alle acht boeken gelezen. Achter de kast lag een envelop met iets om zelf een nieuw verhaal uit te kiezen.`
|
||||
`${config.recipient}, je hebt alle ${config.books.length} boeken gelezen. Achter de kast lag een envelop met iets om zelf een nieuw verhaal uit te kiezen.`
|
||||
);
|
||||
|
||||
if (config.title) {
|
||||
@@ -1023,6 +1556,12 @@
|
||||
els.playAgain.addEventListener("click", resetGame);
|
||||
els.copyButton.addEventListener("click", copyCode);
|
||||
els.drawer.addEventListener("click", handleDrawer);
|
||||
els.minigameRetry.addEventListener("click", () => {
|
||||
const book = state.currentBookId ? state.books.get(state.currentBookId) : null;
|
||||
if (book && (book.meta.kind === "memory" || book.meta.kind === "shelf")) {
|
||||
completeMinigame(book);
|
||||
}
|
||||
});
|
||||
|
||||
$$("[data-close]").forEach((node) => {
|
||||
node.addEventListener("click", () => {
|
||||
@@ -1078,7 +1617,7 @@
|
||||
if (state.solvedCount === state.order.length) {
|
||||
unlockDrawer({ announce: false, sound: false });
|
||||
setLog(
|
||||
"Welkom terug. Alle acht boeken zijn al gelezen — de lade staat op je te wachten.",
|
||||
`Welkom terug. Alle ${state.order.length} boeken zijn al gelezen — de lade staat op je te wachten.`,
|
||||
"done"
|
||||
);
|
||||
} else if (state.solvedCount > 0) {
|
||||
@@ -1087,7 +1626,7 @@
|
||||
"done"
|
||||
);
|
||||
} else {
|
||||
setLog("De kast staat klaar. Kies een boek en los de kleine opdracht op.");
|
||||
setLog("De kast staat klaar: twee vragen en twee minigames. Kies een boek.");
|
||||
}
|
||||
} catch (error) {
|
||||
setLog(`De boekenkast kon niet geladen worden: ${error.message}`, "warning");
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="theme-color" content="#101b16">
|
||||
<meta name="description" content="Lees de acht boeken van Mama's geheime leeshoek en open de lade met de cadeaubon.">
|
||||
<meta name="description" content="Open de vier boeken van Mama's geheime leeshoek en open de lade met de cadeaubon.">
|
||||
<title>Mama's Geheime Leeshoek</title>
|
||||
<link rel="stylesheet" href="style.css">
|
||||
</head>
|
||||
@@ -13,14 +13,14 @@
|
||||
<header class="hero">
|
||||
<p class="eyebrow">Een verhaal voor <span id="recipient-name">Mama</span></p>
|
||||
<h1 id="game-title">Mama's Geheime Leeshoek</h1>
|
||||
<p class="tagline" id="game-subtitle">Lees de acht boeken, vind het geheimwoord en open de lade.</p>
|
||||
<p class="tagline" id="game-subtitle">Open de vier boeken, vind het geheimwoord en open de lade.</p>
|
||||
</header>
|
||||
|
||||
<main class="game-shell" id="game-shell">
|
||||
<div class="hud">
|
||||
<div class="progress" aria-live="polite">
|
||||
<div class="progress-copy">
|
||||
<span id="progress-text">0 / 8 boeken gelezen</span>
|
||||
<span id="progress-text">0 / 4 boeken gelezen</span>
|
||||
<span id="progress-percent">0%</span>
|
||||
</div>
|
||||
<div class="progress-track" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0" id="progress-track">
|
||||
@@ -75,10 +75,10 @@
|
||||
</section>
|
||||
|
||||
<div class="underbar">
|
||||
<p class="log" id="log" role="status" aria-live="polite">De kast staat klaar. Kies een boek en los de kleine opdracht op.</p>
|
||||
<p class="log" id="log" role="status" aria-live="polite">De kast staat klaar: twee vragen en twee minigames. Kies een boek.</p>
|
||||
</div>
|
||||
|
||||
<p class="controls-hint">Klik op een boek om het te openen. Er is geen tijdsdruk — elk verhaal wacht geduldig.</p>
|
||||
<p class="controls-hint">Klik op een boek. Twee boeken stellen een vraag, twee boeken zijn een minigame. Er is geen tijdsdruk.</p>
|
||||
</main>
|
||||
|
||||
<footer class="footer">
|
||||
@@ -106,11 +106,30 @@
|
||||
|
||||
<div class="book-page page-right">
|
||||
<div class="task">
|
||||
<p class="task-kicker">Opdracht</p>
|
||||
<h3 id="book-question">Vraag</h3>
|
||||
<div class="options" id="book-options" role="group" aria-label="Kies je antwoord"></div>
|
||||
<div class="task-panel" id="quiz-task">
|
||||
<p class="task-kicker">Opdracht</p>
|
||||
<h3 id="book-question">Vraag</h3>
|
||||
<div class="options" id="book-options" role="group" aria-label="Kies je antwoord"></div>
|
||||
</div>
|
||||
|
||||
<div class="task-panel" id="memory-task" hidden>
|
||||
<p class="task-kicker">Minigame · Memory</p>
|
||||
<h3 id="memory-prompt">Vind alle paren.</h3>
|
||||
<p class="minigame-meta" id="memory-stats"></p>
|
||||
<div class="memory-grid" id="memory-grid" role="grid" aria-label="Memoryspel"></div>
|
||||
</div>
|
||||
|
||||
<div class="task-panel" id="shelf-task" hidden>
|
||||
<p class="task-kicker">Minigame · Boekenrek</p>
|
||||
<h3 id="shelf-prompt">Zet elk boek in het juiste rek.</h3>
|
||||
<p class="minigame-meta" id="shelf-help"></p>
|
||||
<div class="shelf-tray" id="shelf-tray" aria-label="Nog te plaatsen boeken"></div>
|
||||
<div class="shelf-racks" id="shelf-racks"></div>
|
||||
</div>
|
||||
|
||||
<p class="feedback" id="book-feedback" role="status" aria-live="polite"></p>
|
||||
<p class="hint" id="book-hint" hidden></p>
|
||||
<button type="button" class="secondary-btn minigame-retry" id="minigame-retry" hidden>Probeer opnieuw</button>
|
||||
<div class="letter-stamp" id="letter-stamp" aria-hidden="true" hidden>
|
||||
<span class="stamp-letter" id="stamp-letter">L</span>
|
||||
<span class="stamp-caption">gevonden</span>
|
||||
@@ -126,7 +145,7 @@
|
||||
<section class="voucher" role="dialog" aria-modal="true" aria-labelledby="voucher-title" aria-describedby="voucher-lead">
|
||||
<p class="voucher-kicker">Gevonden in de geheime lade</p>
|
||||
<h2 id="voucher-title">Een boek naar keuze</h2>
|
||||
<p class="voucher-lead" id="voucher-lead">Mama, je hebt alle acht boeken gelezen. Achter de kast lag een envelop met iets om zelf een nieuw verhaal uit te kiezen.</p>
|
||||
<p class="voucher-lead" id="voucher-lead">Mama, je hebt alle vier boeken gelezen. Achter de kast lag een envelop met iets om zelf een nieuw verhaal uit te kiezen.</p>
|
||||
|
||||
<div class="voucher-card">
|
||||
<span class="voucher-label">Cadeaubon</span>
|
||||
|
||||
@@ -1154,6 +1154,356 @@ h1 {
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.minigame-meta {
|
||||
margin: 6px 0 14px;
|
||||
color: #7a6440;
|
||||
font-size: clamp(.76rem, 1.5vw, .84rem);
|
||||
font-weight: 700;
|
||||
line-height: 1.45;
|
||||
}
|
||||
|
||||
.memory-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(4, minmax(0, 1fr));
|
||||
gap: clamp(6px, 1.2vw, 10px);
|
||||
margin: 0 0 14px;
|
||||
}
|
||||
|
||||
.memory-card {
|
||||
position: relative;
|
||||
aspect-ratio: 3 / 4;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
background: none;
|
||||
cursor: pointer;
|
||||
perspective: 800px;
|
||||
-webkit-tap-highlight-color: transparent;
|
||||
}
|
||||
|
||||
.memory-inner {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
transform-style: preserve-3d;
|
||||
transition: transform .35s cubic-bezier(.2, .8, .3, 1);
|
||||
}
|
||||
|
||||
.memory-card.is-flipped .memory-inner {
|
||||
transform: rotateY(180deg);
|
||||
}
|
||||
|
||||
.memory-face {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 5px;
|
||||
overflow: hidden;
|
||||
border-radius: 5px;
|
||||
backface-visibility: hidden;
|
||||
-webkit-backface-visibility: hidden;
|
||||
}
|
||||
|
||||
.memory-back {
|
||||
border: 1px solid #8a6a2f;
|
||||
background:
|
||||
radial-gradient(circle at 30% 20%, rgba(255, 255, 255, .12), transparent 38%),
|
||||
repeating-linear-gradient(45deg, rgba(240, 201, 106, .05) 0 6px, transparent 6px 12px),
|
||||
linear-gradient(150deg, #2e4a30, #182f22);
|
||||
color: var(--brass-bright);
|
||||
box-shadow:
|
||||
inset 0 0 0 3px rgba(240, 201, 106, .14),
|
||||
0 4px 8px rgba(0, 0, 0, .2);
|
||||
}
|
||||
|
||||
.memory-back-mark {
|
||||
display: grid;
|
||||
place-items: center;
|
||||
width: 56%;
|
||||
aspect-ratio: 1;
|
||||
border: 1px solid rgba(240, 201, 106, .35);
|
||||
border-radius: 50%;
|
||||
background: rgba(0, 0, 0, .14);
|
||||
}
|
||||
|
||||
.memory-back-mark svg {
|
||||
width: 62%;
|
||||
height: 62%;
|
||||
opacity: .85;
|
||||
}
|
||||
|
||||
.memory-front {
|
||||
transform: rotateY(180deg);
|
||||
border: 1px solid #b89a5c;
|
||||
background:
|
||||
radial-gradient(circle at 30% 20%, rgba(255, 255, 255, .8), transparent 40%),
|
||||
linear-gradient(180deg, #fff9ea, #ecdbb6);
|
||||
color: #5c4724;
|
||||
}
|
||||
|
||||
.memory-front svg {
|
||||
width: 58%;
|
||||
height: 40%;
|
||||
overflow: visible;
|
||||
}
|
||||
|
||||
.memory-emblem {
|
||||
display: grid;
|
||||
place-items: center;
|
||||
width: 58%;
|
||||
height: 40%;
|
||||
}
|
||||
|
||||
.memory-emblem svg {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
overflow: visible;
|
||||
}
|
||||
|
||||
.memory-label {
|
||||
max-width: 96%;
|
||||
padding: 0 2px;
|
||||
overflow: hidden;
|
||||
font-family: var(--serif);
|
||||
font-size: clamp(.5rem, 1.2vw, .68rem);
|
||||
font-weight: 700;
|
||||
line-height: 1.1;
|
||||
text-align: center;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.memory-card.is-matched .memory-front {
|
||||
border-color: #5f7d4f;
|
||||
background:
|
||||
radial-gradient(circle at 30% 20%, rgba(255, 255, 255, .8), transparent 40%),
|
||||
linear-gradient(180deg, #f3f8e6, #dfecc9);
|
||||
box-shadow: 0 0 0 2px rgba(95, 125, 79, .42);
|
||||
}
|
||||
|
||||
.memory-card.is-matched {
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
.memory-card:focus-visible {
|
||||
outline: 2px solid var(--brass-dark);
|
||||
outline-offset: 2px;
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
.memory-card.is-matched:focus-visible {
|
||||
outline-color: #5f7d4f;
|
||||
}
|
||||
|
||||
.memory-card:disabled {
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
.shelf-tray {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 7px;
|
||||
min-height: 62px;
|
||||
margin-bottom: 10px;
|
||||
padding: 9px;
|
||||
border: 1px dashed rgba(154, 107, 35, .45);
|
||||
border-radius: 9px;
|
||||
background: rgba(185, 154, 92, .09);
|
||||
}
|
||||
|
||||
.shelf-tray:empty::after {
|
||||
content: "Alle boeken staan op hun plek.";
|
||||
align-self: center;
|
||||
width: 100%;
|
||||
color: #7a6440;
|
||||
font-size: .8rem;
|
||||
font-style: italic;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.shelf-item {
|
||||
position: relative;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 4px;
|
||||
width: clamp(58px, 11vw, 76px);
|
||||
min-height: clamp(72px, 14vw, 94px);
|
||||
padding: 7px 5px 6px 8px;
|
||||
border: 1px solid rgba(255, 255, 255, .2);
|
||||
border-radius: 3px 6px 6px 3px;
|
||||
background:
|
||||
radial-gradient(circle at 28% 18%, rgba(255, 255, 255, .14), transparent 40%),
|
||||
linear-gradient(150deg, var(--item-cover, #2e4a30), var(--item-cover-2, #557c4c));
|
||||
color: var(--item-ink, #f7eedb);
|
||||
box-shadow: 0 4px 9px rgba(0, 0, 0, .24), inset 0 0 0 1px rgba(255, 255, 255, .1);
|
||||
cursor: pointer;
|
||||
transition: transform .15s, box-shadow .15s, border-color .15s;
|
||||
}
|
||||
|
||||
.shelf-item::before {
|
||||
content: "";
|
||||
position: absolute;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
width: 5px;
|
||||
border-radius: 3px 0 0 3px;
|
||||
background: linear-gradient(90deg, rgba(0, 0, 0, .4), rgba(255, 255, 255, .08));
|
||||
}
|
||||
|
||||
.shelf-item.is-placed {
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
.shelf-item:not(.is-placed):hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 8px 14px rgba(0, 0, 0, .28), 0 0 0 1px rgba(240, 201, 106, .55);
|
||||
}
|
||||
|
||||
.shelf-item.is-selected {
|
||||
border-color: var(--brass-bright);
|
||||
box-shadow: 0 0 0 2px var(--brass), 0 8px 14px rgba(0, 0, 0, .28);
|
||||
transform: translateY(-3px);
|
||||
}
|
||||
|
||||
.shelf-item:focus-visible {
|
||||
outline: 2px solid var(--brass-dark);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
|
||||
.mini-emblem {
|
||||
display: grid;
|
||||
place-items: center;
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
}
|
||||
|
||||
.mini-emblem svg {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
overflow: visible;
|
||||
}
|
||||
|
||||
.mini-label {
|
||||
display: -webkit-box;
|
||||
max-width: 100%;
|
||||
overflow: hidden;
|
||||
-webkit-box-orient: vertical;
|
||||
-webkit-line-clamp: 2;
|
||||
font-family: var(--serif);
|
||||
font-size: clamp(.5rem, 1.15vw, .62rem);
|
||||
font-weight: 700;
|
||||
line-height: 1.1;
|
||||
text-align: center;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.shelf-racks {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.rack {
|
||||
position: relative;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
min-height: 108px;
|
||||
padding: 9px;
|
||||
border: 1px solid #c8b48a;
|
||||
border-radius: 8px;
|
||||
background: rgba(255, 255, 255, .3);
|
||||
color: #4b3a20;
|
||||
font: inherit;
|
||||
text-align: left;
|
||||
cursor: pointer;
|
||||
transition: border-color .15s, background .15s, box-shadow .15s;
|
||||
}
|
||||
|
||||
.rack:hover,
|
||||
.rack.is-targetable {
|
||||
border-color: #8a6a2f;
|
||||
background: #fffaf0;
|
||||
}
|
||||
|
||||
.rack.is-targetable {
|
||||
box-shadow: inset 0 0 0 1px rgba(138, 106, 47, .18);
|
||||
}
|
||||
|
||||
.rack.is-filled {
|
||||
border-color: #8fa47b;
|
||||
background: rgba(232, 240, 217, .58);
|
||||
}
|
||||
|
||||
.rack.is-wrong {
|
||||
border-color: #a34a3d;
|
||||
animation: rack-shake .32s ease;
|
||||
}
|
||||
|
||||
.rack:focus-visible {
|
||||
outline: 2px solid var(--brass-dark);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
|
||||
.rack:disabled {
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
.rack-label {
|
||||
font-size: clamp(.62rem, 1.3vw, .72rem);
|
||||
font-weight: 800;
|
||||
letter-spacing: .08em;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.rack-hint {
|
||||
color: #7a6440;
|
||||
font-size: clamp(.56rem, 1.15vw, .64rem);
|
||||
line-height: 1.3;
|
||||
}
|
||||
|
||||
.rack-slot {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-height: 58px;
|
||||
margin-top: auto;
|
||||
border: 1px dashed rgba(154, 107, 35, .36);
|
||||
border-radius: 6px;
|
||||
background: rgba(255, 255, 255, .22);
|
||||
}
|
||||
|
||||
.rack.is-filled .rack-slot {
|
||||
border-style: solid;
|
||||
border-color: #8fa47b;
|
||||
background: rgba(255, 255, 255, .38);
|
||||
}
|
||||
|
||||
.rack .shelf-item {
|
||||
width: 76px;
|
||||
min-height: 72px;
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
.rack .shelf-item:hover {
|
||||
transform: none;
|
||||
}
|
||||
|
||||
.minigame-retry {
|
||||
align-self: flex-start;
|
||||
margin-bottom: 14px;
|
||||
}
|
||||
|
||||
@keyframes rack-shake {
|
||||
0%, 100% { transform: translateX(0); }
|
||||
30% { transform: translateX(-5px); }
|
||||
62% { transform: translateX(4px); }
|
||||
84% { transform: translateX(-2px); }
|
||||
}
|
||||
|
||||
.feedback {
|
||||
min-height: 2.7em;
|
||||
margin: 0;
|
||||
@@ -1612,6 +1962,35 @@ h1 {
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.memory-grid {
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.memory-label {
|
||||
font-size: .54rem;
|
||||
}
|
||||
|
||||
.shelf-tray {
|
||||
padding: 7px;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.shelf-tray .shelf-item {
|
||||
width: 66px;
|
||||
min-height: 76px;
|
||||
padding: 6px 4px 5px 7px;
|
||||
}
|
||||
|
||||
.rack {
|
||||
min-height: 100px;
|
||||
padding: 7px;
|
||||
}
|
||||
|
||||
.rack .shelf-item {
|
||||
width: 52px;
|
||||
min-height: 66px;
|
||||
}
|
||||
|
||||
.primary-btn {
|
||||
align-self: stretch;
|
||||
text-align: center;
|
||||
@@ -1626,6 +2005,18 @@ h1 {
|
||||
.shelf {
|
||||
gap: 5px;
|
||||
}
|
||||
|
||||
.memory-grid {
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
}
|
||||
|
||||
.memory-label {
|
||||
font-size: .58rem;
|
||||
}
|
||||
|
||||
.rack-hint {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
|
||||
Reference in new issue
Block a user