japanese-drum-game/public/src/js/titlescreen.js

103 lines
2.8 KiB
JavaScript
Raw Normal View History

2018-09-18 06:37:59 +08:00
class Titlescreen{
constructor(songId){
this.songId = songId
if(!songId){
loader.changePage("titlescreen", false)
this.titleScreen = document.getElementById("title-screen")
this.proceed = document.getElementById("title-proceed")
this.disclaimerText = document.getElementById("title-disclaimer-text")
this.disclaimerCopyright = document.getElementById("title-disclaimer-copyright")
this.logo = new Logo()
}
this.setLang(allStrings[settings.getItem("language")])
if(songId){
if(localStorage.getItem("tutorial") === "true"){
new SongSelect(false, false, this.touched, this.songId)
}else{
new SettingsView(false, true, this.songId)
}
}else{
pageEvents.add(this.titleScreen, ["mousedown", "touchstart"], event => {
if(event.type === "touchstart"){
event.preventDefault()
this.touched = true
}else if(event.type === "mousedown" && event.which !== 1){
return
}
this.onPressed(true)
})
assets.sounds["v_title"].play()
this.keyboard = new Keyboard({
confirm: ["enter", "space", "don_l", "don_r"]
}, this.onPressed.bind(this))
this.gamepad = new Gamepad({
2019-04-06 03:53:51 +08:00
confirm: ["a", "b", "x", "y", "start", "ls", "rs"]
}, this.onPressed.bind(this))
if(p2.session){
pageEvents.add(p2, "message", response => {
if(response.type === "songsel"){
this.goNext(true)
}
})
}
pageEvents.send("title-screen")
2018-11-02 06:05:18 +08:00
}
2015-07-17 16:22:46 +08:00
}
onPressed(pressed, name){
if(pressed){
this.titleScreen.style.cursor = "auto"
this.clean()
assets.sounds["se_don"].play()
this.goNext()
}
2018-09-27 02:30:57 +08:00
}
2018-11-02 06:05:18 +08:00
goNext(fromP2){
if(p2.session && !fromP2){
p2.send("songsel")
}else if(fromP2 || localStorage.getItem("tutorial") === "true"){
if(this.touched){
localStorage.setItem("tutorial", "true")
}
2018-11-02 06:05:18 +08:00
pageEvents.remove(p2, "message")
setTimeout(() => {
new SongSelect(false, false, this.touched, this.songId)
2018-11-02 06:05:18 +08:00
}, 500)
}else{
2018-11-02 06:05:18 +08:00
setTimeout(() => {
new SettingsView(this.touched, true, this.songId)
2018-11-02 06:05:18 +08:00
}, 500)
2018-09-18 06:37:59 +08:00
}
}
2019-04-06 18:19:10 +08:00
setLang(lang, noEvent){
settings.setLang(lang, true)
if(this.songId){
return
}
this.proceed.innerText = strings.titleProceed
this.proceed.setAttribute("alt", strings.titleProceed)
2019-01-28 19:43:18 +08:00
this.disclaimerText.innerText = strings.titleDisclaimer
this.disclaimerText.setAttribute("alt", strings.titleDisclaimer)
this.disclaimerCopyright.innerText = strings.titleCopyright
this.disclaimerCopyright.setAttribute("alt", strings.titleCopyright)
2019-01-28 09:57:18 +08:00
this.logo.updateSubtitle()
}
2018-09-18 06:37:59 +08:00
clean(){
this.keyboard.clean()
2018-09-27 02:30:57 +08:00
this.gamepad.clean()
2019-01-28 09:57:18 +08:00
this.logo.clean()
2019-02-04 17:14:42 +08:00
assets.sounds["v_title"].stop()
2018-10-13 02:04:28 +08:00
pageEvents.remove(this.titleScreen, ["mousedown", "touchstart"])
2018-09-18 06:37:59 +08:00
delete this.titleScreen
delete this.proceed
2019-01-28 19:50:22 +08:00
delete this.titleDisclaimer
delete this.titleCopyright
2018-09-18 06:37:59 +08:00
}
}