Spaces:
Sleeping
Sleeping
Download docs/app/index.html from FC-Bit/arkanum: direct link, hf CLI and curl.
- Browser
- Download file 45.6 kB
-
https://huggingface.co/spaces/FC-Bit/arkanum/resolve/main/docs/app/index.html
- Command line
-
hf download hf://spaces/FC-Bit/arkanum/docs/app/index.html
-
curl -L -o index.html https://huggingface.co/spaces/FC-Bit/arkanum/resolve/main/docs/app/index.html
45.6 kB
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="mobile-web-app-capable" content="yes">
<title>Arkanum – Regelexperte</title>
<link rel="manifest" href="manifest.json">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<meta name="theme-color" content="#1a1a2e">
<style>
:root {
--bg: #1a1a2e;
--surface: #16213e;
--primary: #e94560;
--accent: #f5a623;
--text: #eee;
--text-muted: #999;
--border: #333;
--success: #4caf50;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
background: var(--bg);
color: var(--text);
min-height: 100dvh;
display: flex;
flex-direction: column;
}
header {
background: var(--surface);
padding: 1rem;
text-align: center;
border-bottom: 2px solid var(--primary);
}
header h1 {
font-size: 1.4rem;
letter-spacing: 2px;
}
header h1 span { color: var(--primary); }
header p {
font-size: 0.8rem;
color: var(--text-muted);
margin-top: 0.25rem;
}
/* Mode Toggle */
.mode-toggle {
display: flex;
justify-content: center;
gap: 0;
margin-top: 0.5rem;
}
.mode-toggle button {
background: transparent;
border: 1px solid var(--border);
color: var(--text-muted);
padding: 0.3rem 1rem;
font-size: 0.75rem;
cursor: pointer;
transition: all 0.2s;
}
.mode-toggle button:first-child { border-radius: 6px 0 0 6px; }
.mode-toggle button:last-child { border-radius: 0 6px 6px 0; }
.mode-toggle button.active {
background: var(--primary);
border-color: var(--primary);
color: white;
}
main {
flex: 1;
padding: 1rem;
max-width: 700px;
width: 100%;
margin: 0 auto;
display: flex;
flex-direction: column;
gap: 1rem;
}
/* ---- Chat Mode ---- */
.chat-area {
flex: 1;
overflow-y: auto;
display: flex;
flex-direction: column;
gap: 0.75rem;
padding-bottom: 1rem;
}
.message {
padding: 0.75rem 1rem;
border-radius: 12px;
max-width: 90%;
line-height: 1.5;
font-size: 0.95rem;
}
.message.user {
background: var(--primary);
align-self: flex-end;
border-bottom-right-radius: 4px;
}
.message.assistant {
background: var(--surface);
align-self: flex-start;
border-bottom-left-radius: 4px;
border: 1px solid var(--border);
}
.message.assistant h2 { font-size: 1rem; color: var(--accent); margin: 0.5rem 0 0.25rem; }
.message.assistant h2:first-child { margin-top: 0; }
.message.assistant p { margin: 0.25rem 0; }
.message.assistant ul, .message.assistant ol { margin: 0.25rem 0 0.25rem 1.25rem; }
.message.assistant strong { color: var(--accent); }
.message .image-preview {
max-width: 200px;
max-height: 150px;
border-radius: 8px;
margin-bottom: 0.5rem;
display: block;
}
.message .sources {
margin-top: 0.5rem;
padding-top: 0.5rem;
border-top: 1px solid var(--border);
font-size: 0.8rem;
color: var(--text-muted);
}
.message .situation {
font-style: italic;
color: var(--text-muted);
margin-bottom: 0.5rem;
font-size: 0.85rem;
}
.input-area {
background: var(--surface);
border-radius: 16px;
padding: 0.75rem;
border: 1px solid var(--border);
}
.image-preview-bar {
display: none;
align-items: center;
gap: 0.5rem;
margin-bottom: 0.5rem;
padding-bottom: 0.5rem;
border-bottom: 1px solid var(--border);
}
.image-preview-bar.active { display: flex; }
.image-preview-bar img {
width: 48px;
height: 48px;
object-fit: cover;
border-radius: 8px;
}
.image-preview-bar .remove {
background: none;
border: none;
color: var(--primary);
font-size: 1.2rem;
cursor: pointer;
margin-left: auto;
}
.input-row {
display: flex;
gap: 0.5rem;
align-items: flex-end;
}
.input-row textarea {
flex: 1;
background: transparent;
border: none;
color: var(--text);
font-size: 1rem;
font-family: inherit;
resize: none;
outline: none;
max-height: 120px;
line-height: 1.4;
}
.btn {
width: 44px;
height: 44px;
border-radius: 50%;
border: none;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
font-size: 1.2rem;
}
.btn-camera {
background: var(--surface);
border: 1px solid var(--border);
color: var(--text);
}
.btn-send {
background: var(--primary);
color: white;
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.loading {
display: inline-flex;
gap: 4px;
padding: 0.5rem 0;
}
.loading span {
width: 8px;
height: 8px;
background: var(--accent);
border-radius: 50%;
animation: bounce 1.2s infinite ease-in-out;
}
.loading span:nth-child(2) { animation-delay: 0.2s; }
.loading span:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce {
0%, 80%, 100% { transform: scale(0); }
40% { transform: scale(1); }
}
.welcome {
text-align: center;
color: var(--text-muted);
margin-top: 2rem;
}
.welcome h2 { color: var(--accent); font-size: 1.1rem; margin-bottom: 0.5rem; }
.examples {
display: flex;
flex-direction: column;
gap: 0.5rem;
margin-top: 1rem;
}
.example-btn {
background: var(--surface);
border: 1px solid var(--border);
color: var(--text);
padding: 0.6rem 1rem;
border-radius: 10px;
cursor: pointer;
font-size: 0.85rem;
text-align: left;
}
.example-btn:hover { border-color: var(--primary); }
input[type="file"] { display: none; }
/* Login Screen */
.login-overlay {
position: fixed;
inset: 0;
background: var(--bg);
display: flex;
align-items: center;
justify-content: center;
z-index: 100;
}
.login-overlay.hidden { display: none; }
.login-box {
background: var(--surface);
border: 1px solid var(--border);
border-radius: 16px;
padding: 2rem;
text-align: center;
max-width: 320px;
width: 90%;
}
.login-box h2 { color: var(--primary); font-size: 1.4rem; letter-spacing: 2px; margin-bottom: 0.5rem; }
.login-box p { color: var(--text-muted); font-size: 0.85rem; margin-bottom: 1.5rem; }
.login-box input {
width: 100%;
padding: 0.75rem 1rem;
background: var(--bg);
border: 1px solid var(--border);
border-radius: 10px;
color: var(--text);
font-size: 1rem;
outline: none;
margin-bottom: 1rem;
}
.login-box input:focus { border-color: var(--primary); }
.login-box button {
width: 100%;
padding: 0.75rem;
background: var(--primary);
color: white;
border: none;
border-radius: 10px;
font-size: 1rem;
cursor: pointer;
}
.login-error {
color: var(--primary);
font-size: 0.85rem;
margin-top: 0.5rem;
display: none;
}
/* ---- Voice Guide Mode ---- */
.voice-guide { display: none; flex-direction: column; flex: 1; gap: 1rem; }
.voice-guide.active { display: flex; }
.chat-mode.hidden { display: none; }
/* Mode Selection */
.mode-select {
display: flex;
flex-direction: column;
align-items: center;
gap: 1rem;
margin-top: 2rem;
text-align: center;
}
.mode-select h2 { color: var(--accent); font-size: 1.1rem; }
.mode-select p { color: var(--text-muted); font-size: 0.85rem; }
.mode-select-buttons {
display: flex;
gap: 0.75rem;
flex-wrap: wrap;
justify-content: center;
}
.mode-select-btn {
background: var(--surface);
border: 2px solid var(--border);
color: var(--text);
padding: 1rem 1.5rem;
border-radius: 12px;
cursor: pointer;
font-size: 0.95rem;
min-width: 160px;
transition: border-color 0.2s;
}
.mode-select-btn:hover { border-color: var(--primary); }
.mode-select-btn strong { display: block; color: var(--accent); margin-bottom: 0.25rem; }
.mode-select-btn span { font-size: 0.8rem; color: var(--text-muted); }
/* Progress Bar */
.vg-progress {
background: var(--surface);
border-radius: 12px;
padding: 0.75rem 1rem;
border: 1px solid var(--border);
}
.vg-progress-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 0.5rem;
}
.vg-progress-title {
font-size: 0.85rem;
color: var(--accent);
font-weight: 600;
}
.vg-progress-count {
font-size: 0.75rem;
color: var(--text-muted);
}
.vg-progress-bar {
height: 4px;
background: var(--border);
border-radius: 2px;
overflow: hidden;
}
.vg-progress-fill {
height: 100%;
background: var(--accent);
border-radius: 2px;
transition: width 0.3s ease;
}
.vg-phase-dots {
display: flex;
gap: 0.5rem;
margin-top: 0.5rem;
justify-content: center;
}
.vg-phase-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--border);
transition: background 0.2s;
}
.vg-phase-dot.done { background: var(--success); }
.vg-phase-dot.current { background: var(--accent); }
/* Step Card */
.vg-step-card {
background: var(--surface);
border: 1px solid var(--border);
border-radius: 16px;
padding: 1.25rem;
flex: 1;
overflow-y: auto;
line-height: 1.6;
font-size: 0.95rem;
}
.vg-step-card .vg-step-text { white-space: pre-wrap; }
.vg-step-card .sources {
margin-top: 0.75rem;
padding-top: 0.5rem;
border-top: 1px solid var(--border);
font-size: 0.8rem;
color: var(--text-muted);
}
/* Voice Controls */
.vg-controls {
display: flex;
gap: 0.5rem;
align-items: center;
justify-content: center;
flex-wrap: wrap;
}
.vg-btn {
padding: 0.6rem 1.2rem;
border-radius: 10px;
border: 1px solid var(--border);
background: var(--surface);
color: var(--text);
font-size: 0.9rem;
cursor: pointer;
display: flex;
align-items: center;
gap: 0.4rem;
transition: all 0.2s;
}
.vg-btn:hover { border-color: var(--primary); }
.vg-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.vg-btn.primary {
background: var(--primary);
border-color: var(--primary);
color: white;
}
.vg-btn.primary:hover { background: #d63a52; }
.vg-btn-mic {
width: 56px;
height: 56px;
border-radius: 50%;
font-size: 1.4rem;
padding: 0;
justify-content: center;
}
.vg-btn-mic.listening {
background: var(--primary);
border-color: var(--primary);
animation: pulse 1.5s infinite;
}
@keyframes pulse {
0%, 100% { box-shadow: 0 0 0 0 rgba(233, 69, 96, 0.4); }
50% { box-shadow: 0 0 0 12px rgba(233, 69, 96, 0); }
}
.vg-status {
text-align: center;
font-size: 0.8rem;
color: var(--text-muted);
min-height: 1.2rem;
}
/* Voice Guide Input (for typed questions during walkthrough) */
.vg-input-area {
background: var(--surface);
border-radius: 12px;
padding: 0.5rem;
border: 1px solid var(--border);
display: none;
}
.vg-input-area.active { display: block; }
.vg-input-row {
display: flex;
gap: 0.5rem;
align-items: center;
}
.vg-input-row input {
flex: 1;
background: transparent;
border: none;
color: var(--text);
font-size: 0.9rem;
outline: none;
padding: 0.4rem;
}
.vg-exit-btn {
position: absolute;
top: 0.5rem;
right: 0.5rem;
background: none;
border: none;
color: var(--text-muted);
font-size: 0.8rem;
cursor: pointer;
}
</style>
</head>
<body>
<!-- Login Screen -->
<div class="login-overlay" id="loginOverlay">
<div class="login-box">
<h2>ARKANUM</h2>
<p>Passwort eingeben um fortzufahren</p>
<input type="password" id="passwordInput" placeholder="Passwort"
onkeydown="if(event.key==='Enter') login()">
<button onclick="login()">Eintreten</button>
<div class="login-error" id="loginError">Falsches Passwort</div>
</div>
</div>
<header>
<h1><span>ARKANUM</span></h1>
<p>S.T.A.L.K.E.R. The Board Game – Regelexperte</p>
<div class="mode-toggle">
<button class="active" id="btnModeChat" onclick="switchMode('chat')">Chat</button>
<button id="btnModeVoice" onclick="switchMode('voice')">Voice Guide</button>
</div>
</header>
<main>
<!-- Chat Mode -->
<div class="chat-mode" id="chatMode">
<div class="chat-area" id="chatArea">
<div class="welcome">
<h2>Willkommen, Stalker.</h2>
<p>Stell eine Regelfrage oder fotografiere eine Karte/Spielsituation.</p>
<div class="examples">
<button class="example-btn" onclick="askExample(this)">Wie funktioniert Aufmerksamkeit (Attention)?</button>
<button class="example-btn" onclick="askExample(this)">Wie viele Aktionen hat ein Stalker pro Zug?</button>
<button class="example-btn" onclick="askExample(this)">Was passiert bei einer Emission?</button>
</div>
</div>
</div>
<div class="input-area">
<div class="image-preview-bar" id="imagePreview">
<img id="previewImg" src="" alt="Preview">
<span id="previewName">bild.jpg</span>
<button class="remove" onclick="removeImage()">×</button>
</div>
<div class="input-row">
<button class="btn btn-camera" onclick="captureImage()" title="Foto aufnehmen">
📷
</button>
<textarea id="questionInput" rows="1" placeholder="Regelfrage eingeben..."
onkeydown="handleKey(event)" oninput="autoGrow(this)"></textarea>
<button class="btn btn-send" id="sendBtn" onclick="send()" title="Absenden">
➤
</button>
</div>
</div>
</div>
<!-- Voice Guide Mode -->
<div class="voice-guide" id="voiceGuide">
<!-- Step 1: Mode selection -->
<div id="vgModeSelect" class="mode-select">
<h2>Voice Guide starten</h2>
<p>Welchen Modus wollt ihr spielen?</p>
<div class="mode-select-buttons">
<button class="mode-select-btn" onclick="vgStart('campaign')">
<strong>Campaign</strong>
<span>Vollständige Kampagne mit Story-Missionen</span>
</button>
<button class="mode-select-btn" onclick="vgStart('zone_survival')">
<strong>Zone Survival</strong>
<span>Einzelne Session, schnellerer Einstieg</span>
</button>
</div>
</div>
<!-- Step 2: Active walkthrough -->
<div id="vgActive" style="display:none; flex-direction:column; flex:1; gap:0.75rem;">
<!-- Progress -->
<div class="vg-progress">
<div class="vg-progress-header">
<span class="vg-progress-title" id="vgPhaseTitle">Spielübersicht</span>
<span class="vg-progress-count" id="vgStepCount">Schritt 1/2</span>
</div>
<div class="vg-progress-bar">
<div class="vg-progress-fill" id="vgProgressFill" style="width: 0%"></div>
</div>
<div class="vg-phase-dots" id="vgPhaseDots"></div>
</div>
<!-- Step Content -->
<div class="vg-step-card" id="vgStepCard">
<div class="loading"><span></span><span></span><span></span></div>
</div>
<!-- Status -->
<div class="vg-status" id="vgStatus"></div>
<!-- Controls -->
<div class="vg-controls">
<button class="vg-btn" id="vgBtnBack" onclick="vgBack()" disabled>Zurück</button>
<button class="vg-btn" id="vgBtnReplay" onclick="vgReplay()">Nochmal</button>
<button class="vg-btn vg-btn-mic" id="vgBtnMic" onclick="vgToggleMic()">🎤</button>
<button class="vg-btn primary" id="vgBtnNext" onclick="vgNext()">Weiter</button>
<button class="vg-btn" id="vgBtnStop" onclick="vgStop()">Beenden</button>
</div>
<!-- Typed question input -->
<div class="vg-input-area" id="vgInputArea">
<div class="vg-input-row">
<input type="text" id="vgQuestionInput" placeholder="Regelfrage eingeben..."
onkeydown="if(event.key==='Enter') vgAskQuestion()">
<button class="btn btn-send" style="width:36px;height:36px;font-size:1rem;" onclick="vgAskQuestion()">➤</button>
</div>
</div>
</div>
</div>
</main>
<input type="file" id="imageInput" accept="image/*" capture="environment" onchange="handleImage(event)">
<script>
// ===================== SHARED =====================
const API_BASE = window.location.hostname.includes('github.io')
? 'https://FC-Bit-arkanum.hf.space'
: window.location.origin;
let selectedImage = null;
let selectedImageType = 'image/jpeg';
function getPassword() { return localStorage.getItem('arkanum_pw') || ''; }
function setPassword(pw) { localStorage.setItem('arkanum_pw', pw); }
async function login() {
const pw = document.getElementById('passwordInput').value;
try {
const resp = await fetch(`${API_BASE}/api/ask`, {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'X-Password': pw },
body: JSON.stringify({ question: 'test', game: 'stalker' }),
});
if (resp.status === 401) {
document.getElementById('loginError').style.display = 'block';
return;
}
setPassword(pw);
document.getElementById('loginOverlay').classList.add('hidden');
} catch (e) {
setPassword(pw);
document.getElementById('loginOverlay').classList.add('hidden');
}
}
if (getPassword()) {
document.getElementById('loginOverlay').classList.add('hidden');
}
function switchMode(mode) {
document.getElementById('btnModeChat').classList.toggle('active', mode === 'chat');
document.getElementById('btnModeVoice').classList.toggle('active', mode === 'voice');
document.getElementById('chatMode').classList.toggle('hidden', mode !== 'chat');
document.getElementById('voiceGuide').classList.toggle('active', mode === 'voice');
}
// ===================== CHAT MODE =====================
function captureImage() {
document.getElementById('imageInput').click();
}
function handleImage(event) {
const file = event.target.files[0];
if (!file) return;
selectedImageType = file.type || 'image/jpeg';
const reader = new FileReader();
reader.onload = (e) => {
selectedImage = file;
document.getElementById('previewImg').src = e.target.result;
document.getElementById('previewName').textContent = file.name;
document.getElementById('imagePreview').classList.add('active');
};
reader.readAsDataURL(file);
event.target.value = '';
}
function removeImage() {
selectedImage = null;
document.getElementById('imagePreview').classList.remove('active');
}
function handleKey(event) {
if (event.key === 'Enter' && !event.shiftKey) {
event.preventDefault();
send();
}
}
function autoGrow(el) {
el.style.height = 'auto';
el.style.height = Math.min(el.scrollHeight, 120) + 'px';
}
function askExample(btn) {
document.getElementById('questionInput').value = btn.textContent;
send();
}
function addMessage(role, html) {
const chatArea = document.getElementById('chatArea');
const welcome = chatArea.querySelector('.welcome');
if (welcome) welcome.remove();
const msg = document.createElement('div');
msg.className = `message ${role}`;
msg.innerHTML = html;
chatArea.appendChild(msg);
chatArea.scrollTop = chatArea.scrollHeight;
return msg;
}
function addLoading() {
return addMessage('assistant',
'<div class="loading"><span></span><span></span><span></span></div>');
}
function renderMarkdown(text) {
let html = text
.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>')
.replace(/\*\*(.*?)\*\*/g, '<strong>$1</strong>')
.replace(/^### (.+)$/gm, '<h3>$1</h3>')
.replace(/^## (.+)$/gm, '<h2>$1</h2>')
.replace(/^[\-\*] (.+)$/gm, '<li>$1</li>')
.replace(/(<li>.*<\/li>)/gs, '<ul>$1</ul>')
.replace(/\n\n/g, '</p><p>')
return '<p>' + html + '</p>';
}
async function send() {
const input = document.getElementById('questionInput');
const question = input.value.trim();
if (!question) return;
let userHtml = '';
if (selectedImage) {
const imgSrc = document.getElementById('previewImg').src;
userHtml += `<img class="image-preview" src="${imgSrc}" alt="Foto">`;
}
userHtml += question.replace(/</g, '<').replace(/>/g, '>');
addMessage('user', userHtml);
input.value = '';
input.style.height = 'auto';
document.getElementById('sendBtn').disabled = true;
const loadingMsg = addLoading();
try {
let data;
if (selectedImage) {
const formData = new FormData();
formData.append('question', question);
formData.append('game', 'stalker');
formData.append('image', selectedImage);
const resp = await fetch(`${API_BASE}/api/ask/vision`, {
method: 'POST',
headers: { 'X-Password': getPassword() },
body: formData,
});
data = await resp.json();
let html = '';
if (data.situation) {
html += `<div class="situation">${data.situation}</div>`;
}
html += renderMarkdown(data.answer);
html += `<div class="sources">Quellen: ${data.sources.join(', ')}</div>`;
loadingMsg.innerHTML = html;
removeImage();
} else {
const resp = await fetch(`${API_BASE}/api/ask`, {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'X-Password': getPassword() },
body: JSON.stringify({ question, game: 'stalker' }),
});
data = await resp.json();
let html = renderMarkdown(data.answer);
html += `<div class="sources">Quellen: ${data.sources.join(', ')}</div>`;
loadingMsg.innerHTML = html;
}
if (data && data.detail === 'Falsches Passwort') {
localStorage.removeItem('arkanum_pw');
document.getElementById('loginOverlay').classList.remove('hidden');
loadingMsg.innerHTML = `<p style="color: var(--primary)">Sitzung abgelaufen. Bitte erneut einloggen.</p>`;
}
} catch (err) {
loadingMsg.innerHTML = `<p style="color: var(--primary)">Fehler: ${err.message}</p>`;
}
document.getElementById('sendBtn').disabled = false;
document.getElementById('chatArea').scrollTop =
document.getElementById('chatArea').scrollHeight;
}
// ===================== VOICE GUIDE =====================
let vg = {
walkthrough: null,
mode: null, // 'campaign' | 'zone_survival'
phaseIdx: 0,
stepIdx: 0,
phases: [],
audio: null,
isPlaying: false,
prefetchedNext: null, // { text, sources, audio }
recognition: null,
isListening: false,
audioUnlocked: false,
};
async function vgStart(mode) {
vg.mode = mode;
document.getElementById('vgModeSelect').style.display = 'none';
document.getElementById('vgActive').style.display = 'flex';
document.getElementById('vgInputArea').classList.add('active');
// Load walkthrough definition
try {
const resp = await fetch(`${API_BASE}/api/walkthrough/stalker`, {
headers: { 'X-Password': getPassword() },
});
vg.walkthrough = await resp.json();
} catch (err) {
document.getElementById('vgStepCard').innerHTML =
`<p style="color: var(--primary)">Fehler beim Laden: ${err.message}</p>`;
return;
}
vg.phases = vg.walkthrough.modes[mode].phases;
vg.phaseIdx = 0;
vg.stepIdx = 0;
// Unlock audio on iOS with user gesture
vg.audioUnlocked = true;
vgRenderPhaseDots();
vgLoadCurrentStep();
}
function vgGetTotalSteps() {
return vg.phases.reduce((sum, p) => sum + p.steps.length, 0);
}
function vgGetGlobalStepIndex() {
let idx = 0;
for (let i = 0; i < vg.phaseIdx; i++) {
idx += vg.phases[i].steps.length;
}
return idx + vg.stepIdx;
}
function vgRenderPhaseDots() {
const container = document.getElementById('vgPhaseDots');
container.innerHTML = vg.phases.map((p, i) => {
const cls = i < vg.phaseIdx ? 'done' : (i === vg.phaseIdx ? 'current' : '');
return `<div class="vg-phase-dot ${cls}" title="${p.title}"></div>`;
}).join('');
}
function vgUpdateProgress() {
const phase = vg.phases[vg.phaseIdx];
document.getElementById('vgPhaseTitle').textContent = phase.title;
const globalIdx = vgGetGlobalStepIndex();
const total = vgGetTotalSteps();
document.getElementById('vgStepCount').textContent =
`Schritt ${globalIdx + 1}/${total}`;
document.getElementById('vgProgressFill').style.width =
`${((globalIdx + 1) / total) * 100}%`;
vgRenderPhaseDots();
// Back button
document.getElementById('vgBtnBack').disabled =
(vg.phaseIdx === 0 && vg.stepIdx === 0);
}
async function vgLoadCurrentStep() {
const phase = vg.phases[vg.phaseIdx];
const step = phase.steps[vg.stepIdx];
vgUpdateProgress();
document.getElementById('vgStepCard').innerHTML =
'<div class="loading"><span></span><span></span><span></span></div>';
document.getElementById('vgStatus').textContent = 'Lade Schritt...';
// Check if prefetched
const stepKey = `${vg.phaseIdx}_${vg.stepIdx}`;
if (vg.prefetchedNext && vg.prefetchedNext.key === stepKey) {
vgDisplayStep(vg.prefetchedNext.text, vg.prefetchedNext.sources, vg.prefetchedNext.audio);
vg.prefetchedNext = null;
vgPrefetchNext();
return;
}
try {
// Expand step text
const resp = await fetch(`${API_BASE}/api/walkthrough/step`, {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'X-Password': getPassword() },
body: JSON.stringify({
game: 'stalker',
mode: vg.mode,
phase_id: phase.id,
step_id: step.id,
}),
});
const data = await resp.json();
// Get TTS audio
const audioResp = await fetch(`${API_BASE}/api/tts`, {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'X-Password': getPassword() },
body: JSON.stringify({ text: data.text }),
});
const audioBlob = await audioResp.blob();
const audioUrl = URL.createObjectURL(audioBlob);
vgDisplayStep(data.text, data.sources, audioUrl);
vgPrefetchNext();
} catch (err) {
document.getElementById('vgStepCard').innerHTML =
`<p style="color: var(--primary)">Fehler: ${err.message}</p>`;
document.getElementById('vgStatus').textContent = '';
}
}
function vgDisplayStep(text, sources, audioUrl) {
let html = `<div class="vg-step-text">${text.replace(/</g, '<').replace(/>/g, '>')}</div>`;
if (sources && sources.length > 0) {
html += `<div class="sources">Quellen: ${sources.join(', ')}</div>`;
}
document.getElementById('vgStepCard').innerHTML = html;
document.getElementById('vgStatus').textContent = '';
// Play audio
if (vg.audio) {
vg.audio.pause();
URL.revokeObjectURL(vg.audio.src);
}
vg.audio = new Audio(audioUrl);
vg.audio.onended = () => {
vg.isPlaying = false;
document.getElementById('vgStatus').textContent = 'Sage "Weiter" oder drücke den Button';
};
vg.audio.onplay = () => {
vg.isPlaying = true;
document.getElementById('vgStatus').textContent = 'Spielt ab...';
};
vg.audio.play().catch(() => {
document.getElementById('vgStatus').textContent = 'Tippe auf "Nochmal" zum Abspielen';
});
}
async function vgPrefetchNext() {
// Determine next step
let nextPhaseIdx = vg.phaseIdx;
let nextStepIdx = vg.stepIdx + 1;
if (nextStepIdx >= vg.phases[nextPhaseIdx].steps.length) {
nextPhaseIdx++;
nextStepIdx = 0;
}
if (nextPhaseIdx >= vg.phases.length) return; // no more steps
const phase = vg.phases[nextPhaseIdx];
const step = phase.steps[nextStepIdx];
const key = `${nextPhaseIdx}_${nextStepIdx}`;
try {
const resp = await fetch(`${API_BASE}/api/walkthrough/step`, {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'X-Password': getPassword() },
body: JSON.stringify({
game: 'stalker',
mode: vg.mode,
phase_id: phase.id,
step_id: step.id,
}),
});
const data = await resp.json();
const audioResp = await fetch(`${API_BASE}/api/tts`, {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'X-Password': getPassword() },
body: JSON.stringify({ text: data.text }),
});
const audioBlob = await audioResp.blob();
const audioUrl = URL.createObjectURL(audioBlob);
vg.prefetchedNext = { key, text: data.text, sources: data.sources, audio: audioUrl };
} catch (e) {
// Prefetch failed – not critical
}
}
function vgNext() {
if (vg.audio) { vg.audio.pause(); }
vg.stepIdx++;
if (vg.stepIdx >= vg.phases[vg.phaseIdx].steps.length) {
vg.phaseIdx++;
vg.stepIdx = 0;
}
if (vg.phaseIdx >= vg.phases.length) {
// Walkthrough complete
document.getElementById('vgStepCard').innerHTML =
'<div class="vg-step-text">Geschafft! Ihr kennt jetzt die wichtigsten Regeln. Viel Spaß beim Spielen! Falls ihr eine Frage habt, wechselt einfach in den Chat-Modus.</div>';
document.getElementById('vgBtnNext').disabled = true;
document.getElementById('vgStatus').textContent = 'Walkthrough abgeschlossen';
vgUpdateProgress();
return;
}
vgLoadCurrentStep();
}
function vgBack() {
if (vg.audio) { vg.audio.pause(); }
vg.stepIdx--;
if (vg.stepIdx < 0) {
vg.phaseIdx--;
if (vg.phaseIdx < 0) {
vg.phaseIdx = 0;
vg.stepIdx = 0;
return;
}
vg.stepIdx = vg.phases[vg.phaseIdx].steps.length - 1;
}
vg.prefetchedNext = null;
vgLoadCurrentStep();
}
function vgReplay() {
if (vg.audio) {
vg.audio.currentTime = 0;
vg.audio.play().catch(() => {});
}
}
function vgStop() {
if (vg.audio) {
vg.audio.pause();
URL.revokeObjectURL(vg.audio.src);
vg.audio = null;
}
if (vg.recognition && vg.isListening) {
vg.recognition.stop();
vg.isListening = false;
}
if (vg.prefetchedNext && vg.prefetchedNext.audio) {
URL.revokeObjectURL(vg.prefetchedNext.audio);
}
vg.prefetchedNext = null;
document.getElementById('vgActive').style.display = 'none';
document.getElementById('vgModeSelect').style.display = 'flex';
document.getElementById('vgInputArea').classList.remove('active');
document.getElementById('vgBtnNext').disabled = false;
}
// ---- Speech Recognition ----
function vgInitSpeechRecognition() {
const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
if (!SpeechRecognition) return null;
const recog = new SpeechRecognition();
recog.lang = 'de-DE';
recog.continuous = false;
recog.interimResults = false;
recog.onresult = (event) => {
const transcript = event.results[0][0].transcript.toLowerCase().trim();
vgHandleVoiceInput(transcript);
};
recog.onend = () => {
vg.isListening = false;
document.getElementById('vgBtnMic').classList.remove('listening');
document.getElementById('vgStatus').textContent = '';
};
recog.onerror = (event) => {
vg.isListening = false;
document.getElementById('vgBtnMic').classList.remove('listening');
if (event.error !== 'no-speech') {
document.getElementById('vgStatus').textContent = `Mikrofon-Fehler: ${event.error}`;
}
};
return recog;
}
function vgToggleMic() {
if (!vg.recognition) {
vg.recognition = vgInitSpeechRecognition();
}
if (!vg.recognition) {
document.getElementById('vgStatus').textContent = 'Spracherkennung nicht verfügbar';
return;
}
if (vg.isListening) {
vg.recognition.stop();
vg.isListening = false;
document.getElementById('vgBtnMic').classList.remove('listening');
} else {
// Pause audio while listening
if (vg.audio && vg.isPlaying) {
vg.audio.pause();
}
vg.recognition.start();
vg.isListening = true;
document.getElementById('vgBtnMic').classList.add('listening');
document.getElementById('vgStatus').textContent = 'Höre zu...';
}
}
function vgHandleVoiceInput(text) {
// Intent classification
const continueWords = ['weiter', 'ja', 'ok', 'okay', 'nächster', 'nächste', 'fertig', 'next', 'yes'];
const backWords = ['nochmal', 'zurück', 'wiederhole', 'wiederholen', 'nochmals', 'repeat', 'back'];
const words = text.split(/\s+/);
const isContinue = continueWords.some(w => words.includes(w));
const isBack = backWords.some(w => words.includes(w));
if (isContinue) {
vgNext();
} else if (isBack) {
vgReplay();
} else {
// It's a question – send to /api/ask
vgAskQuestionText(text);
}
}
async function vgAskQuestion() {
const input = document.getElementById('vgQuestionInput');
const question = input.value.trim();
if (!question) return;
input.value = '';
await vgAskQuestionText(question);
}
async function vgAskQuestionText(question) {
// Pause current audio
if (vg.audio && vg.isPlaying) {
vg.audio.pause();
}
const card = document.getElementById('vgStepCard');
const savedContent = card.innerHTML;
card.innerHTML = `<div class="vg-step-text" style="color: var(--primary)">Frage: ${question.replace(/</g, '<')}</div>
<div class="loading"><span></span><span></span><span></span></div>`;
document.getElementById('vgStatus').textContent = 'Beantworte Frage...';
try {
const resp = await fetch(`${API_BASE}/api/ask`, {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'X-Password': getPassword() },
body: JSON.stringify({ question, game: 'stalker' }),
});
const data = await resp.json();
// TTS for the answer
const audioResp = await fetch(`${API_BASE}/api/tts`, {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'X-Password': getPassword() },
body: JSON.stringify({ text: data.answer }),
});
const audioBlob = await audioResp.blob();
const audioUrl = URL.createObjectURL(audioBlob);
card.innerHTML = `<div class="vg-step-text" style="color: var(--primary); font-size: 0.85rem; margin-bottom: 0.5rem;">Frage: ${question.replace(/</g, '<')}</div>
<div class="vg-step-text">${data.answer.replace(/</g, '<').replace(/>/g, '>')}</div>
<div class="sources">Quellen: ${data.sources.join(', ')}</div>
<div style="margin-top: 0.75rem; text-align: center;">
<button class="vg-btn" onclick="vgResumeWalkthrough()">Zurück zum Walkthrough</button>
</div>`;
// Play answer audio
const answerAudio = new Audio(audioUrl);
answerAudio.play().catch(() => {});
document.getElementById('vgStatus').textContent = '';
// Save walkthrough content to restore
vg._savedStepContent = savedContent;
} catch (err) {
card.innerHTML = `<p style="color: var(--primary)">Fehler: ${err.message}</p>
<div style="margin-top: 0.75rem; text-align: center;">
<button class="vg-btn" onclick="vgResumeWalkthrough()">Zurück zum Walkthrough</button>
</div>`;
vg._savedStepContent = savedContent;
document.getElementById('vgStatus').textContent = '';
}
}
function vgResumeWalkthrough() {
if (vg._savedStepContent) {
document.getElementById('vgStepCard').innerHTML = vg._savedStepContent;
vg._savedStepContent = null;
}
document.getElementById('vgStatus').textContent = 'Sage "Weiter" oder drücke den Button';
}
</script>
</body>
</html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="mobile-web-app-capable" content="yes">
<title>Arkanum – Regelexperte</title>
<link rel="manifest" href="manifest.json">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<meta name="theme-color" content="#1a1a2e">
<style>
:root {
--bg: #1a1a2e;
--surface: #16213e;
--primary: #e94560;
--accent: #f5a623;
--text: #eee;
--text-muted: #999;
--border: #333;
--success: #4caf50;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
background: var(--bg);
color: var(--text);
min-height: 100dvh;
display: flex;
flex-direction: column;
}
header {
background: var(--surface);
padding: 1rem;
text-align: center;
border-bottom: 2px solid var(--primary);
}
header h1 {
font-size: 1.4rem;
letter-spacing: 2px;
}
header h1 span { color: var(--primary); }
header p {
font-size: 0.8rem;
color: var(--text-muted);
margin-top: 0.25rem;
}
/* Mode Toggle */
.mode-toggle {
display: flex;
justify-content: center;
gap: 0;
margin-top: 0.5rem;
}
.mode-toggle button {
background: transparent;
border: 1px solid var(--border);
color: var(--text-muted);
padding: 0.3rem 1rem;
font-size: 0.75rem;
cursor: pointer;
transition: all 0.2s;
}
.mode-toggle button:first-child { border-radius: 6px 0 0 6px; }
.mode-toggle button:last-child { border-radius: 0 6px 6px 0; }
.mode-toggle button.active {
background: var(--primary);
border-color: var(--primary);
color: white;
}
main {
flex: 1;
padding: 1rem;
max-width: 700px;
width: 100%;
margin: 0 auto;
display: flex;
flex-direction: column;
gap: 1rem;
}
/* ---- Chat Mode ---- */
.chat-area {
flex: 1;
overflow-y: auto;
display: flex;
flex-direction: column;
gap: 0.75rem;
padding-bottom: 1rem;