taiko-web/public/src/js/titlescreen.js

56 lines
1.4 KiB
JavaScript
Raw Normal View History

2018-09-18 00:37:59 +02:00
class Titlescreen{
constructor(){
loader.changePage("titlescreen")
this.titleScreen = document.getElementById("title-screen")
2018-10-09 08:59:36 +02:00
pageEvents.keyAdd(this, "all", "down", this.keyDown.bind(this))
pageEvents.add(this.titleScreen, "mousedown", this.onPressed.bind(this))
2018-10-05 19:03:59 +02:00
pageEvents.once(this.titleScreen, "touchstart").then(this.onPressed.bind(this))
2018-09-18 00:37:59 +02:00
assets.sounds["title"].play()
2018-09-26 20:30:57 +02:00
this.gamepad = new Gamepad({
2018-10-09 08:59:36 +02:00
"13": ["a", "b", "x", "y", "start", "ls", "rs"]
2018-10-08 22:32:25 +02:00
}, pressed => {
2018-09-26 20:30:57 +02:00
if(pressed){
this.onPressed()
}
})
2015-07-17 10:22:46 +02:00
}
2018-10-09 08:59:36 +02:00
keyDown(event, code){
if(!code){
code = event.keyCode
}
if(code == 13 || code == 32 || code == 86 || code == 66){
// Enter, Space, V, B
this.onPressed()
}
}
onPressed(event){
2018-10-09 08:59:36 +02:00
if(event){
if(event.type === "touchstart"){
event.preventDefault()
this.touched = true
}else if(event.type === "mousedown" && event.which !== 1){
return
}
}
2018-10-05 19:03:59 +02:00
this.titleScreen.style.cursor = "auto"
2018-09-18 00:37:59 +02:00
this.clean()
assets.sounds["don"].play()
2018-09-26 20:30:57 +02:00
setTimeout(this.goNext.bind(this), 500)
}
goNext(){
if(this.touched || localStorage.getItem("tutorial") === "true"){
new SongSelect(false, false, this.touched)
}else{
new Tutorial()
2018-09-18 00:37:59 +02:00
}
}
clean(){
2018-09-26 20:30:57 +02:00
this.gamepad.clean()
2018-09-18 00:37:59 +02:00
assets.sounds["title"].stop()
2018-10-09 08:59:36 +02:00
pageEvents.keyRemove(this, "all")
2018-10-05 19:03:59 +02:00
pageEvents.remove(this.titleScreen, "mousedown")
pageEvents.remove(this.titleScreen, "touchstart")
2018-09-18 00:37:59 +02:00
delete this.titleScreen
}
}