2018-09-18 06:37:59 +08:00
|
|
|
class Tutorial{
|
2022-02-11 22:28:22 +08:00
|
|
|
constructor(...args){
|
|
|
|
this.init(...args)
|
|
|
|
}
|
|
|
|
init(fromSongSel, songId){
|
2018-09-27 02:30:57 +08:00
|
|
|
this.fromSongSel = fromSongSel
|
Custom scripting, #song=, translations
- A song can be linked directly by adding "#song=<id>" to the url, replace `<id>` with the id in the database, after loading it jumps immediately jumps to the difficulty selection
- Added tutorial translations
- Fixed song preview not playing
- Use text fallback for the logo when there are no vectors
- Increased combo cache by 1 pixel
- A custom javascript file can be loaded from config.json by defining "custom_js" value
- Added lots of events to help writing custom js files: `version-link, title-screen, language-change, song-select, song-select-move, song-select-difficulty, song-select-back, about, about-link, tutorial, import-songs, import-songs-default, session, session-start, session-end, debug, load-song, load-song-player2, load-song-unfocused, load-song-cancel, load-song-error, game-start, key-events, p2-game-end, p2-disconnected, p2-abandoned, pause, unpause, pause-restart, pause-song-select, game-lag, scoresheet, scoresheet-player2`
- Event syntax example:
```js
addEventListener("game-start", event => {
console.log("game-start", event.detail)
})
```
2019-02-14 17:32:45 +08:00
|
|
|
this.songId = songId
|
2019-04-17 02:06:41 +08:00
|
|
|
loader.changePage("tutorial", true)
|
2018-09-18 06:37:59 +08:00
|
|
|
assets.sounds["bgm_setsume"].playLoop(0.1, false, 0, 1.054, 16.054)
|
2019-04-17 02:06:41 +08:00
|
|
|
this.endButton = this.getElement("view-end-button")
|
2018-10-06 21:24:23 +08:00
|
|
|
|
2019-04-17 02:06:41 +08:00
|
|
|
this.tutorialTitle = this.getElement("view-title")
|
2019-04-07 03:14:44 +08:00
|
|
|
this.tutorialDiv = document.createElement("div")
|
2019-04-17 02:06:41 +08:00
|
|
|
this.getElement("view-content").appendChild(this.tutorialDiv)
|
2022-02-18 04:50:07 +08:00
|
|
|
|
|
|
|
this.items = []
|
|
|
|
this.items.push(this.endButton)
|
|
|
|
this.selected = this.items.length - 1
|
|
|
|
|
2019-04-07 03:14:44 +08:00
|
|
|
this.setStrings()
|
|
|
|
|
2022-02-18 04:50:07 +08:00
|
|
|
pageEvents.add(this.endButton, ["mousedown", "touchstart"], this.onEnd.bind(this))
|
2019-04-17 02:06:41 +08:00
|
|
|
this.keyboard = new Keyboard({
|
2022-02-18 04:50:07 +08:00
|
|
|
confirm: ["enter", "space", "don_l", "don_r"],
|
|
|
|
previous: ["left", "up", "ka_l"],
|
|
|
|
next: ["right", "down", "ka_r"],
|
|
|
|
back: ["escape"]
|
|
|
|
}, this.keyPressed.bind(this))
|
2019-04-17 02:06:41 +08:00
|
|
|
this.gamepad = new Gamepad({
|
2022-02-18 04:50:07 +08:00
|
|
|
"confirm": ["b", "ls", "rs"],
|
|
|
|
"previous": ["u", "l", "lb", "lt", "lsu", "lsl"],
|
|
|
|
"next": ["d", "r", "rb", "rt", "lsd", "lsr"],
|
|
|
|
"back": ["start", "a"]
|
|
|
|
}, this.keyPressed.bind(this))
|
2019-04-17 02:06:41 +08:00
|
|
|
|
2019-04-07 03:14:44 +08:00
|
|
|
pageEvents.send("tutorial")
|
|
|
|
}
|
2019-04-17 02:06:41 +08:00
|
|
|
getElement(name){
|
|
|
|
return loader.screen.getElementsByClassName(name)[0]
|
|
|
|
}
|
2022-02-18 04:50:07 +08:00
|
|
|
keyPressed(pressed, name){
|
|
|
|
if(!pressed){
|
|
|
|
return
|
|
|
|
}
|
|
|
|
var selected = this.items[this.selected]
|
|
|
|
if(name === "confirm"){
|
|
|
|
if(selected === this.endButton){
|
|
|
|
this.onEnd()
|
|
|
|
}else{
|
|
|
|
this.getLink(selected).click()
|
|
|
|
assets.sounds["se_don"].play()
|
|
|
|
}
|
|
|
|
}else if(name === "previous" || name === "next"){
|
2022-02-18 05:06:50 +08:00
|
|
|
if(this.items.length >= 2){
|
|
|
|
selected.classList.remove("selected")
|
|
|
|
this.selected = this.mod(this.items.length, this.selected + (name === "next" ? 1 : -1))
|
|
|
|
this.items[this.selected].classList.add("selected")
|
|
|
|
assets.sounds["se_ka"].play()
|
|
|
|
}
|
2022-02-18 04:50:07 +08:00
|
|
|
}else if(name === "back"){
|
|
|
|
this.onEnd()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mod(length, index){
|
|
|
|
return ((index % length) + length) % length
|
|
|
|
}
|
|
|
|
onEnd(event){
|
|
|
|
var touched = false
|
|
|
|
if(event){
|
|
|
|
if(event.type === "touchstart"){
|
|
|
|
event.preventDefault()
|
|
|
|
touched = true
|
|
|
|
}else if(event.which !== 1){
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.clean()
|
|
|
|
assets.sounds["se_don"].play()
|
|
|
|
try{
|
|
|
|
localStorage.setItem("tutorial", "true")
|
|
|
|
}catch(e){}
|
|
|
|
setTimeout(() => {
|
|
|
|
new SongSelect(this.fromSongSel ? "tutorial" : false, false, touched, this.songId)
|
|
|
|
}, 500)
|
|
|
|
}
|
|
|
|
getLink(target){
|
|
|
|
return target.getElementsByTagName("a")[0]
|
|
|
|
}
|
|
|
|
linkButton(event){
|
|
|
|
if(event.target === event.currentTarget && (event.type === "touchstart" || event.which === 1)){
|
|
|
|
this.getLink(event.currentTarget).click()
|
|
|
|
assets.sounds["se_don"].play()
|
|
|
|
}
|
|
|
|
}
|
2019-04-07 03:14:44 +08:00
|
|
|
insertText(text, parent){
|
|
|
|
parent.appendChild(document.createTextNode(text))
|
|
|
|
}
|
|
|
|
insertKey(key, parent){
|
2020-12-04 18:52:35 +08:00
|
|
|
if(!Array.isArray(key)){
|
|
|
|
key = [key]
|
|
|
|
}
|
|
|
|
var join = true
|
|
|
|
for(var i = 0; i < key.length; i++){
|
|
|
|
if(key[i] === false){
|
|
|
|
join = false
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if(i !== 0){
|
|
|
|
if(join){
|
|
|
|
var span = document.createElement("span")
|
|
|
|
span.classList.add("key-join")
|
|
|
|
span.innerText = strings.tutorial.key.join
|
|
|
|
parent.appendChild(span)
|
|
|
|
}else{
|
|
|
|
parent.appendChild(document.createTextNode(strings.tutorial.key.or))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var kbd = document.createElement("kbd")
|
|
|
|
kbd.innerText = key[i]
|
|
|
|
parent.appendChild(kbd)
|
|
|
|
}
|
2019-04-07 03:14:44 +08:00
|
|
|
}
|
|
|
|
setStrings(){
|
|
|
|
this.tutorialTitle.innerText = strings.howToPlay
|
|
|
|
this.tutorialTitle.setAttribute("alt", strings.howToPlay)
|
|
|
|
this.endButton.innerText = strings.tutorial.ok
|
|
|
|
this.endButton.setAttribute("alt", strings.tutorial.ok)
|
|
|
|
this.tutorialDiv.innerHTML = ""
|
2019-04-06 03:53:51 +08:00
|
|
|
var kbdSettings = settings.getItem("keyboardSettings")
|
2020-12-04 18:52:35 +08:00
|
|
|
var pauseKey = [strings.tutorial.key.esc]
|
|
|
|
if(pageEvents.kbd.indexOf("q") === -1){
|
|
|
|
pauseKey.push(false)
|
|
|
|
pauseKey.push("Q")
|
|
|
|
}
|
2019-04-06 03:53:51 +08:00
|
|
|
var keys = [
|
|
|
|
kbdSettings.don_l[0].toUpperCase(),
|
|
|
|
kbdSettings.don_r[0].toUpperCase(),
|
|
|
|
kbdSettings.ka_l[0].toUpperCase(),
|
|
|
|
kbdSettings.ka_r[0].toUpperCase(),
|
2020-12-04 18:52:35 +08:00
|
|
|
pauseKey,
|
|
|
|
[strings.tutorial.key.shift, strings.tutorial.key.leftArrow],
|
|
|
|
[strings.tutorial.key.shift, strings.tutorial.key.rightArrow],
|
|
|
|
strings.tutorial.key.shift,
|
|
|
|
strings.tutorial.key.ctrl
|
2019-04-06 03:53:51 +08:00
|
|
|
]
|
2019-01-23 02:47:09 +08:00
|
|
|
var keyIndex = 0
|
|
|
|
strings.tutorial.basics.forEach(string => {
|
|
|
|
var par = document.createElement("p")
|
|
|
|
var stringKeys = string.split("%s")
|
|
|
|
stringKeys.forEach((stringKey, i) => {
|
|
|
|
if(i !== 0){
|
|
|
|
this.insertKey(keys[keyIndex++], par)
|
|
|
|
}
|
|
|
|
this.insertText(stringKey, par)
|
|
|
|
})
|
2019-04-07 03:14:44 +08:00
|
|
|
this.tutorialDiv.appendChild(par)
|
2019-01-23 02:47:09 +08:00
|
|
|
})
|
|
|
|
var par = document.createElement("p")
|
|
|
|
var span = document.createElement("span")
|
|
|
|
span.style.fontWeight = "bold"
|
|
|
|
span.innerText = strings.tutorial.otherControls
|
|
|
|
par.appendChild(span)
|
|
|
|
strings.tutorial.otherTutorial.forEach(string => {
|
|
|
|
par.appendChild(document.createElement("br"))
|
|
|
|
var stringKeys = string.split("%s")
|
|
|
|
stringKeys.forEach((stringKey, i) => {
|
|
|
|
if(i !== 0){
|
|
|
|
this.insertKey(keys[keyIndex++], par)
|
|
|
|
}
|
|
|
|
this.insertText(stringKey, par)
|
|
|
|
})
|
|
|
|
})
|
2019-04-07 03:14:44 +08:00
|
|
|
this.tutorialDiv.appendChild(par)
|
2018-09-18 06:37:59 +08:00
|
|
|
}
|
|
|
|
clean(){
|
2019-04-17 02:06:41 +08:00
|
|
|
this.keyboard.clean()
|
|
|
|
this.gamepad.clean()
|
|
|
|
pageEvents.remove(this.endButton, ["mousedown", "touchstart"])
|
2018-09-18 06:37:59 +08:00
|
|
|
assets.sounds["bgm_setsume"].stop()
|
2019-04-07 03:14:44 +08:00
|
|
|
delete this.tutorialTitle
|
2018-09-18 06:37:59 +08:00
|
|
|
delete this.endButton
|
2019-04-07 03:14:44 +08:00
|
|
|
delete this.tutorialDiv
|
2018-09-18 06:37:59 +08:00
|
|
|
}
|
|
|
|
}
|