2018-09-11 06:17:13 +08:00
|
|
|
class loadSong{
|
|
|
|
constructor(selectedSong, autoPlayEnabled){
|
|
|
|
this.selectedSong = selectedSong
|
|
|
|
this.autoPlayEnabled = autoPlayEnabled
|
|
|
|
this.songFilePath = "/songs/" + this.selectedSong.folder + "/" + this.selectedSong.difficulty
|
|
|
|
$("#screen").load("/src/views/loadsong.html", () => {
|
|
|
|
this.run()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
run(){
|
|
|
|
var id = this.selectedSong.folder
|
|
|
|
var promises = []
|
|
|
|
assets.sounds["start"].play()
|
2015-07-18 10:57:56 +08:00
|
|
|
|
2018-09-11 06:17:13 +08:00
|
|
|
var img = document.createElement("img")
|
|
|
|
promises.push(promiseLoad(img))
|
|
|
|
img.id = "music-bg"
|
|
|
|
img.src = "/songs/" + id + "/bg.png"
|
|
|
|
document.getElementById("assets").appendChild(img)
|
2015-07-17 16:22:46 +08:00
|
|
|
|
2018-09-11 06:17:13 +08:00
|
|
|
promises.push(new Promise((resolve, reject) => {
|
|
|
|
var songObj
|
|
|
|
assets.songs.forEach(song => {
|
|
|
|
if(song.id == id){
|
|
|
|
songObj = song
|
|
|
|
}
|
|
|
|
})
|
|
|
|
if(songObj.sound){
|
|
|
|
songObj.sound.gain = snd.musicGain
|
|
|
|
resolve()
|
|
|
|
}else{
|
|
|
|
snd.musicGain.load("/songs/" + id + "/main.mp3").then(sound => {
|
|
|
|
songObj.sound = sound
|
|
|
|
resolve()
|
|
|
|
}, reject)
|
2018-08-29 13:55:16 +08:00
|
|
|
}
|
2018-09-11 06:17:13 +08:00
|
|
|
}))
|
2018-08-29 13:55:16 +08:00
|
|
|
|
2018-09-11 06:17:13 +08:00
|
|
|
promises.push(ajax(this.songFilePath).then(data => {
|
|
|
|
this.songData = data.replace(/\0/g, "").split("\n")
|
|
|
|
}))
|
2015-07-17 16:22:46 +08:00
|
|
|
|
2018-09-11 06:17:13 +08:00
|
|
|
Promise.all(promises).then(() => {
|
|
|
|
$("#screen").load("/src/views/game.html", () => {
|
|
|
|
var taikoGame = new Controller(this.selectedSong, this.songData, this.autoPlayEnabled)
|
|
|
|
taikoGame.run()
|
|
|
|
})
|
|
|
|
}, () => {
|
|
|
|
alert("An error occurred, please refresh")
|
|
|
|
})
|
2015-07-17 16:22:46 +08:00
|
|
|
}
|
|
|
|
}
|