mirror of
https://github.com/db9979/wibosim.git
synced 2026-12-06 21:44:09 +01:00
- Klassenkollision .book (Handbuch) vs. Orderbuch-Tabelle behoben: kein seitlicher Überlauf mehr - Kursliste schmaler gesetzt, damit die Änderungsspalte auch mit Safari-Schriften passt - Hilfe-Knopf im Aktienkopf fest oben rechts - Admin: Klicks in Einstellungsfelder (data-sec) wurden als Menüwechsel gewertet und leerten die Seite Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018i4GUhQVoPUusUzxgxLWkK
179 lines
12 KiB
JavaScript
179 lines
12 KiB
JavaScript
// Hilfe: „?“-Knopf an jeder Kartenüberschrift, ausführliche Begriffserklärungen (Klick/Tippen auf unterstrichene
|
||
// Begriffe), Handbuch-Ansicht mit Suche und Glossar A–Z sowie „Neu für dich“-Hinweise beim ersten Kontakt.
|
||
import { GLOSSARY, openModal, toast } from './ui.js';
|
||
import { esc, $, store } from './util.js';
|
||
import { CARD_HELP, TERMS, MANUAL } from './helptext.js';
|
||
|
||
// Kurztexte neuer Begriffe ins Tooltip-Glossar übernehmen
|
||
for (const [k, v] of Object.entries(TERMS)) if (v.short && !GLOSSARY[k]) GLOSSARY[k] = v.short;
|
||
|
||
let goView = () => {};
|
||
const termBtn = (t) => `<button type="button" class="chip term-chip" data-term="${esc(t)}">${esc(t)}</button>`;
|
||
|
||
// ---------------------------------------------------------------- Karten-Hilfe
|
||
export function openHelp(key) {
|
||
const h = CARD_HELP[key];
|
||
if (!h) return;
|
||
const ch = MANUAL.find((c) => c.id === h.chapter);
|
||
const { el, close } = openModal(`
|
||
<h2><span class="help-ic" aria-hidden="true">?</span> ${esc(h.title)}</h2>
|
||
<section class="help-sec"><h3>Worum geht's?</h3><p>${esc(h.what)}</p></section>
|
||
<section class="help-sec"><h3>So funktioniert's</h3><ol>${h.how.map((x) => `<li>${esc(x)}</li>`).join('')}</ol></section>
|
||
<section class="help-sec effect"><h3>Wirkung im Spiel</h3><p>${esc(h.effect)}</p></section>
|
||
<section class="help-sec tip"><h3>💡 Tipp</h3><p>${esc(h.tip)}</p></section>
|
||
${h.terms?.length ? `<section class="help-sec"><h3>Begriffe</h3><div class="chips">${h.terms.filter((t) => GLOSSARY[t] || TERMS[t]).map(termBtn).join('')}</div></section>` : ''}
|
||
<div class="dlg-actions">${ch ? `<button type="button" class="btn ghost" data-r="book">📖 Handbuch: ${esc(ch.title)}</button>` : ''}<button type="button" class="btn" data-r="ok">Verstanden</button></div>`,
|
||
{ label: `Hilfe: ${h.title}`, cls: 'help-modal' });
|
||
el.querySelector('[data-r="ok"]').addEventListener('click', () => close());
|
||
el.querySelector('[data-r="book"]')?.addEventListener('click', () => { close(); openBook(h.chapter); });
|
||
}
|
||
|
||
// ---------------------------------------------------------------- Begriff ausführlich
|
||
export function openTerm(term) {
|
||
const short = GLOSSARY[term];
|
||
const t = TERMS[term];
|
||
if (!short && !t) return;
|
||
const { el, close } = openModal(`
|
||
<h2>📘 ${esc(term)}</h2>
|
||
<p class="help-lead">${esc(t?.long ?? short.replace(/^[^:]+:\s*/, ''))}</p>
|
||
${t?.example && t.example !== '–' ? `<section class="help-sec example"><h3>Beispiel</h3><p>${esc(t.example)}</p></section>` : ''}
|
||
${t?.effect ? `<section class="help-sec effect"><h3>Wirkung im Spiel</h3><p>${esc(t.effect)}</p></section>` : ''}
|
||
${t?.see?.length ? `<section class="help-sec"><h3>Siehe auch</h3><div class="chips">${t.see.filter((x) => GLOSSARY[x] || TERMS[x]).map(termBtn).join('')}</div></section>` : ''}
|
||
<div class="dlg-actions"><button type="button" class="btn ghost" data-r="all">📖 Alle Begriffe</button><button type="button" class="btn" data-r="ok">Schließen</button></div>`,
|
||
{ label: `Begriff: ${term}`, cls: 'help-modal' });
|
||
el.querySelector('[data-r="ok"]').addEventListener('click', () => close());
|
||
el.querySelector('[data-r="all"]').addEventListener('click', () => { close(); openBook('glossar'); });
|
||
}
|
||
|
||
// ---------------------------------------------------------------- „?“ an Kartenüberschriften einsetzen
|
||
const MATCHERS = Object.entries(CARD_HELP).flatMap(([key, h]) => h.match.map((m) => [m, key])).sort((a, b) => b[0].length - a[0].length);
|
||
const LETTER = /[A-Za-zÄÖÜäöüß-]/;
|
||
function keyFor(h2) {
|
||
const text = (h2.textContent ?? '').replace(/\s+/g, ' ').trim();
|
||
for (const [m, key] of MATCHERS) if (text.startsWith(m) && !LETTER.test(text.charAt(m.length))) return key;
|
||
return null;
|
||
}
|
||
function decorate() {
|
||
for (const h2 of document.querySelectorAll('h2.card-h:not([data-hq]), h2.h4:not([data-hq])')) {
|
||
h2.dataset.hq = '1';
|
||
if (h2.closest('.modal')) continue;
|
||
const key = keyFor(h2);
|
||
if (!key) continue;
|
||
const b = document.createElement('button');
|
||
b.type = 'button';
|
||
b.className = 'help-q';
|
||
b.dataset.help = key;
|
||
b.setAttribute('aria-label', `Hilfe: ${CARD_HELP[key].title}`);
|
||
b.title = `Hilfe: ${CARD_HELP[key].title}`;
|
||
b.textContent = '?';
|
||
const first = h2.firstChild;
|
||
h2.insertBefore(b, first ? first.nextSibling : null);
|
||
}
|
||
}
|
||
let queued = false;
|
||
const schedule = () => { if (!queued) { queued = true; requestAnimationFrame(() => { queued = false; decorate(); }); } };
|
||
|
||
// ---------------------------------------------------------------- Handbuch
|
||
let bookChapter = 'start';
|
||
let bookQuery = '';
|
||
export function openBook(chapter = 'start') { bookChapter = chapter; goView('hilfe'); }
|
||
|
||
const strip = (h) => h.replace(/<[^>]*>/g, '');
|
||
function chainHtml(chain) {
|
||
return `<figure class="chain" aria-label="Wirkungskette"><ol>${chain.map((c, i) => `<li><b>${esc(c.t)}</b><span>${esc(c.d)}</span></li>${i < chain.length - 1 ? '<li class="arrow" aria-hidden="true">→</li>' : ''}`).join('')}</ol><figcaption class="muted small">Wirkungskette</figcaption></figure>`;
|
||
}
|
||
function allTerms() {
|
||
return [...new Set([...Object.keys(GLOSSARY), ...Object.keys(TERMS)])].sort((a, b) => a.localeCompare(b, 'de'));
|
||
}
|
||
function termText(k) { return TERMS[k]?.short ?? GLOSSARY[k] ?? ''; }
|
||
|
||
export function renderHandbook() {
|
||
const el = $('#v-hilfe');
|
||
if (!el) return;
|
||
const q = bookQuery.trim().toLowerCase();
|
||
const toc = [...MANUAL.map((c) => [c.id, `${c.icon} ${c.title}`]), ['glossar', '🔤 Begriffe A–Z']];
|
||
let main;
|
||
if (q) {
|
||
const hitsC = MANUAL.filter((c) => (`${c.title} ${c.body.map(strip).join(' ')}`).toLowerCase().includes(q));
|
||
const hitsT = allTerms().filter((k) => (`${k} ${termText(k)} ${TERMS[k]?.long ?? ''}`).toLowerCase().includes(q));
|
||
main = `<h2>Suche: „${esc(bookQuery)}“</h2>
|
||
${hitsC.length ? `<h3 class="h4">Kapitel</h3><ul class="plain">${hitsC.map((c) => `<li><button type="button" class="linkish" data-book="${c.id}">${c.icon} ${esc(c.title)}</button></li>`).join('')}</ul>` : ''}
|
||
${hitsT.length ? `<h3 class="h4">Begriffe</h3><dl class="gloss">${hitsT.map((k) => `<div><dt><button type="button" class="linkish" data-term="${esc(k)}">${esc(k)}</button></dt><dd>${esc(termText(k).replace(/^[^:]+:\s*/, ''))}</dd></div>`).join('')}</dl>` : ''}
|
||
${!hitsC.length && !hitsT.length ? '<p class="muted">Nichts gefunden – versuche einen anderen Begriff.</p>' : ''}`;
|
||
} else if (bookChapter === 'glossar') {
|
||
const terms = allTerms();
|
||
const letters = [...new Set(terms.map((k) => k[0].toUpperCase()))];
|
||
main = `<h2>🔤 Begriffe A–Z</h2><p class="muted">Ein Klick auf einen Begriff öffnet die ausführliche Erklärung mit Beispiel und Wirkung im Spiel.</p>
|
||
<nav class="az" aria-label="Buchstaben">${letters.map((l) => `<a href="#gl-${esc(l)}">${esc(l)}</a>`).join('')}</nav>
|
||
${letters.map((l) => `<h3 class="h4" id="gl-${esc(l)}">${esc(l)}</h3><dl class="gloss">${terms.filter((k) => k[0].toUpperCase() === l).map((k) => `<div><dt><button type="button" class="linkish" data-term="${esc(k)}">${esc(k)}</button></dt><dd>${esc(termText(k).replace(/^[^:]+:\s*/, ''))}</dd></div>`).join('')}</dl>`).join('')}`;
|
||
} else {
|
||
const c = MANUAL.find((x) => x.id === bookChapter) ?? MANUAL[0];
|
||
const i = MANUAL.indexOf(c);
|
||
const helps = Object.entries(CARD_HELP).filter(([, h]) => h.chapter === c.id);
|
||
main = `<h2>${c.icon} ${esc(c.title)}</h2>
|
||
${c.body.map((p) => `<p>${p}</p>`).join('')}
|
||
${c.chain ? chainHtml(c.chain) : ''}
|
||
${helps.length ? `<h3 class="h4">Bereiche im Spiel</h3><div class="chips">${helps.map(([k, h]) => `<button type="button" class="chip" data-help="${k}">? ${esc(h.title)}</button>`).join('')}</div>` : ''}
|
||
<div class="book-nav">${i > 0 ? `<button type="button" class="btn ghost small" data-book="${MANUAL[i - 1].id}">← ${esc(MANUAL[i - 1].title)}</button>` : '<span></span>'}
|
||
${i < MANUAL.length - 1 ? `<button type="button" class="btn ghost small" data-book="${MANUAL[i + 1].id}">${esc(MANUAL[i + 1].title)} →</button>` : `<button type="button" class="btn ghost small" data-book="glossar">Begriffe A–Z →</button>`}</div>`;
|
||
}
|
||
const had = document.activeElement?.id === 'bookSearch';
|
||
el.innerHTML = `<div class="page hbook">
|
||
<aside class="card book-toc"><div class="body">
|
||
<label class="sr" for="bookSearch">Im Handbuch suchen</label>
|
||
<input id="bookSearch" type="search" placeholder="Suchen, z. B. Leerverkauf" value="${esc(bookQuery)}" autocomplete="off">
|
||
<nav aria-label="Kapitel"><ul class="plain">${toc.map(([id, t]) => `<li><button type="button" class="toc-item" data-book="${id}" ${!q && id === bookChapter ? 'aria-current="page"' : ''}>${esc(t)}</button></li>`).join('')}</ul></nav>
|
||
<p class="muted small">Etwas unklar oder kaputt? <button type="button" class="linkish" data-act="bug">🐞 Melden</button></p>
|
||
</div></aside>
|
||
<article class="card book-main"><div class="body">${main}</div></article></div>`;
|
||
if (had) { const s = $('#bookSearch'); s.focus(); s.setSelectionRange(s.value.length, s.value.length); }
|
||
}
|
||
export const showHandbook = () => renderHandbook();
|
||
|
||
// ---------------------------------------------------------------- „Neu für dich“ beim ersten Kontakt
|
||
const SEEN_KEY = 'helpSeen';
|
||
const seen = new Set((() => { const v = store.get(SEEN_KEY, []); return Array.isArray(v) ? v : []; })());
|
||
/** Einmaliger Hinweis zu einer Funktion (key = Hilfe-Schlüssel oder Begriff) */
|
||
export function firstTime(id, title, text, { help, term } = {}) {
|
||
if (seen.has(id) || document.querySelector('.tour')) return;
|
||
seen.add(id);
|
||
store.set(SEEN_KEY, [...seen]);
|
||
const btn = help ? `<button type="button" class="linkish" data-help="${esc(help)}">Mehr erfahren</button>` : term ? `<button type="button" class="linkish" data-term="${esc(term)}">Mehr erfahren</button>` : '';
|
||
toast(`${esc(text)} ${btn}`, 'gold', { title: `Neu für dich: ${title}`, html: true, ms: 12_000 });
|
||
}
|
||
|
||
/** Erstkontakt-Hinweise beim Öffnen einer Ansicht */
|
||
export function hintsForView(view, S) {
|
||
if (!S?.profile) return;
|
||
if (view === 'termine') {
|
||
if (S.agm?.open?.length) firstTime('agm', 'Hauptversammlungen', 'Als Aktionär stimmst du über Dividende, Rückkauf, Kapitalerhöhung und Vergütung ab – geschlossene Spieler können die Fonds überstimmen.', { help: 'hv' });
|
||
else if (S.predict?.open?.length) firstTime('tip', 'Tippspiel', 'Tippe am Abend auf den nächsten Handelstag – richtige Tipps bringen Punkte, Serienbonus und XP.', { help: 'tipp' });
|
||
else if (S.ipo?.pending?.length) firstTime('ipo', 'Börsengänge', 'Zeichne Aktien eines neuen Unternehmens zum Ausgabepreis – bei Überzeichnung wird anteilig zugeteilt.', { help: 'ipo' });
|
||
else firstTime('plan', 'Dein Plan', 'Hier bereitest du den nächsten Handelstag vor: Orders, Kursalarme, Watchlist und Termine.', { help: 'plan' });
|
||
} else if (view === 'parlament') firstTime('politik', 'Politik', 'Gesetze verändern Gewinne ganzer Branchen. Der Markt preist die Wahrscheinlichkeit schon während der Abstimmung ein – deine Stimme zählt mit.', { help: 'abstimmung' });
|
||
else if (view === 'battles') firstTime('battle', 'Battles', 'Duelle in einem eigenen Depot mit 50.000 € – dein Hauptdepot bleibt unberührt.', { help: 'schnellBattle' });
|
||
else if (view === 'clans') firstTime('clans', 'Clans', 'Gemeinsam spielen: Clan-Fonds, Pinnwand und ein Wochenziel mit XP für alle.', { help: 'clans' });
|
||
}
|
||
|
||
export function initHelp(go) {
|
||
goView = go;
|
||
decorate();
|
||
new MutationObserver(schedule).observe(document.body, { childList: true, subtree: true });
|
||
document.addEventListener('click', (e) => {
|
||
const h = e.target.closest('[data-help]');
|
||
if (h) { e.preventDefault(); e.stopPropagation(); openHelp(h.dataset.help); return; }
|
||
const t = e.target.closest('[data-term]');
|
||
if (t) { e.preventDefault(); openTerm(t.dataset.term); return; }
|
||
const b = e.target.closest('[data-book]');
|
||
if (b) { bookChapter = b.dataset.book; bookQuery = ''; renderHandbook(); window.scrollTo({ top: 0 }); return; }
|
||
// unterstrichene Begriffe: Klick/Tippen öffnet die ausführliche Erklärung (nicht innerhalb von Knöpfen/Links)
|
||
const g = e.target.closest('[data-gl]');
|
||
if (g && !g.closest('button, a, .modal, tr[data-sym], label')) { openTerm(g.dataset.gl); }
|
||
}, true);
|
||
document.addEventListener('keydown', (e) => {
|
||
const g = e.target.closest?.('[data-gl]');
|
||
if (g && (e.key === 'Enter' || e.key === ' ') && !g.closest('button, a')) { e.preventDefault(); openTerm(g.dataset.gl); }
|
||
});
|
||
document.addEventListener('input', (e) => { if (e.target.id === 'bookSearch') { bookQuery = e.target.value; renderHandbook(); } });
|
||
}
|