modified: templates/quiz_buzzer_multiplayer.html

This commit is contained in:
2025-11-28 22:54:35 +01:00
parent 0d49cbc974
commit 7cb53a3526

View File

@@ -264,18 +264,15 @@
{ id: 4, name: teamNames[3] || 'Spieler 4', score: {{ player_scores[3] if player_scores else 0 }} } { id: 4, name: teamNames[3] || 'Spieler 4', score: {{ player_scores[3] if player_scores else 0 }} }
]; ];
// Leertaste zum Buzzern // Leertaste zum Starten und Buzzern
document.addEventListener('keydown', function(e) { document.addEventListener('keydown', function(e) {
if (e.code === 'Space' && canBuzz && !currentBuzzer) { if (e.code === 'Space') {
e.preventDefault(); e.preventDefault();
triggerBuzz(); if (!gameStarted) {
} startGame();
}); } else if (canBuzz && !currentBuzzer) {
triggerBuzz();
document.addEventListener('keydown', function(e) { }
if (e.code === 'Space' && !gameStarted) {
e.preventDefault();
startGame();
} }
}); });
@@ -353,12 +350,14 @@
function startGame() { function startGame() {
if (gameStarted) return; if (gameStarted) return;
gameStarted = true; gameStarted = true;
document.getElementById('startButton').classList.add('disabled'); var startBtn = document.getElementById('startButton');
document.getElementById('startButton').style.cursor = 'wait'; if (startBtn) {
startBtn.classList.add('disabled');
startBtn.style.cursor = 'wait';
startBtn.style.display = 'none';
}
document.getElementById('buzzerHint').style.display = 'block'; document.getElementById('buzzerHint').style.display = 'block';
const device_id = window.deviceId; const device_id = window.deviceId;
const startPosition = getOption('startPosition', 'start'); const startPosition = getOption('startPosition', 'start');
let position_ms = 0; let position_ms = 0;
@@ -366,12 +365,10 @@
const duration = {{ track.duration_ms if track.duration_ms else 180000 }}; const duration = {{ track.duration_ms if track.duration_ms else 180000 }};
position_ms = Math.floor(Math.random() * (duration - 30000)); position_ms = Math.floor(Math.random() * (duration - 30000));
} }
fetch(`/play_track?device_id=${device_id}&track_uri={{ track.uri }}&position_ms=${position_ms}`, { method: 'POST' }) fetch(`/play_track?device_id=${device_id}&track_uri={{ track.uri }}&position_ms=${position_ms}`, { method: 'POST' })
.then(response => response.json()) .then(response => response.json())
.then(() => { .then(() => {
console.log('Play command sent'); console.log('Play command sent');
document.getElementById('startButton').style.display = 'none';
canBuzz = true; canBuzz = true;
}) })
.catch(error => console.error('Error starting playback:', error)); .catch(error => console.error('Error starting playback:', error));
@@ -556,7 +553,7 @@
player_id: currentBuzzer, player_id: currentBuzzer,
apply_points: false // Punkte NICHT sofort anwenden apply_points: false // Punkte NICHT sofort anwenden
}) })
) })
.then(response => response.json()) .then(response => response.json())
.then(data => { .then(data => {
const resultContainer = document.getElementById('resultContainer'); const resultContainer = document.getElementById('resultContainer');