From b053dffec11713896e8194d64c6866f6f3d82a30 Mon Sep 17 00:00:00 2001 From: LoveEevee Date: Thu, 27 Sep 2018 00:12:50 +0300 Subject: [PATCH] Added song select music, more keys --- public/src/js/assets.js | 1 + public/src/js/game.js | 8 ++++++-- public/src/js/keyboard.js | 29 +++++++++++++++++++++-------- public/src/js/scoresheet.js | 8 ++++---- public/src/js/songselect.js | 21 ++++++++++++++++----- 5 files changed, 48 insertions(+), 19 deletions(-) diff --git a/public/src/js/assets.js b/public/src/js/assets.js index 347d3f4..6ef130c 100644 --- a/public/src/js/assets.js +++ b/public/src/js/assets.js @@ -91,6 +91,7 @@ var assets = { "renda.ogg" ], "audioMusic": [ + "bgm_songsel.ogg", "bgm_result.ogg", "bgm_setsume.ogg" ], diff --git a/public/src/js/game.js b/public/src/js/game.js index 1c9ec94..d537390 100644 --- a/public/src/js/game.js +++ b/public/src/js/game.js @@ -351,8 +351,12 @@ class Game{ } } getAccurateTime(){ - var currentDate = new Date() - return currentDate.getTime() - this.startDate.getTime() - this.elapsedTimeSincePause + if(this.isPaused()){ + return this.getElapsedTime().ms + }else{ + var currentDate = new Date() + return currentDate.getTime() - this.startDate.getTime() - this.elapsedTimeSincePause + } } getCircles(){ return this.songData.circles diff --git a/public/src/js/keyboard.js b/public/src/js/keyboard.js index 73ca1dd..b1f24e9 100644 --- a/public/src/js/keyboard.js +++ b/public/src/js/keyboard.js @@ -91,7 +91,7 @@ class Keyboard{ var ms = this.game.getAccurateTime() this.gamepadMenu.play((pressed, keyCode) => { if(pressed){ - if(this.game.isPaused()){ + if(paused){ if(keyCode === "cancel"){ return setTimeout(() => { this.controller.togglePauseMenu() @@ -110,17 +110,30 @@ class Keyboard{ this.controller.togglePauseMenu() }) if(this.game.isPaused()){ - this.checkKey(this.kbd["previous"], "menu", () => { + var moveMenuMinus = () => { moveMenu = -1 - }) - this.checkKey(this.kbd["next"], "menu", () => { + } + var moveMenuPlus = () => { moveMenu = 1 - }) - this.checkKey(this.kbd["confirm"], "menu", () => { + } + var moveMenuConfirm = () => { setTimeout(() => { - document.getElementsByClassName("selected")[0].click() + var selected = document.getElementsByClassName("selected")[0] + if(selected){ + selected.click() + } }, 200) - }) + for(var key in this.keyTime){ + this.keyTime[key] = null + } + } + this.checkKey(this.kbd["previous"], "menu", moveMenuMinus) + this.checkKey(this.kbd["ka_l"], "menu", moveMenuMinus) + this.checkKey(this.kbd["next"], "menu", moveMenuPlus) + this.checkKey(this.kbd["ka_r"], "menu", moveMenuPlus) + this.checkKey(this.kbd["confirm"], "menu", moveMenuConfirm) + this.checkKey(this.kbd["don_l"], "menu", moveMenuConfirm) + this.checkKey(this.kbd["don_r"], "menu", moveMenuConfirm) } if(moveMenu){ assets.sounds["ka"].play() diff --git a/public/src/js/scoresheet.js b/public/src/js/scoresheet.js index b225d98..2393077 100644 --- a/public/src/js/scoresheet.js +++ b/public/src/js/scoresheet.js @@ -116,11 +116,11 @@ class Scoresheet{ code = event.keyCode } var selected = this.elem("selected", this.scoresheet) - if(code == 13){ - // Enter + if(code == 13 || code == 32 || code == 86 || code == 66){ + // Enter, Space, V, B selected.click() - }else if(code == 37 || code == 39){ - // Left, Right + }else if(code == 37 || code == 39 || code == 67 || code == 78){ + // Left, Right, C, N selected.classList.remove("selected") var next = selected.nextElementSibling if(!next){ diff --git a/public/src/js/songselect.js b/public/src/js/songselect.js index 21a4c85..cc13cd8 100644 --- a/public/src/js/songselect.js +++ b/public/src/js/songselect.js @@ -177,7 +177,9 @@ class SongSelect{ this.selectedSong = 0 this.selectedDiff = 0 - if(fromTutorial){ + assets.sounds["bgm_songsel"].playLoop(0.1, false, 0, 1.442, 3.506) + + if(fromTutorial || !"selectedSong" in localStorage){ this.selectedSong = this.songs.findIndex(song => song.action === "tutorial") }else{ if("selectedSong" in localStorage){ @@ -636,8 +638,8 @@ class SongSelect{ if(this.previewing !== null){ this.endPreview() } - }else if(screen !== "title"){ - if(this.previewing !== this.selectedSong){ + }else if(screen !== "title" && ms > this.state.moveMS + 100){ + if(this.previewing !== this.selectedSong && "id" in this.songs[this.selectedSong]){ this.startPreview() } } @@ -1478,7 +1480,7 @@ class SongSelect{ var currentSong = this.songs[this.selectedSong] var id = currentSong.id var prvTime = currentSong.preview - this.endPreview() + this.endPreview(true) if("id" in currentSong){ var startLoad = this.getMS() @@ -1508,13 +1510,17 @@ class SongSelect{ } } previewLoaded(startLoad, prvtime){ + snd.musicGain.fadeOut(0.4) var endLoad = this.getMS() var difference = endLoad - startLoad var minDelay = 300 var delay = minDelay - Math.min(minDelay, difference) this.preview.playLoop(delay / 1000, false, prvtime / 1000) } - endPreview() { + endPreview(noFadeIn){ + if(!noFadeIn){ + snd.musicGain.fadeIn(0.4) + } this.previewId++ this.previewing = null if(this.preview){ @@ -1559,6 +1565,11 @@ class SongSelect{ } clean(){ + assets.sounds["bgm_songsel"].stop() + snd.musicGain.fadeIn() + setTimeout(() => { + snd.musicGain.fadeIn() + }, 500) this.redrawRunning = false this.endPreview() pageEvents.keyRemove(this, "all")