From e677f2f03205e48edc20e14a48e4faa0632096a8 Mon Sep 17 00:00:00 2001 From: LoveEevee Date: Fri, 15 Feb 2019 01:10:34 +0300 Subject: [PATCH] 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 --- public/src/js/about.js | 6 ++++-- public/src/js/keyboard.js | 6 ------ public/src/js/loader.js | 7 +++++++ public/src/js/loadsong.js | 3 ++- public/src/js/main.js | 8 +++++--- public/src/js/p2.js | 1 - public/src/js/scoresheet.js | 9 ++++++++- public/src/js/session.js | 2 +- public/src/js/songselect.js | 4 ++++ public/src/js/titlescreen.js | 8 +++++--- public/src/js/view.js | 2 ++ server.py | 3 +++ 12 files changed, 41 insertions(+), 18 deletions(-) diff --git a/public/src/js/about.js b/public/src/js/about.js index 069b007..1c3586d 100644 --- a/public/src/js/about.js +++ b/public/src/js/about.js @@ -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 diff --git a/public/src/js/keyboard.js b/public/src/js/keyboard.js index 399fb98..186c651 100644 --- a/public/src/js/keyboard.js +++ b/public/src/js/keyboard.js @@ -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 - }) - } } } diff --git a/public/src/js/loader.js b/public/src/js/loader.js index f1c9bf9..a171642 100644 --- a/public/src/js/loader.js +++ b/public/src/js/loader.js @@ -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")) diff --git a/public/src/js/loadsong.js b/public/src/js/loadsong.js index 45b69e2..6629afc 100644 --- a/public/src/js/loadsong.js +++ b/public/src/js/loadsong.js @@ -18,7 +18,8 @@ class LoadSong{ pageEvents.send("load-song", { selectedSong: selectedSong, autoPlayEnabled: autoPlayEnabled, - multiplayer: multiplayer + multiplayer: multiplayer, + touchEnabled: touchEnabled }) } run(){ diff --git a/public/src/js/main.js b/public/src/js/main.js index 85b9625..a63691e 100644 --- a/public/src/js/main.js +++ b/public/src/js/main.js @@ -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) diff --git a/public/src/js/p2.js b/public/src/js/p2.js index aa5e834..1f6f97e 100644 --- a/public/src/js/p2.js +++ b/public/src/js/p2.js @@ -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) diff --git a/public/src/js/scoresheet.js b/public/src/js/scoresheet.js index 3e1326a..1402b86 100644 --- a/public/src/js/scoresheet.js +++ b/public/src/js/scoresheet.js @@ -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){ diff --git a/public/src/js/session.js b/public/src/js/session.js index 9a7c2cf..8dfe8e6 100644 --- a/public/src/js/session.js +++ b/public/src/js/session.js @@ -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") diff --git a/public/src/js/songselect.js b/public/src/js/songselect.js index f029739..6dbe579 100644 --- a/public/src/js/songselect.js +++ b/public/src/js/songselect.js @@ -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"){ diff --git a/public/src/js/titlescreen.js b/public/src/js/titlescreen.js index beac5f3..642aab9 100644 --- a/public/src/js/titlescreen.js +++ b/public/src/js/titlescreen.js @@ -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){ diff --git a/public/src/js/view.js b/public/src/js/view.js index f612782..fa0c534 100644 --- a/public/src/js/view.js +++ b/public/src/js/view.js @@ -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++ } } } diff --git a/server.py b/server.py index 19ddd03..b4b65ca 100644 --- a/server.py +++ b/server.py @@ -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()