Change some events, fix p2 sending gameend twice

- Fixed gameend being sent twice in p2
- Add `ready`, `loader-error`, and `song-select-random` events
- Fixed `session-start` not firing when invited, added event detail
- Fixed `language-change` being fired at startup
- Fixed `version-link` and `about-link` firing twice
- "#song=" will fire `song-select-difficulty`
- Removed `key-events` and `scoresheet-player2`, merged with `scoresheet` and made it more detailed
This commit is contained in:
LoveEevee 2019-02-15 01:10:34 +03:00
parent adc45cb652
commit e677f2f032
12 changed files with 41 additions and 18 deletions

View File

@ -152,8 +152,10 @@
return target.getElementsByTagName("a")[0]
}
linkButton(event){
this.getLink(event.currentTarget).click()
pageEvents.send("about-link", event)
if(event.target === event.currentTarget){
this.getLink(event.currentTarget).click()
pageEvents.send("about-link", event)
}
}
clean(){
cancelTouch = true

View File

@ -259,11 +259,5 @@ class Keyboard{
if(this.controller.multiplayer === 1){
pageEvents.remove(window, "beforeunload")
}
if(this.controller.multiplayer !== 2){
pageEvents.send("key-events", {
keyboard: this.keyboardEvents,
gamepad: this.gamepad.gamepadEvents
})
}
}
}

View File

@ -153,6 +153,7 @@ class Loader{
}
}))
var readyEvent = "normal"
var songId
var hashLower = location.hash.toLowerCase()
p2 = new P2Connection()
@ -160,6 +161,7 @@ class Loader{
var number = parseInt(location.hash.slice(6))
if(number > 0){
songId = number
readyEvent = "song-id"
}
}else if(location.hash.length === 6){
p2.hashLock = true
@ -167,10 +169,13 @@ class Loader{
p2.open()
pageEvents.add(p2, "message", response => {
if(response.type === "session"){
pageEvents.send("session-start", "invited")
readyEvent = "session-start"
resolve()
}else if(response.type === "gameend"){
p2.hash("")
p2.hashLock = false
readyEvent = "session-expired"
resolve()
}
})
@ -196,6 +201,7 @@ class Loader{
this.canvasTest.clean()
this.clean()
this.callback(songId)
pageEvents.send("ready", readyEvent)
})
}, this.errorMsg.bind(this))
@ -218,6 +224,7 @@ class Loader{
}
errorMsg(error){
console.error(error)
pageEvents.send("loader-error", error)
this.error = true
this.loaderPercentage.appendChild(document.createElement("br"))
this.loaderPercentage.appendChild(document.createTextNode("An error occurred, please refresh"))

View File

@ -18,7 +18,8 @@ class LoadSong{
pageEvents.send("load-song", {
selectedSong: selectedSong,
autoPlayEnabled: autoPlayEnabled,
multiplayer: multiplayer
multiplayer: multiplayer,
touchEnabled: touchEnabled
})
}
run(){

View File

@ -90,9 +90,11 @@ pageEvents.add(root, ["touchstart", "touchmove", "touchend"], event => {
})
var versionDiv = document.getElementById("version")
var versionLink = document.getElementById("version-link")
pageEvents.add(versionDiv, ["click", "touchend"], () => {
versionLink.click()
pageEvents.send("version-link")
pageEvents.add(versionDiv, ["click", "touchend"], event => {
if(event.target === versionDiv){
versionLink.click()
pageEvents.send("version-link")
}
})
resizeRoot()
setInterval(resizeRoot, 100)

View File

@ -128,7 +128,6 @@ class P2Connection{
for(var i in response.value){
this.results[i] = response.value[i].toString()
}
pageEvents.send("scoresheet-player2", this.results)
break
case "note":
this.notes.push(response.value)

View File

@ -61,8 +61,15 @@ class Scoresheet{
})
}
pageEvents.send("scoresheet", {
selectedSong: controller.selectedSong,
autoPlayEnabled: controller.autoPlayEnabled,
multiplayer: multiplayer,
touchEnabled: touchEnabled,
results: this.results,
multiplayer: multiplayer
p2results: multiplayer ? p2.results : null,
keyboardEvents: controller.keyboard.keyboardEvents,
gamepadEvents: controller.keyboard.gamepad.gamepadEvents,
touchEvents: controller.view.touchEvents
})
}
keyDown(event, code){

View File

@ -30,7 +30,7 @@ class Session{
}else if(response.type === "songsel"){
p2.clearMessage("users")
this.onEnd(false, true)
pageEvents.send("session-start")
pageEvents.send("session-start", "host")
}
})
p2.send("invite")

View File

@ -313,6 +313,9 @@ class SongSelect{
this.redraw()
pageEvents.send("song-select")
pageEvents.send("song-select-move", this.songs[this.selectedSong])
if(songIdIndex !== -1){
pageEvents.send("song-select-difficulty", this.songs[this.selectedSong])
}
}
keyDown(event, code){
@ -615,6 +618,7 @@ class SongSelect{
setTimeout(() => {
this.moveToSong(moveBy)
}, 200)
pageEvents.send("song-select-random")
}else if(currentSong.action === "tutorial"){
this.toTutorial()
}else if(currentSong.action === "about"){

View File

@ -15,7 +15,7 @@ class Titlescreen{
this.logo = new Logo()
}
this.lang = this.getLang()
this.setLang(allStrings[this.lang])
this.setLang(allStrings[this.lang], true)
if(songId){
this.goNext()
@ -106,7 +106,7 @@ class Titlescreen{
}
return "ja"
}
setLang(lang){
setLang(lang, initial){
strings = lang
loader.screen.style.fontFamily = strings.font
@ -129,7 +129,9 @@ class Titlescreen{
this.disclaimerCopyright.setAttribute("alt", strings.titleCopyright)
this.logo.updateSubtitle()
pageEvents.send("language-change", lang.id)
if(!initial){
pageEvents.send("language-change", lang.id)
}
}
addLangs(){
for(var i in allStrings){

View File

@ -74,6 +74,7 @@
this.nextBeat = 0
this.gogoTime = 0
this.drumroll = []
this.touchEvents = 0
this.beatInterval = this.controller.parsedSongData.beatInfo.beatInterval
this.font = strings.font
@ -1601,6 +1602,7 @@
this.touchNote("ka_r")
}
}
this.touchEvents++
}
}
}

View File

@ -210,6 +210,7 @@ async def connection(ws, path):
user["other_user"]["ws"].send(sent_msg1),
user["other_user"]["ws"].send(sent_msg2)
])
del user["other_user"]["other_user"]
del user["other_user"]
else:
# Other user disconnected
@ -304,6 +305,7 @@ async def connection(ws, path):
user["other_user"]["ws"].send(sent_msg1),
user["other_user"]["ws"].send(sent_msg2)
])
del user["other_user"]["other_user"]
del user["other_user"]
else:
# Other user disconnected
@ -324,6 +326,7 @@ async def connection(ws, path):
user["other_user"]["ws"].send(msgobj("gameend")),
user["other_user"]["ws"].send(status_event())
])
del user["other_user"]["other_user"]
if user["action"] == "waiting":
del server_status["waiting"][user["gameid"]]
await notify_status()