mirror of
https://github.com/deunix-educ/PyQuest.git
synced 2026-11-25 08:19:44 +01:00
Add guide character (owl) with varied bilingual messages, moods and setting
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
+11
-2
@@ -5,14 +5,17 @@ import { el, renderInline } from './dom.js';
|
||||
export class HintPanel {
|
||||
#i18n;
|
||||
#hints;
|
||||
#onReveal;
|
||||
#revealed = 0;
|
||||
#button;
|
||||
#list;
|
||||
#root;
|
||||
|
||||
/** @param {string[]} hints Indices déjà localisés, du plus vague au plus précis. */
|
||||
constructor(i18n, hints) {
|
||||
/** @param {string[]} hints Indices déjà localisés, du plus vague au plus précis.
|
||||
* @param {{onReveal?: () => void}} [options] Rappel à chaque indice révélé. */
|
||||
constructor(i18n, hints, { onReveal = () => {} } = {}) {
|
||||
this.#i18n = i18n;
|
||||
this.#onReveal = onReveal;
|
||||
this.#hints = hints;
|
||||
this.#button = el('button', { type: 'button', class: 'btn', onclick: () => this.reveal() });
|
||||
this.#list = el('ol', { class: 'hint-list', 'aria-live': 'polite' });
|
||||
@@ -24,6 +27,11 @@ export class HintPanel {
|
||||
return this.#root;
|
||||
}
|
||||
|
||||
/** Reste-t-il au moins un indice à révéler ? */
|
||||
get hasMore() {
|
||||
return this.#revealed < this.#hints.length;
|
||||
}
|
||||
|
||||
/** Affiche l'indice suivant. Renvoie false s'il n'en reste plus. */
|
||||
reveal() {
|
||||
if (this.#revealed >= this.#hints.length) {
|
||||
@@ -32,6 +40,7 @@ export class HintPanel {
|
||||
this.#list.append(el('li', {}, renderInline(this.#hints[this.#revealed])));
|
||||
this.#revealed += 1;
|
||||
this.#refresh();
|
||||
this.#onReveal();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user