2015-07-17 16:22:46 +08:00
|
|
|
function loadSong(selectedSong){
|
|
|
|
|
|
|
|
var _this = this;
|
|
|
|
var _selectedSong=selectedSong;
|
|
|
|
var _bgLoaded=false;
|
|
|
|
var _musicLoaded=false;
|
|
|
|
var _songDataLoaded=false;
|
|
|
|
var _songFilePath = '/songs/'+_selectedSong.folder+'/'+_selectedSong.difficulty;
|
|
|
|
var _songData;
|
|
|
|
|
|
|
|
this.run = function(){
|
|
|
|
|
2018-08-06 18:13:01 +08:00
|
|
|
assets.sounds["bgm_songsel"].pause();
|
|
|
|
assets.sounds["bgm_songsel"].currentTime = 0;
|
|
|
|
|
2015-07-18 12:25:38 +08:00
|
|
|
assets.sounds["start"].play();
|
2015-07-17 16:22:46 +08:00
|
|
|
$("#assets").append("<img id='music-bg' src='/songs/"+_selectedSong.folder+"/bg.png' />");
|
|
|
|
|
2015-07-18 10:57:56 +08:00
|
|
|
var audio = new Audio();
|
|
|
|
audio.src = '/songs/'+_selectedSong.folder+'/'+_selectedSong.title+'.mp3';
|
|
|
|
audio.load();
|
|
|
|
|
2015-07-17 16:22:46 +08:00
|
|
|
$("#music-bg").load(function(){
|
|
|
|
_bgLoaded=true;
|
|
|
|
_this.checkIfEverythingLoaded();
|
|
|
|
});
|
|
|
|
|
2015-07-18 10:57:56 +08:00
|
|
|
audio.onloadeddata = function(){
|
2015-07-17 16:22:46 +08:00
|
|
|
_musicLoaded=true;
|
2015-07-18 10:57:56 +08:00
|
|
|
assets.sounds["main-music"]=audio;
|
2015-07-17 16:22:46 +08:00
|
|
|
_this.checkIfEverythingLoaded();
|
2015-07-18 10:57:56 +08:00
|
|
|
};
|
2015-07-17 16:22:46 +08:00
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
url : _songFilePath,
|
|
|
|
dataType: "text",
|
|
|
|
success : function (data) {
|
|
|
|
_songData = data.split("\n");
|
|
|
|
_songDataLoaded=true;
|
|
|
|
_this.checkIfEverythingLoaded();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
this.checkIfEverythingLoaded = function(){
|
|
|
|
if(_musicLoaded && _songDataLoaded && _bgLoaded){
|
|
|
|
$("#screen").load("/src/views/game.html", function(){
|
|
|
|
var taikoGame = new Controller(_selectedSong, _songData);
|
|
|
|
taikoGame.run();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$("#screen").load("/src/views/loadsong.html", _this.run);
|
|
|
|
}
|