/** * Audio Overlap Debug Test Script * * This script helps test that background sounds stop properly when progressing through tasks. * * To use: * 1. Start the game and begin playing * 2. Open the browser console (F12) * 3. Copy and paste this script into the console * 4. Press Enter to run the test * * The test will simulate rapid task progression and monitor for audio overlaps. */ console.log('🎵 Starting Audio Overlap Test...'); // Function to test audio stopping function testAudioStopping() { if (!window.game || !window.game.audioManager) { console.error('❌ Game or AudioManager not available'); return; } const audioManager = window.game.audioManager; console.log('🎵 Testing audio category stopping...'); // Test rapid audio switching let testCount = 0; const maxTests = 5; const testInterval = setInterval(() => { testCount++; console.log(`🎵 Test ${testCount}/${maxTests}: Playing task audio...`); // Stop all audio first audioManager.stopAllImmediate(); // Wait a bit, then play new audio setTimeout(() => { audioManager.playTaskAudio('teasing', { fadeIn: 500, loop: true }); // Check how many audio elements are playing after a short delay setTimeout(() => { const currentlyPlaying = audioManager.getCurrentlyPlaying(); const playingCount = Object.keys(currentlyPlaying).length; console.log(`🎵 Test ${testCount}: ${playingCount} audio tracks currently playing`); console.log('🎵 Playing audio details:', currentlyPlaying); if (playingCount > 1) { console.warn(`⚠️ WARNING: ${playingCount} tracks playing simultaneously!`); } else { console.log('✅ Audio overlap test passed'); } }, 100); }, 50); if (testCount >= maxTests) { clearInterval(testInterval); console.log('🎵 Audio overlap test completed'); // Clean up setTimeout(() => { audioManager.stopAllImmediate(); console.log('🎵 Test cleanup completed'); }, 2000); } }, 1000); } // Function to monitor audio during actual gameplay function monitorGameplayAudio() { if (!window.game || !window.game.audioManager) { console.error('❌ Game or AudioManager not available'); return; } console.log('🎵 Starting gameplay audio monitoring...'); console.log('🎵 Quickly complete or skip several tasks to test audio overlap prevention'); // Monitor audio every 500ms const monitorInterval = setInterval(() => { const currentlyPlaying = window.game.audioManager.getCurrentlyPlaying(); const playingCount = Object.keys(currentlyPlaying).length; if (playingCount > 1) { console.warn(`⚠️ AUDIO OVERLAP DETECTED: ${playingCount} tracks playing!`); console.log('🎵 Overlapping audio details:', currentlyPlaying); } else if (playingCount === 1) { console.log(`✅ Single audio track playing (normal)`); } }, 500); // Stop monitoring after 30 seconds setTimeout(() => { clearInterval(monitorInterval); console.log('🎵 Audio monitoring stopped'); }, 30000); return monitorInterval; } // Function to test rapid task progression simulation function simulateRapidProgression() { if (!window.game || !window.game.gameState || !window.game.gameState.isRunning) { console.error('❌ Game not running - start a game first'); return; } console.log('🎵 Simulating rapid task progression...'); let progressCount = 0; const maxProgress = 3; const progressInterval = setInterval(() => { progressCount++; console.log(`🎵 Rapid progression test ${progressCount}/${maxProgress}`); // Simulate completing a task (this should stop audio and start new audio) if (window.game.gameState.isRunning) { window.game.completeTask(); } if (progressCount >= maxProgress) { clearInterval(progressInterval); console.log('🎵 Rapid progression test completed'); } }, 200); // Very fast progression to test overlap } // Run the tests console.log('🎵 Audio Debug Test Menu:'); console.log('🎵 1. Run testAudioStopping() - Tests basic audio stopping'); console.log('🎵 2. Run monitorGameplayAudio() - Monitors for overlaps during gameplay'); console.log('🎵 3. Run simulateRapidProgression() - Simulates rapid task progression'); console.log('🎵 Example: testAudioStopping()'); // Make functions available globally for manual testing window.audioDebugTest = { testAudioStopping, monitorGameplayAudio, simulateRapidProgression }; console.log('🎵 Functions available as window.audioDebugTest.*'); console.log('🎵 Quick test: window.audioDebugTest.testAudioStopping()');