2018-11-02 06:05:18 +08:00
|
|
|
class Session{
|
|
|
|
constructor(touchEnabled){
|
|
|
|
this.touchEnabled = touchEnabled
|
2019-01-16 20:33:42 +08:00
|
|
|
loader.changePage("session", true)
|
2019-04-17 02:06:41 +08:00
|
|
|
this.endButton = this.getElement("view-end-button")
|
2018-11-02 06:05:18 +08:00
|
|
|
if(touchEnabled){
|
2019-04-17 02:06:41 +08:00
|
|
|
this.getElement("view-outer").classList.add("touch-enabled")
|
2018-11-02 06:05:18 +08:00
|
|
|
}
|
|
|
|
this.sessionInvite = document.getElementById("session-invite")
|
|
|
|
|
2019-04-17 02:06:41 +08:00
|
|
|
var tutorialTitle = this.getElement("view-title")
|
2019-01-23 02:47:09 +08:00
|
|
|
tutorialTitle.innerText = strings.session.multiplayerSession
|
|
|
|
tutorialTitle.setAttribute("alt", strings.session.multiplayerSession)
|
|
|
|
this.sessionInvite.parentNode.insertBefore(document.createTextNode(strings.session.linkTutorial), this.sessionInvite)
|
|
|
|
this.endButton.innerText = strings.session.cancel
|
|
|
|
this.endButton.setAttribute("alt", strings.session.cancel)
|
|
|
|
|
2018-11-02 06:05:18 +08:00
|
|
|
pageEvents.add(window, ["mousedown", "touchstart"], this.mouseDown.bind(this))
|
2019-04-17 02:06:41 +08:00
|
|
|
this.keyboard = new Keyboard({
|
|
|
|
confirm: ["esc"]
|
|
|
|
}, this.keyPress.bind(this))
|
2018-11-02 06:05:18 +08:00
|
|
|
this.gamepad = new Gamepad({
|
2019-04-17 02:06:41 +08:00
|
|
|
confirm: ["start", "b", "ls", "rs"]
|
|
|
|
}, this.keyPress.bind(this))
|
2018-11-02 06:05:18 +08:00
|
|
|
|
|
|
|
p2.hashLock = true
|
|
|
|
pageEvents.add(p2, "message", response => {
|
|
|
|
if(response.type === "invite"){
|
|
|
|
this.sessionInvite.innerText = location.origin + location.pathname + "#" + response.value
|
|
|
|
p2.hash(response.value)
|
|
|
|
}else if(response.type === "songsel"){
|
|
|
|
p2.clearMessage("users")
|
2019-04-17 02:06:41 +08:00
|
|
|
this.onEnd(true)
|
2019-02-15 06:10:34 +08:00
|
|
|
pageEvents.send("session-start", "host")
|
2018-11-02 06:05:18 +08:00
|
|
|
}
|
|
|
|
})
|
2020-03-13 10:34:54 +08:00
|
|
|
p2.send("invite", {
|
|
|
|
id: null,
|
|
|
|
name: account.loggedIn ? account.displayName : null
|
|
|
|
})
|
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
|
|
|
pageEvents.send("session")
|
2018-11-02 06:05:18 +08:00
|
|
|
}
|
2019-04-17 02:06:41 +08:00
|
|
|
getElement(name){
|
|
|
|
return loader.screen.getElementsByClassName(name)[0]
|
|
|
|
}
|
2018-11-02 06:05:18 +08:00
|
|
|
mouseDown(event){
|
2019-04-06 03:53:51 +08:00
|
|
|
if(event.type === "mousedown" && event.which !== 1){
|
|
|
|
return
|
|
|
|
}
|
2018-11-02 06:05:18 +08:00
|
|
|
if(event.target === this.sessionInvite){
|
|
|
|
this.sessionInvite.focus()
|
|
|
|
}else{
|
|
|
|
getSelection().removeAllRanges()
|
|
|
|
this.sessionInvite.blur()
|
|
|
|
}
|
|
|
|
if(event.target === this.endButton){
|
|
|
|
this.onEnd()
|
|
|
|
}
|
|
|
|
}
|
2019-04-17 02:06:41 +08:00
|
|
|
keyPress(pressed){
|
|
|
|
if(pressed){
|
|
|
|
this.onEnd()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
onEnd(fromP2){
|
2018-11-02 06:05:18 +08:00
|
|
|
if(!p2.session){
|
|
|
|
p2.send("leave")
|
|
|
|
p2.hash("")
|
|
|
|
p2.hashLock = false
|
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
|
|
|
pageEvents.send("session-cancel")
|
2018-11-02 06:05:18 +08:00
|
|
|
}else if(!fromP2){
|
|
|
|
return p2.send("songsel")
|
|
|
|
}
|
|
|
|
this.clean()
|
2019-02-04 17:14:42 +08:00
|
|
|
assets.sounds["se_don"].play()
|
2018-11-02 06:05:18 +08:00
|
|
|
setTimeout(() => {
|
|
|
|
new SongSelect(false, false, this.touchEnabled)
|
|
|
|
}, 500)
|
|
|
|
}
|
|
|
|
clean(){
|
2019-04-17 02:06:41 +08:00
|
|
|
this.keyboard.clean()
|
2018-11-02 06:05:18 +08:00
|
|
|
this.gamepad.clean()
|
|
|
|
pageEvents.remove(window, ["mousedown", "touchstart"])
|
2018-12-16 03:13:16 +08:00
|
|
|
pageEvents.remove(p2, "message")
|
2018-11-02 06:05:18 +08:00
|
|
|
delete this.endButton
|
|
|
|
delete this.sessionInvite
|
|
|
|
}
|
|
|
|
}
|