In-Game-Soundboard (einklappbar, Broadcast an alle)
- send_sound (api.php): whitelisted Sounds via active_emojis an alle Clients broadcasten - play.html: einklappbares Soundboard-Panel unten links (Maeh/Buzzer/Drumroll/Airhorn) - renderEmojis spielt Sound-Events via HTML5 Audio() ab (kein visuelles Element) - sounds/README.txt erklaert, welche MP3-Dateien noch abgelegt werden muessen Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
1d3feeb2fe
commit
6b21658a70
3 changed files with 71 additions and 2 deletions
25
api.php
25
api.php
|
|
@ -660,6 +660,31 @@ try {
|
|||
respond(['ok' => true]);
|
||||
break;
|
||||
|
||||
case 'send_sound':
|
||||
// Soundboard: kurzen Sound bei allen Spielern abspielen (via active_emojis broadcast)
|
||||
$body = input();
|
||||
$code = slugCode((string) ($body['code'] ?? ''));
|
||||
$key = (string) ($body['sound'] ?? '');
|
||||
$sounds = [
|
||||
'maeh' => 'sounds/maeh.mp3',
|
||||
'buzzer' => 'sounds/buzzer.mp3',
|
||||
'drumroll' => 'sounds/drumroll.mp3',
|
||||
'airhorn' => 'sounds/airhorn.mp3',
|
||||
];
|
||||
if (!isset($sounds[$key])) respond(['error' => 'Unbekannter Sound.'], 400);
|
||||
$emojiStmt = $pdo->prepare('SELECT active_emojis FROM gtl_rooms WHERE code=?');
|
||||
$emojiStmt->execute([$code]);
|
||||
$emojiRow = $emojiStmt->fetch();
|
||||
if (!$emojiRow) respond(['error' => 'Raum nicht gefunden.'], 404);
|
||||
$list = (!empty($emojiRow['active_emojis'])) ? (json_decode($emojiRow['active_emojis'], true) ?: []) : [];
|
||||
$list = array_filter($list, fn($e) => ($e['ts'] ?? 0) >= ($now - 4));
|
||||
$list[] = ['sound' => $sounds[$key], 'ts' => $now, 'id' => uniqid()];
|
||||
$list = array_values(array_slice($list, -20));
|
||||
$pdo->prepare('UPDATE gtl_rooms SET active_emojis=?, updated_at=? WHERE code=?')
|
||||
->execute([json_encode($list), $now, $code]);
|
||||
respond(['ok' => true]);
|
||||
break;
|
||||
|
||||
case 'request_voting':
|
||||
// Demokratischer Voting-Antrag: sobald ALLE Spieler angefragt haben → auto-open
|
||||
$body = input();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue