feat: indices réservés au mode facile, entrées du carnet barrables d'un trait rouge

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TUSFREC9ggGvmuz9Gw6MRB
This commit is contained in:
Julien Quiaios 2026-10-24 17:12:52 +00:00
parent ecc20f9702
commit e412d4fda7
5 changed files with 76 additions and 3 deletions

View File

@ -54,6 +54,7 @@ export abstract class BaseRenderer implements View {
private uvHaloEl: HTMLElement; private uvHaloEl: HTMLElement;
private notebookBtn: HTMLButtonElement; private notebookBtn: HTMLButtonElement;
private notebookEl: HTMLElement | null = null; private notebookEl: HTMLElement | null = null;
private hintBtn: HTMLButtonElement;
/** Dernier objet obtenu : sa case clignote dans l'inventaire. */ /** Dernier objet obtenu : sa case clignote dans l'inventaire. */
private freshItem: string | null = null; private freshItem: string | null = null;
/** Indice porté par le message affiché (noté via le bouton en mode difficile). */ /** Indice porté par le message affiché (noté via le bouton en mode difficile). */
@ -100,7 +101,7 @@ export abstract class BaseRenderer implements View {
this.notebookBtn = el('button', 'hud-btn notebook-btn', right); this.notebookBtn = el('button', 'hud-btn notebook-btn', right);
this.notebookBtn.title = 'Carnet d’indices (C)'; this.notebookBtn.title = 'Carnet d’indices (C)';
this.notebookBtn.onclick = () => this.toggleNotebook(); this.notebookBtn.onclick = () => this.toggleNotebook();
const hintBtn = el('button', 'hud-btn', right); const hintBtn = (this.hintBtn = el('button', 'hud-btn', right));
hintBtn.innerHTML = '<span>?</span> Indice'; hintBtn.innerHTML = '<span>?</span> Indice';
hintBtn.title = 'Obtenir un indice (H)'; hintBtn.title = 'Obtenir un indice (H)';
hintBtn.onclick = () => engine.nextHint(); hintBtn.onclick = () => engine.nextHint();
@ -179,7 +180,7 @@ export abstract class BaseRenderer implements View {
else this.engine.goBack(); else this.engine.goBack();
} else if ((e.key === 'c' || e.key === 'C') && !this.debug) { } else if ((e.key === 'c' || e.key === 'C') && !this.debug) {
this.toggleNotebook(); this.toggleNotebook();
} else if (e.key === 'h' || e.key === 'H') { } else if ((e.key === 'h' || e.key === 'H') && this.engine.state.difficulty === 'easy') {
this.engine.nextHint(); this.engine.nextHint();
} else if (e.key === 'd' || e.key === 'D') { } else if (e.key === 'd' || e.key === 'D') {
this.debug = !this.debug; this.debug = !this.debug;
@ -203,6 +204,8 @@ export abstract class BaseRenderer implements View {
this.renderInventory(); this.renderInventory();
const n = this.engine.state.notebook.length; const n = this.engine.state.notebook.length;
this.notebookBtn.innerHTML = `Carnet${n ? ` <b>${n}</b>` : ''}`; this.notebookBtn.innerHTML = `Carnet${n ? ` <b>${n}</b>` : ''}`;
// Indices à la demande : mode facile uniquement.
this.hintBtn.style.display = this.engine.state.difficulty === 'easy' ? '' : 'none';
if (this.notebookEl) this.renderNotebook(); if (this.notebookEl) this.renderNotebook();
} }
@ -458,7 +461,47 @@ export abstract class BaseRenderer implements View {
return; return;
} }
const list = el('ol', '', book); const list = el('ol', '', book);
for (const id of ids) el('li', '', list).textContent = this.engine.getClue(id)?.text ?? id; const struck = this.engine.state.struck;
for (const id of ids) {
const li = el('li', 'notebook-entry', list);
li.title = struck.includes(id) ? 'Cliquer pour rétablir' : 'Cliquer pour barrer';
const text = el('span', '', li);
text.textContent = this.engine.getClue(id)?.text ?? id;
li.onclick = () => this.engine.toggleStrike(id);
if (struck.includes(id)) this.drawStrike(li, text, id);
}
}
/** Trait rouge tracé à la main sur chaque ligne du texte (légèrement penché et ondulé, stable d'un rendu à l'autre). */
private drawStrike(li: HTMLElement, text: HTMLElement, seed: string): void {
let h = 2166136261;
for (let i = 0; i < seed.length; i++) h = Math.imul(h ^ seed.charCodeAt(i), 16777619);
const rnd = () => ((h = Math.imul(h ^ (h >>> 15), 2246822507) ^ (h >>> 13)) >>> 0) / 4294967296;
const box = li.getBoundingClientRect();
const NS = 'http://www.w3.org/2000/svg';
const svg = document.createElementNS(NS, 'svg');
svg.setAttribute('class', 'notebook-strike');
svg.setAttribute('width', String(box.width));
svg.setAttribute('height', String(box.height));
for (const r of Array.from(text.getClientRects())) {
const x0 = r.left - box.left - 3 - rnd() * 4;
const x1 = r.right - box.left + 2 + rnd() * 5;
const y = r.top - box.top + r.height * 0.55;
const tilt = (rnd() - 0.5) * 5;
const steps = Math.max(2, Math.round((x1 - x0) / 40));
let d = `M${x0.toFixed(1)},${(y - tilt / 2).toFixed(1)}`;
for (let i = 1; i <= steps; i++) {
const t = i / steps;
const x = x0 + (x1 - x0) * t;
const cy = y - tilt / 2 + tilt * (t - 0.5 / steps) + (rnd() - 0.5) * 3;
d += ` Q${(x - (x1 - x0) / steps / 2).toFixed(1)},${cy.toFixed(1)} ${x.toFixed(1)},${(y - tilt / 2 + tilt * t + (rnd() - 0.5) * 1.2).toFixed(1)}`;
}
const path = document.createElementNS(NS, 'path');
path.setAttribute('d', d);
path.setAttribute('stroke-width', (2 + rnd() * 0.8).toFixed(1));
svg.appendChild(path);
}
li.appendChild(svg);
} }
// --- Puzzles ------------------------------------------------------------------------ // --- Puzzles ------------------------------------------------------------------------

