From 5a82469da5b7c26eec458994530d3993f70d8558 Mon Sep 17 00:00:00 2001 From: LoveEevee Date: Wed, 29 Aug 2018 08:55:16 +0300 Subject: [PATCH] Fix getting stuck at the loading screen --- public/src/js/controller.js | 10 +++++----- public/src/js/game.js | 6 +++--- public/src/js/loader.js | 21 +++++++++++++-------- public/src/js/loadsong.js | 12 +++++++++++- public/src/js/scoresheet.js | 6 +++--- public/src/js/songselect.js | 14 +++++++------- public/src/js/titlescreen.js | 4 ++-- 7 files changed, 44 insertions(+), 29 deletions(-) diff --git a/public/src/js/controller.js b/public/src/js/controller.js index 9ac7fce..4a63d0f 100644 --- a/public/src/js/controller.js +++ b/public/src/js/controller.js @@ -23,11 +23,11 @@ function Controller(selectedSong, songData, autoPlayEnabled){ this.loadUIEvents = function(){ $("#song-selection-butt").click(function(){ - assets.sounds["don"].play(); + assets.sounds["don"].playAsset(); _this.songSelection(); }); $("#restart-butt").click(function(){ - assets.sounds["don"].play(); + assets.sounds["don"].playAsset(); _this.restartSong(); }); $("#continue-butt").click(function(){ @@ -48,7 +48,7 @@ function Controller(selectedSong, songData, autoPlayEnabled){ else if(ms>=0 && !started){ //when music shall starts setTimeout(function(){ assets.sounds["main-music"].volume = 0.7; - assets.sounds["main-music"].play(); + assets.sounds["main-music"].playAsset(); }, _songData.generalInfo.audioWait); started=true; } @@ -84,7 +84,7 @@ function Controller(selectedSong, songData, autoPlayEnabled){ if (score.fail == 0) { vp = 'fullcombo'; setTimeout(function(){ - assets.sounds['fullcombo'].play(); + assets.sounds['fullcombo'].playAsset(); }, 1350); } else if (score.hp >= 50) { vp = 'clear'; @@ -92,7 +92,7 @@ function Controller(selectedSong, songData, autoPlayEnabled){ vp = 'fail'; } - assets.sounds['game' + vp].play(); + assets.sounds['game' + vp].playAsset(); setTimeout(function(){ var scoresheet = new Scoresheet(_this, _this.getGlobalScore()); diff --git a/public/src/js/game.js b/public/src/js/game.js index 10f1e5c..09a45c7 100644 --- a/public/src/js/game.js +++ b/public/src/js/game.js @@ -230,7 +230,7 @@ function Game(controller, selectedSong, songData){ _mainMusicPlaying=false; } else{ - assets.sounds["main-music"].play(); + assets.sounds["main-music"].playAsset(); _mainMusicPlaying=true; } } @@ -253,14 +253,14 @@ function Game(controller, selectedSong, songData){ this.togglePause = function(){ if(!_paused){ - assets.sounds["pause"].play(); + assets.sounds["pause"].playAsset(); _paused=true; _latestDate = new Date(); _this.toggleMainMusic(); } else{ - assets.sounds["cancel"].play(); + assets.sounds["cancel"].playAsset(); _paused=false; var currentDate = new Date(); _ellapsedTimeSincePause = _ellapsedTimeSincePause + Math.abs(currentDate.getTime() - _latestDate.getTime()); diff --git a/public/src/js/loader.js b/public/src/js/loader.js index a7c9ae1..3d633ae 100644 --- a/public/src/js/loader.js +++ b/public/src/js/loader.js @@ -24,16 +24,21 @@ function Loader(){ assets.audio.forEach(function(name){ var id = name.substr(0, name.length-4); - var audio = new Audio(); - audio.src = '/assets/audio/'+name; - audio.muted = true; - audio.load(); - audio.onloadeddata = function(){ - assets.sounds[id] = new Audio(); - assets.sounds[id].src = audio.src; - assets.sounds[id].load(); + assets.sounds[id] = new Audio(); + assets.sounds[id].muted = true; + assets.sounds[id].playAsset = function(){ + try{ + assets.sounds[id].muted = false; + assets.sounds[id].play() + }catch(e){ + console.warn(e) + } + } + assets.sounds[id].onloadeddata = function(){ _this.assetLoaded(); }; + assets.sounds[id].src = '/assets/audio/'+name; + assets.sounds[id].load(); }); $.ajax({ diff --git a/public/src/js/loadsong.js b/public/src/js/loadsong.js index af9dc0b..a7b91a5 100644 --- a/public/src/js/loadsong.js +++ b/public/src/js/loadsong.js @@ -13,10 +13,11 @@ function loadSong(selectedSong, autoPlayEnabled){ assets.sounds["bgm_songsel"].pause(); assets.sounds["bgm_songsel"].currentTime = 0; - assets.sounds["start"].play(); + assets.sounds["start"].playAsset(); $("#assets").append(""); var audio = new Audio(); + audio.muted = true; audio.src = '/songs/'+_selectedSong.folder+'/main.mp3'; audio.load(); @@ -25,6 +26,15 @@ function loadSong(selectedSong, autoPlayEnabled){ _this.checkIfEverythingLoaded(); }); + audio.playAsset = function(){ + try{ + audio.muted = false; + audio.play() + }catch(e){ + console.warn(e) + } + } + audio.onloadeddata = function(){ _musicLoaded=true; assets.sounds["main-music"]=audio; diff --git a/public/src/js/scoresheet.js b/public/src/js/scoresheet.js index e03abb8..d5a9eb7 100644 --- a/public/src/js/scoresheet.js +++ b/public/src/js/scoresheet.js @@ -81,13 +81,13 @@ function Scoresheet(controller, score){ _this.setResults(); $("#song-select").click(function(){ - assets.sounds["don"].play(); + assets.sounds["don"].playAsset(); bgm.pause(); controller.songSelection(); }); $("#replay").click(function(){ - assets.sounds["don"].play(); + assets.sounds["don"].playAsset(); bgm.pause(); controller.restartSong(); }); @@ -96,7 +96,7 @@ function Scoresheet(controller, score){ } - assets.sounds["results"].play(); + assets.sounds["results"].playAsset(); bgm = new BufferedLoop( {url: '/assets/audio/bgm_result.ogg', duration: 0.847}, diff --git a/public/src/js/songselect.js b/public/src/js/songselect.js index e46972b..b7951ec 100644 --- a/public/src/js/songselect.js +++ b/public/src/js/songselect.js @@ -51,7 +51,7 @@ function SongSelect(){ _this.endPreview(); assets.sounds["diffsel"].pause(); assets.sounds["diffsel"].currentTime = 0; - assets.sounds["don"].play(); + assets.sounds["don"].playAsset(); clearInterval(menuLoop); var difficultyElement = (e.target.className=="stars" || e.target.className=="diffname") ? e.target.parentElement : e.target; @@ -79,14 +79,14 @@ function SongSelect(){ if ($(".opened").length && $(".opened").attr('id') == $(this).attr('id')) { _this.endPreview(); bgm.play(); - assets.sounds["cancel"].play(); + assets.sounds["cancel"].playAsset(); $(".difficulty").hide(); $(".opened").removeClass("opened", 300); assets.sounds["diffsel"].pause(); assets.sounds["diffsel"].currentTime = 0; setTimeout(function(){ - assets.sounds["song-select"].play(); + assets.sounds["song-select"].playAsset(); }, 300); $('.songsel-title').fadeOut(200, function(){ @@ -100,11 +100,11 @@ function SongSelect(){ if(!$('.opened').length) { _this.startPreview($(this).data('song-id'), $(this).data('preview')); - assets.sounds["don"].play(); + assets.sounds["don"].playAsset(); assets.sounds["song-select"].pause(); assets.sounds["song-select"].currentTime = 0; setTimeout(function(){ - assets.sounds["diffsel"].play(); + assets.sounds["diffsel"].playAsset(); }, 300); $('.songsel-title').fadeOut(200, function(){ @@ -114,7 +114,7 @@ function SongSelect(){ } else { _preview.pause(); _this.startPreview($(this).data('song-id'), $(this).data('preview'), false); - assets.sounds["ka"].play(); + assets.sounds["ka"].playAsset(); } }; @@ -136,7 +136,7 @@ function SongSelect(){ bgm.play(); setTimeout(function(){ - assets.sounds["song-select"].play(); + assets.sounds["song-select"].playAsset(); }, 200); for(var i=0; i