@@ -447,9 +447,9 @@ <h2>Game Paused</h2>
447447 async function loadLevelFromGithub ( filename ) {
448448 try {
449449 const response = await fetch ( `${ RAW_CONTENT_BASE } /${ filename } ` ) ;
450- console . log ( response ) ;
450+ loadresponse = console . log ( response ) ;
451451 if ( ! response . ok ) {
452- throw new Error ( 'Failed to fetch level' ) ;
452+ throw new Error ( 'Failed to fetch level. Error:' , loadresponse ) ;
453453 }
454454 const levelCode = await response . text ( ) ;
455455
@@ -600,12 +600,43 @@ <h2>Game Paused</h2>
600600 if ( window . levelData ) {
601601 console . log ( 'Level data found:' , window . levelData ) ;
602602 processLevelData ( window . levelData ) ;
603+ requestAnimationFrame ( updateGame ) ; // Start the game after processing level
604+ if ( isPracticeMode ) {
605+ // Initialize practice mode settings
606+ const gameSpeedSelect = document . getElementById ( 'gameSpeed' ) ;
607+ if ( gameSpeedSelect ) {
608+ gameSpeedSelect . disabled = false ;
609+ if ( SettingsManager . current . gameSpeed ) {
610+ gameSpeed = SettingsManager . current . gameSpeed ;
611+ gameSpeedSelect . value = gameSpeed . toString ( ) ;
612+ }
613+ }
614+
615+ // Switch to practice mode music
616+ if ( isLevelStarted && ! isPaused && ! isGameOver && ! isLevelComplete ) {
617+ try {
618+ switchAudioTracks ( practiceMusic , backgroundMusic ) ;
619+ } catch ( error ) {
620+ console . error ( "Error switching to practice mode music:" , error ) ;
621+ }
622+ }
623+ }
624+ resolve ( ) ;
625+ } else {
626+ const error = new Error ( 'Level data not found in loaded script' ) ;
627+ console . error ( error ) ;
628+ showLoadingError ( `Failed to load level: ${ error . message } ` ) ;
629+ reject ( error ) ;
603630 }
631+ } ;
604632
605-
633+ levelScript . onerror = ( error ) => {
634+ console . error ( 'Error loading level script:' , error ) ;
635+ showLoadingError ( `Failed to load level ${ levelNumber } ` ) ;
636+ reject ( error ) ;
606637 } ;
638+
607639 document . body . appendChild ( levelScript ) ;
608- resolve ( ) ;
609640 }
610641 } catch ( error ) {
611642 console . error ( 'Error initializing level data:' , error ) ;
@@ -661,15 +692,19 @@ <h2>Game Paused</h2>
661692 // Create a blob from the array buffer
662693 const blob = new Blob ( [ data . musicData . data ] , { type : data . musicData . type } ) ;
663694 levelMusic = URL . createObjectURL ( blob ) ;
695+ } else if ( isPracticeMode ) {
696+ levelMusic = '../Sound/Basic Soundeffects/practicetd.mp3' ;
664697 } else {
665- levelMusic = `../Sound/Level Soundtracks/${ data . musicValue } ` ;
698+ levelMusic = data . music ;
699+ console . log ( "Level Soundtrack: " , levelMusic ) ;
666700 }
667701
668702 levelId = data . id ;
669703 document . title = levelTitle ;
670704
671705 // Initialize game systems
672706 // (now in StartButton) > setupAudio();
707+ requestAnimationFrame ( updateGame ) ;
673708 calculateTotalBlocks ( ) ;
674709
675710 // Reset game state
@@ -1769,16 +1804,7 @@ <h2>Game Paused</h2>
17691804 }
17701805 }
17711806
1772- /**
1773- * Optimized game loop using requestAnimationFrame
1774- * @param {number } timestamp - Current timestamp from requestAnimationFrame
1775- */
1776- let lastTime = 0 ;
1777- function gameLoop ( timestamp ) {
1778- const deltaTime = timestamp - lastTime ;
1779- lastTime = timestamp ;
1780- updateGame ( deltaTime ) ;
1781- }
1807+
17821808
17831809 /**
17841810 * Preloads all game assets before starting
@@ -2154,8 +2180,8 @@ <h2>Game Paused</h2>
21542180 // Initialize database
21552181 await initDB ( ) ;
21562182
2157- // Initialize level data
2158- await initializeLevelData ( ) ;
2183+ // Initialize level data (now in StartButton)
2184+ // await initializeLevelData();
21592185
21602186 // Initialize UI and controls
21612187 await initializeLevel ( ) ;
@@ -2164,7 +2190,7 @@ <h2>Game Paused</h2>
21642190 // await setupAudio();
21652191
21662192 // Start game loop
2167- requestAnimationFrame ( gameLoop ) ;
2193+ requestAnimationFrame ( updateGame ) ;
21682194
21692195 } catch ( error ) {
21702196 console . error ( 'Error during initialization:' , error ) ;
0 commit comments