Fix getting stuck at the loading screen

This commit is contained in:
LoveEevee 2018-08-29 08:55:16 +03:00
parent 2adbfc1e99
commit 5a82469da5
7 changed files with 44 additions and 29 deletions

View File

@ -23,11 +23,11 @@ function Controller(selectedSong, songData, autoPlayEnabled){
this.loadUIEvents = function(){ this.loadUIEvents = function(){
$("#song-selection-butt").click(function(){ $("#song-selection-butt").click(function(){
assets.sounds["don"].play(); assets.sounds["don"].playAsset();
_this.songSelection(); _this.songSelection();
}); });
$("#restart-butt").click(function(){ $("#restart-butt").click(function(){
assets.sounds["don"].play(); assets.sounds["don"].playAsset();
_this.restartSong(); _this.restartSong();
}); });
$("#continue-butt").click(function(){ $("#continue-butt").click(function(){
@ -48,7 +48,7 @@ function Controller(selectedSong, songData, autoPlayEnabled){
else if(ms>=0 && !started){ //when music shall starts else if(ms>=0 && !started){ //when music shall starts
setTimeout(function(){ setTimeout(function(){
assets.sounds["main-music"].volume = 0.7; assets.sounds["main-music"].volume = 0.7;
assets.sounds["main-music"].play(); assets.sounds["main-music"].playAsset();
}, _songData.generalInfo.audioWait); }, _songData.generalInfo.audioWait);
started=true; started=true;
} }
@ -84,7 +84,7 @@ function Controller(selectedSong, songData, autoPlayEnabled){
if (score.fail == 0) { if (score.fail == 0) {
vp = 'fullcombo'; vp = 'fullcombo';
setTimeout(function(){ setTimeout(function(){
assets.sounds['fullcombo'].play(); assets.sounds['fullcombo'].playAsset();
}, 1350); }, 1350);
} else if (score.hp >= 50) { } else if (score.hp >= 50) {
vp = 'clear'; vp = 'clear';
@ -92,7 +92,7 @@ function Controller(selectedSong, songData, autoPlayEnabled){
vp = 'fail'; vp = 'fail';
} }
assets.sounds['game' + vp].play(); assets.sounds['game' + vp].playAsset();
setTimeout(function(){ setTimeout(function(){
var scoresheet = new Scoresheet(_this, _this.getGlobalScore()); var scoresheet = new Scoresheet(_this, _this.getGlobalScore());

View File

@ -230,7 +230,7 @@ function Game(controller, selectedSong, songData){
_mainMusicPlaying=false; _mainMusicPlaying=false;
} }
else{ else{
assets.sounds["main-music"].play(); assets.sounds["main-music"].playAsset();
_mainMusicPlaying=true; _mainMusicPlaying=true;
} }
} }
@ -253,14 +253,14 @@ function Game(controller, selectedSong, songData){
this.togglePause = function(){ this.togglePause = function(){
if(!_paused){ if(!_paused){
assets.sounds["pause"].play(); assets.sounds["pause"].playAsset();
_paused=true; _paused=true;
_latestDate = new Date(); _latestDate = new Date();
_this.toggleMainMusic(); _this.toggleMainMusic();
} }
else{ else{
assets.sounds["cancel"].play(); assets.sounds["cancel"].playAsset();
_paused=false; _paused=false;
var currentDate = new Date(); var currentDate = new Date();
_ellapsedTimeSincePause = _ellapsedTimeSincePause + Math.abs(currentDate.getTime() - _latestDate.getTime()); _ellapsedTimeSincePause = _ellapsedTimeSincePause + Math.abs(currentDate.getTime() - _latestDate.getTime());

View File

@ -24,16 +24,21 @@ function Loader(){
assets.audio.forEach(function(name){ assets.audio.forEach(function(name){
var id = name.substr(0, name.length-4); var id = name.substr(0, name.length-4);
var audio = new Audio(); assets.sounds[id] = new Audio();
audio.src = '/assets/audio/'+name; assets.sounds[id].muted = true;
audio.muted = true; assets.sounds[id].playAsset = function(){
audio.load(); try{
audio.onloadeddata = function(){ assets.sounds[id].muted = false;
assets.sounds[id] = new Audio(); assets.sounds[id].play()
assets.sounds[id].src = audio.src; }catch(e){
assets.sounds[id].load(); console.warn(e)
}
}
assets.sounds[id].onloadeddata = function(){
_this.assetLoaded(); _this.assetLoaded();
}; };
assets.sounds[id].src = '/assets/audio/'+name;
assets.sounds[id].load();
}); });
$.ajax({ $.ajax({

View File

@ -13,10 +13,11 @@ function loadSong(selectedSong, autoPlayEnabled){
assets.sounds["bgm_songsel"].pause(); assets.sounds["bgm_songsel"].pause();
assets.sounds["bgm_songsel"].currentTime = 0; assets.sounds["bgm_songsel"].currentTime = 0;
assets.sounds["start"].play(); assets.sounds["start"].playAsset();
$("#assets").append("<img id='music-bg' src='/songs/"+_selectedSong.folder+"/bg.png' />"); $("#assets").append("<img id='music-bg' src='/songs/"+_selectedSong.folder+"/bg.png' />");
var audio = new Audio(); var audio = new Audio();
audio.muted = true;
audio.src = '/songs/'+_selectedSong.folder+'/main.mp3'; audio.src = '/songs/'+_selectedSong.folder+'/main.mp3';
audio.load(); audio.load();
@ -25,6 +26,15 @@ function loadSong(selectedSong, autoPlayEnabled){
_this.checkIfEverythingLoaded(); _this.checkIfEverythingLoaded();
}); });
audio.playAsset = function(){
try{
audio.muted = false;
audio.play()
}catch(e){
console.warn(e)
}
}
audio.onloadeddata = function(){ audio.onloadeddata = function(){
_musicLoaded=true; _musicLoaded=true;
assets.sounds["main-music"]=audio; assets.sounds["main-music"]=audio;

View File

@ -81,13 +81,13 @@ function Scoresheet(controller, score){
_this.setResults(); _this.setResults();
$("#song-select").click(function(){ $("#song-select").click(function(){
assets.sounds["don"].play(); assets.sounds["don"].playAsset();
bgm.pause(); bgm.pause();
controller.songSelection(); controller.songSelection();
}); });
$("#replay").click(function(){ $("#replay").click(function(){
assets.sounds["don"].play(); assets.sounds["don"].playAsset();
bgm.pause(); bgm.pause();
controller.restartSong(); controller.restartSong();
}); });
@ -96,7 +96,7 @@ function Scoresheet(controller, score){
} }
assets.sounds["results"].play(); assets.sounds["results"].playAsset();
bgm = new BufferedLoop( bgm = new BufferedLoop(
{url: '/assets/audio/bgm_result.ogg', duration: 0.847}, {url: '/assets/audio/bgm_result.ogg', duration: 0.847},

View File

@ -51,7 +51,7 @@ function SongSelect(){
_this.endPreview(); _this.endPreview();
assets.sounds["diffsel"].pause(); assets.sounds["diffsel"].pause();
assets.sounds["diffsel"].currentTime = 0; assets.sounds["diffsel"].currentTime = 0;
assets.sounds["don"].play(); assets.sounds["don"].playAsset();
clearInterval(menuLoop); clearInterval(menuLoop);
var difficultyElement = (e.target.className=="stars" || e.target.className=="diffname") ? e.target.parentElement : e.target; 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')) { if ($(".opened").length && $(".opened").attr('id') == $(this).attr('id')) {
_this.endPreview(); _this.endPreview();
bgm.play(); bgm.play();
assets.sounds["cancel"].play(); assets.sounds["cancel"].playAsset();
$(".difficulty").hide(); $(".difficulty").hide();
$(".opened").removeClass("opened", 300); $(".opened").removeClass("opened", 300);
assets.sounds["diffsel"].pause(); assets.sounds["diffsel"].pause();
assets.sounds["diffsel"].currentTime = 0; assets.sounds["diffsel"].currentTime = 0;
setTimeout(function(){ setTimeout(function(){
assets.sounds["song-select"].play(); assets.sounds["song-select"].playAsset();
}, 300); }, 300);
$('.songsel-title').fadeOut(200, function(){ $('.songsel-title').fadeOut(200, function(){
@ -100,11 +100,11 @@ function SongSelect(){
if(!$('.opened').length) { if(!$('.opened').length) {
_this.startPreview($(this).data('song-id'), $(this).data('preview')); _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"].pause();
assets.sounds["song-select"].currentTime = 0; assets.sounds["song-select"].currentTime = 0;
setTimeout(function(){ setTimeout(function(){
assets.sounds["diffsel"].play(); assets.sounds["diffsel"].playAsset();
}, 300); }, 300);
$('.songsel-title').fadeOut(200, function(){ $('.songsel-title').fadeOut(200, function(){
@ -114,7 +114,7 @@ function SongSelect(){
} else { } else {
_preview.pause(); _preview.pause();
_this.startPreview($(this).data('song-id'), $(this).data('preview'), false); _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(); bgm.play();
setTimeout(function(){ setTimeout(function(){
assets.sounds["song-select"].play(); assets.sounds["song-select"].playAsset();
}, 200); }, 200);
for(var i=0; i<assets.songs.length; i++){ for(var i=0; i<assets.songs.length; i++){

View File

@ -32,7 +32,7 @@ function Titlescreen(){
$("#screen").find("#title-screen").show(); $("#screen").find("#title-screen").show();
$(window).resize(_this.positionning); $(window).resize(_this.positionning);
assets.sounds["title"].play(); assets.sounds["title"].playAsset();
} }
@ -40,7 +40,7 @@ function Titlescreen(){
assets.sounds["title"].pause(); assets.sounds["title"].pause();
assets.sounds["title"].currentTime = 0; assets.sounds["title"].currentTime = 0;
assets.sounds["don"].play(); assets.sounds["don"].playAsset();
new SongSelect(); new SongSelect();
} }