View File

@ -193,7 +193,20 @@ export class Engine {
this.view.refresh(); this.view.refresh();
} }
/** Barre ou rétablit une entrée du carnet. Renvoie l'état barré, ou null si l'entrée n'existe pas. */
toggleStrike(entry: string): boolean | null {
if (!this.state.notebook.includes(entry)) return null;
const i = this.state.struck.indexOf(entry);
if (i >= 0) this.state.struck.splice(i, 1);
else this.state.struck.push(entry);
saveState(this.state);
this.view.refresh();
return i < 0;
}
/** Indices à la demande : mode facile uniquement. */
nextHint(): void { nextHint(): void {
if (this.state.difficulty !== 'easy') return;
const idx = this.scenario.hints.findIndex((g) => checkAll(this.state, g.when)); const idx = this.scenario.hints.findIndex((g) => checkAll(this.state, g.when));
if (idx < 0) { if (idx < 0) {
this.view.showMessage('Pas d’indice pour le moment.', 'hint'); this.view.showMessage('Pas d’indice pour le moment.', 'hint');

View File

@ -21,6 +21,8 @@ export interface GameState {
difficulty: Difficulty; difficulty: Difficulty;
/** Indices notés dans le carnet (identifiants, dans l'ordre). */ /** Indices notés dans le carnet (identifiants, dans l'ordre). */
notebook: string[]; notebook: string[];
/** Entrées du carnet barrées par le joueur. */
struck: string[];
} }
export function newState(scenarioId: string, startScene: string, difficulty: Difficulty = 'easy'): GameState { export function newState(scenarioId: string, startScene: string, difficulty: Difficulty = 'easy'): GameState {
@ -29,6 +31,7 @@ export function newState(scenarioId: string, startScene: string, difficulty: Dif
vars: {}, vars: {},
fired: {}, fired: {},
notebook: [], notebook: [],
struck: [],
difficulty, difficulty,
scene: startScene, scene: startScene,
flags: {}, flags: {},

View File

@ -307,6 +307,10 @@ button.primary:hover { background: #dbb55c; }
} }
.notebook h3 { margin: 0 0 8px; font-family: var(--serif); font-size: 24px; color: #3a2a1a; } .notebook h3 { margin: 0 0 8px; font-family: var(--serif); font-size: 24px; color: #3a2a1a; }
.notebook ol { margin: 0; padding-left: 18px; line-height: 32px; font-size: 16px; } .notebook ol { margin: 0; padding-left: 18px; line-height: 32px; font-size: 16px; }
.notebook-entry { position: relative; cursor: pointer; }
.notebook-entry:hover > span { color: #4a3a6a; }
.notebook-strike { position: absolute; left: 0; top: 0; overflow: visible; pointer-events: none; }
.notebook-strike path { fill: none; stroke: #c0281e; stroke-linecap: round; opacity: .85; }
.notebook-empty { font-family: var(--serif); font-style: italic; color: #6a5a4a; line-height: 1.6; } .notebook-empty { font-family: var(--serif); font-style: italic; color: #6a5a4a; line-height: 1.6; }
.notebook .puzzle-close { top: 10px; right: 10px; color: var(--text); } .notebook .puzzle-close { top: 10px; right: 10px; color: var(--text); }

View File

@ -131,6 +131,16 @@ describe('moteur', () => {
expect(state.notebook).toEqual(['un message']); expect(state.notebook).toEqual(['un message']);
}); });
it('carnet : barrer puis rétablir une entrée', () => {
const { engine, state } = makeEngine();
engine.noteText('note');
expect(engine.toggleStrike('note')).toBe(true);
expect(state.struck).toEqual(['note']);
expect(engine.toggleStrike('note')).toBe(false);
expect(state.struck).toEqual([]);
expect(engine.toggleStrike('absente')).toBe(null);
});
it('objet inutilisable en l\'état : son propre message', () => { it('objet inutilisable en l\'état : son propre message', () => {
const { engine, state, hs, messages } = makeEngine({ items: [{ id: 'x', name: 'X', icon: '', unusable: 'éteint' }] }); const { engine, state, hs, messages } = makeEngine({ items: [{ id: 'x', name: 'X', icon: '', unusable: 'éteint' }] });
state.inventory = ['x']; state.inventory = ['x'];