2018-09-18 06:37:59 +08:00
|
|
|
class Titlescreen{
|
|
|
|
constructor(){
|
2019-01-16 20:33:42 +08:00
|
|
|
loader.changePage("titlescreen", false)
|
2019-01-21 23:47:22 +08:00
|
|
|
|
2018-09-18 06:37:59 +08:00
|
|
|
this.titleScreen = document.getElementById("title-screen")
|
2019-01-21 23:47:22 +08:00
|
|
|
this.proceed = document.getElementById("title-proceed")
|
|
|
|
this.langDropdown = document.getElementById("lang-dropdown")
|
2019-01-22 03:08:02 +08:00
|
|
|
this.langId = document.getElementById("lang-id")
|
2019-01-21 23:47:22 +08:00
|
|
|
|
|
|
|
this.lang = this.getLang()
|
|
|
|
this.setLang(allStrings[this.lang])
|
|
|
|
this.addLangs()
|
2019-01-05 15:44:28 +08:00
|
|
|
|
2018-10-09 14:59:36 +08:00
|
|
|
pageEvents.keyAdd(this, "all", "down", this.keyDown.bind(this))
|
2018-10-13 02:04:28 +08:00
|
|
|
pageEvents.add(this.titleScreen, ["mousedown", "touchstart"], this.onPressed.bind(this))
|
2019-01-21 23:47:22 +08:00
|
|
|
pageEvents.add(this.langDropdown, "change", this.langChange.bind(this))
|
|
|
|
|
2018-09-18 06:37:59 +08:00
|
|
|
assets.sounds["title"].play()
|
2018-09-27 02:30:57 +08:00
|
|
|
this.gamepad = new Gamepad({
|
2018-10-09 14:59:36 +08:00
|
|
|
"13": ["a", "b", "x", "y", "start", "ls", "rs"]
|
2018-10-09 04:32:25 +08:00
|
|
|
}, pressed => {
|
2018-09-27 02:30:57 +08:00
|
|
|
if(pressed){
|
|
|
|
this.onPressed()
|
|
|
|
}
|
|
|
|
})
|
2018-11-02 06:05:18 +08:00
|
|
|
if(p2.session){
|
|
|
|
pageEvents.add(p2, "message", response => {
|
|
|
|
if(response.type === "songsel"){
|
|
|
|
this.goNext(true)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2015-07-17 16:22:46 +08:00
|
|
|
}
|
2019-01-21 23:47:22 +08:00
|
|
|
|
2018-10-09 14:59:36 +08:00
|
|
|
keyDown(event, code){
|
2019-01-21 23:47:22 +08:00
|
|
|
if(event && event.target === this.langDropdown){
|
|
|
|
return
|
|
|
|
}
|
2018-10-09 14:59:36 +08:00
|
|
|
if(!code){
|
|
|
|
code = event.keyCode
|
|
|
|
}
|
2018-10-23 22:51:55 +08:00
|
|
|
if(code == 13 || code == 32 || code == 70 || code == 74){
|
|
|
|
// Enter, Space, F, J
|
2018-10-09 14:59:36 +08:00
|
|
|
this.onPressed()
|
|
|
|
}
|
|
|
|
}
|
2018-10-06 21:24:23 +08:00
|
|
|
onPressed(event){
|
2018-10-09 14:59:36 +08:00
|
|
|
if(event){
|
|
|
|
if(event.type === "touchstart"){
|
|
|
|
event.preventDefault()
|
|
|
|
this.touched = true
|
|
|
|
}else if(event.type === "mousedown" && event.which !== 1){
|
|
|
|
return
|
|
|
|
}
|
2018-10-06 21:24:23 +08:00
|
|
|
}
|
2018-10-06 01:03:59 +08:00
|
|
|
this.titleScreen.style.cursor = "auto"
|
2018-09-18 06:37:59 +08:00
|
|
|
this.clean()
|
|
|
|
assets.sounds["don"].play()
|
2018-11-02 06:05:18 +08:00
|
|
|
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 || this.touched || localStorage.getItem("tutorial") === "true"){
|
|
|
|
pageEvents.remove(p2, "message")
|
|
|
|
setTimeout(() => {
|
|
|
|
new SongSelect(false, false, this.touched)
|
|
|
|
}, 500)
|
2018-10-06 23:09:57 +08:00
|
|
|
}else{
|
2018-11-02 06:05:18 +08:00
|
|
|
setTimeout(() => {
|
|
|
|
new Tutorial()
|
|
|
|
}, 500)
|
2018-09-18 06:37:59 +08:00
|
|
|
}
|
|
|
|
}
|
2019-01-21 23:47:22 +08:00
|
|
|
|
|
|
|
getLang(){
|
|
|
|
if(localStorage.lang && localStorage.lang in allStrings){
|
|
|
|
return localStorage.lang
|
|
|
|
}
|
|
|
|
if("languages" in navigator){
|
|
|
|
var userLang = navigator.languages.slice()
|
|
|
|
userLang.unshift(navigator.language)
|
|
|
|
for(var i in userLang){
|
|
|
|
for(var j in allStrings){
|
|
|
|
if(allStrings[j].regex.test(userLang[i])){
|
|
|
|
return j
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "ja"
|
|
|
|
}
|
|
|
|
setLang(lang){
|
|
|
|
strings = lang
|
|
|
|
this.proceed.innerText = strings.titleProceed
|
|
|
|
this.proceed.setAttribute("alt", strings.titleProceed)
|
2019-01-22 03:08:02 +08:00
|
|
|
this.langId.innerText = strings.id.toUpperCase()
|
|
|
|
this.langId.setAttribute("alt", strings.id.toUpperCase())
|
2019-01-21 23:47:22 +08:00
|
|
|
loader.screen.style.fontFamily = strings.font
|
|
|
|
loader.screen.style.fontWeight = strings.font === "Microsoft YaHei, sans-serif" ? "bold" : ""
|
|
|
|
}
|
|
|
|
addLangs(){
|
|
|
|
for(var i in allStrings){
|
|
|
|
var option = document.createElement("option")
|
|
|
|
option.value = i
|
|
|
|
if(i === this.lang){
|
|
|
|
option.selected = true
|
|
|
|
}
|
|
|
|
option.appendChild(document.createTextNode(allStrings[i].name))
|
|
|
|
this.langDropdown.appendChild(option)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
langChange(){
|
|
|
|
this.lang = this.langDropdown.value
|
|
|
|
localStorage.lang = this.lang
|
|
|
|
this.setLang(allStrings[this.lang])
|
|
|
|
}
|
|
|
|
|
2018-09-18 06:37:59 +08:00
|
|
|
clean(){
|
2018-09-27 02:30:57 +08:00
|
|
|
this.gamepad.clean()
|
2018-09-18 06:37:59 +08:00
|
|
|
assets.sounds["title"].stop()
|
2018-10-09 14:59:36 +08:00
|
|
|
pageEvents.keyRemove(this, "all")
|
2018-10-13 02:04:28 +08:00
|
|
|
pageEvents.remove(this.titleScreen, ["mousedown", "touchstart"])
|
2019-01-21 23:47:22 +08:00
|
|
|
pageEvents.remove(this.langDropdown, "change")
|
2018-09-18 06:37:59 +08:00
|
|
|
delete this.titleScreen
|
2019-01-21 23:47:22 +08:00
|
|
|
delete this.proceed
|
|
|
|
delete this.langDropdown
|
2018-09-18 06:37:59 +08:00
|
|
|
}
|
|
|
|
}
|