From 7ee8773e61b8dd2d6f50e4283d048a9506b003f5 Mon Sep 17 00:00:00 2001 From: LoveEevee Date: Wed, 6 Mar 2019 00:48:30 +0300 Subject: [PATCH] View: Fix donbg scrolling - All metadata fields in imported TJA files are now optional - Added new metadata fields: `TITLEEN` and `SUBTITLEEN` (`EN` can be any language id from strings.js) --- public/src/css/game.css | 3 ++ public/src/js/canvasdraw.js | 8 +++--- public/src/js/controller.js | 4 ++- public/src/js/game.js | 9 ++++-- public/src/js/importsongs.js | 53 +++++++++++++++++++++++++----------- public/src/js/loadsong.js | 14 ++++++---- public/src/js/parsetja.js | 15 ++++------ public/src/js/songselect.js | 8 +++--- public/src/js/view.js | 4 +++ 9 files changed, 75 insertions(+), 43 deletions(-) diff --git a/public/src/css/game.css b/public/src/css/game.css index 2944e82..f8b7214 100644 --- a/public/src/css/game.css +++ b/public/src/css/game.css @@ -94,3 +94,6 @@ z-index: 2; transition: 1s background-color linear; } +.fix-animations *{ + animation: none !important; +} diff --git a/public/src/js/canvasdraw.js b/public/src/js/canvasdraw.js index 7733c3d..97d3afd 100644 --- a/public/src/js/canvasdraw.js +++ b/public/src/js/canvasdraw.js @@ -48,9 +48,9 @@ this.regex = { comma: /[,.]/, ideographicComma: /[、。]/, - apostrophe: /['']/, + apostrophe: /[''’]/, degree: /[゚°]/, - brackets: /[\((\))\[\]「」『』【】]/, + brackets: /[\((\))\[\]「」『』【】::;;]/, tilde: /[\--~~〜_]/, tall: /[bbddffgghhj-lj-ltt♪]/, i: /[ii]/, @@ -625,8 +625,6 @@ drawn.push({text: symbol, x: -2, y: 0, w: 20, scale: [0.6, 0.5]}) }else if(symbol === " "){ drawn.push({text: symbol, x: 0, y: 0, w: 10}) - }else if(symbol === "'"){ - drawn.push({text: ",", x: 0, y: -15, w: 7, scale: [1, 0.7]}) }else if(symbol === '"'){ drawn.push({text: symbol, x: 2, y: 0, w: 10}) }else if(symbol === "∀"){ @@ -637,6 +635,8 @@ } }else if(symbol === "."){ drawn.push({text: symbol, x: -9, y: 0, w: 37}) + }else if(r.apostrophe.test(symbol)){ + drawn.push({text: ",", x: 0, y: -15, w: 7, scale: [1, 0.7]}) }else if(r.comma.test(symbol)){ // Comma, full stop if(bold){ diff --git a/public/src/js/controller.js b/public/src/js/controller.js index 1c33b39..d0bc63b 100644 --- a/public/src/js/controller.js +++ b/public/src/js/controller.js @@ -68,7 +68,9 @@ class Controller{ } stopMainLoop(){ this.mainLoopRunning = false - this.mainAsset.stop() + if(this.mainAsset){ + this.mainAsset.stop() + } if(this.multiplayer !== 2){ clearInterval(this.gameInterval) } diff --git a/public/src/js/game.js b/public/src/js/game.js index 558b095..ceabf3f 100644 --- a/public/src/js/game.js +++ b/public/src/js/game.js @@ -465,7 +465,8 @@ class Game{ var started = this.fadeOutStarted if(started){ var ms = this.elapsedTime - var musicDuration = this.controller.mainAsset.duration * 1000 - this.controller.offset + var duration = this.mainAsset ? this.mainAsset.duration : 0 + var musicDuration = duration * 1000 - this.controller.offset if(this.musicFadeOut === 0){ if(this.controller.multiplayer === 1){ p2.send("gameresults", this.getGlobalScore()) @@ -491,7 +492,7 @@ class Game{ playMainMusic(){ var ms = this.elapsedTime + this.controller.offset if(!this.mainMusicPlaying && (!this.fadeOutStarted || ms < this.fadeOutStarted + 1600)){ - if(this.controller.multiplayer !== 2){ + if(this.controller.multiplayer !== 2 && this.mainAsset){ this.mainAsset.play((ms < 0 ? -ms : 0) / 1000, false, Math.max(0, ms / 1000)) } this.mainMusicPlaying = true @@ -502,7 +503,9 @@ class Game{ assets.sounds["se_pause"].play() this.paused = true this.latestDate = Date.now() - this.mainAsset.stop() + if(this.mainAsset){ + this.mainAsset.stop() + } this.mainMusicPlaying = false this.view.pauseMove(0, true) this.view.gameDiv.classList.add("game-paused") diff --git a/public/src/js/importsongs.js b/public/src/js/importsongs.js index 374908f..5040c92 100644 --- a/public/src/js/importsongs.js +++ b/public/src/js/importsongs.js @@ -184,25 +184,26 @@ id: index + 1, type: "tja", chart: data, - stars: [] + stars: [], + music: "muted" } + var titleLang = {} + var subtitleLang = {} var dir = file.webkitRelativePath.toLowerCase() dir = dir.slice(0, dir.lastIndexOf("/") + 1) var hasCategory = false for(var diff in tja.metadata){ var meta = tja.metadata[diff] - songObj.title = songObj.title_en = meta.title || file.name.slice(0, file.name.lastIndexOf(".")) + songObj.title = meta.title || file.name.slice(0, file.name.lastIndexOf(".")) var subtitle = meta.subtitle || "" - if(subtitle.startsWith("--")){ - subtitle = subtitle.slice(2) + if(subtitle.startsWith("--") || subtitle.startsWith("++")){ + subtitle = subtitle.slice(2).trim() } - songObj.subtitle = songObj.subtitle_en = subtitle + songObj.subtitle = subtitle songObj.preview = meta.demostart || 0 - if(meta.level){ - songObj.stars[this.courseTypes[diff]] = meta.level + (meta.branch ? " B" : "") - } + songObj.stars[this.courseTypes[diff]] = (meta.level || "0") + (meta.branch ? " B" : "") if(meta.wave){ - songObj.music = this.otherFiles[dir + meta.wave.toLowerCase()] + songObj.music = this.otherFiles[dir + meta.wave.toLowerCase()] || songObj.music } if(meta.genre){ songObj.category = this.categories[meta.genre.toLowerCase()] || meta.genre @@ -210,11 +211,33 @@ if(meta.taikowebskin){ songObj.song_skin = this.getSkin(dir, meta.taikowebskin) } + for(var id in allStrings){ + if(meta["title" + id]){ + titleLang[id] = meta["title" + id] + } + if(meta["subtitle" + id]){ + subtitleLang[id] = meta["subtitle" + id] + } + } + } + var titleLangArray = [] + for(var id in titleLang){ + titleLangArray.push(id + " " + titleLang[id]) + } + if(titleLangArray.length !== 0){ + songObj.title_lang = titleLangArray.join("\n") + } + var subtitleLangArray = [] + for(var id in subtitleLang){ + subtitleLangArray.push(id + " " + subtitleLang[id]) + } + if(subtitleLangArray.length !== 0){ + songObj.subtitle_lang = subtitleLangArray.join("\n") } if(!songObj.category){ songObj.category = category || this.getCategory(file) } - if(songObj.music && songObj.stars.filter(star => star).length !== 0){ + if(songObj.stars.length !== 0){ this.songs[index] = songObj } }).catch(() => {}) @@ -237,10 +260,10 @@ type: "osu", chart: data, subtitle: osu.metadata.ArtistUnicode || osu.metadata.Artist, - subtitle_en: osu.metadata.Artist || osu.metadata.ArtistUnicode, + subtitle_lang: osu.metadata.Artist || osu.metadata.ArtistUnicode, preview: osu.generalInfo.PreviewTime / 1000, stars: [null, null, null, parseInt(osu.difficulty.overallDifficulty) || 1], - music: this.otherFiles[dir + osu.generalInfo.AudioFilename.toLowerCase()] + music: this.otherFiles[dir + osu.generalInfo.AudioFilename.toLowerCase()] || "muted" } var filename = file.name.slice(0, file.name.lastIndexOf(".")) var title = osu.metadata.TitleUnicode || osu.metadata.Title @@ -251,13 +274,11 @@ suffix = " " + matches[0] } songObj.title = title + suffix - songObj.title_en = (osu.metadata.Title || osu.metadata.TitleUnicode) + suffix + songObj.title_lang = (osu.metadata.Title || osu.metadata.TitleUnicode) + suffix }else{ songObj.title = filename } - if(songObj.music){ - this.songs[index] = songObj - } + this.songs[index] = songObj songObj.category = category || this.getCategory(file) }).catch(() => {}) reader.readAsText(file) diff --git a/public/src/js/loadsong.js b/public/src/js/loadsong.js index 6629afc..94012fb 100644 --- a/public/src/js/loadsong.js +++ b/public/src/js/loadsong.js @@ -97,16 +97,18 @@ class LoadSong{ if(songObj.sound){ songObj.sound.gain = snd.musicGain resolve() - }else if(songObj.music){ + }else if(!songObj.music){ + snd.musicGain.load(gameConfig.songs_baseurl + id + "/main.mp3").then(sound => { + songObj.sound = sound + resolve() + }, reject) + }else if(songObj.music !== "muted"){ snd.musicGain.load(songObj.music, true).then(sound => { songObj.sound = sound resolve() }, reject) }else{ - snd.musicGain.load(gameConfig.songs_baseurl + id + "/main.mp3").then(sound => { - songObj.sound = sound - resolve() - }, reject) + resolve() } })) if(songObj.chart){ @@ -119,10 +121,10 @@ class LoadSong{ Promise.all(promises).then(() => { this.setupMultiplayer() }, error => { - console.error(error) if(Array.isArray(error) && error[1] instanceof HTMLElement){ error = error[0] + ": " + error[1].outerHTML } + console.error(error) pageEvents.send("load-song-error", error) errorMessage(new Error(error).stack) alert("An error occurred, please refresh") diff --git a/public/src/js/parsetja.js b/public/src/js/parsetja.js index 22e2e9f..427bb43 100644 --- a/public/src/js/parsetja.js +++ b/public/src/js/parsetja.js @@ -44,7 +44,7 @@ var hasSong = false var courses = {} var currentCourse = {} - var courseName = this.difficulty + var courseName = "oni" for(var lineNum = 0; lineNum < this.data.length; lineNum++){ var line = this.data[lineNum] @@ -55,10 +55,10 @@ inSong = true if(!hasSong){ + if(!(courseName in courses)){ + courses[courseName] = {} + } for(var name in currentCourse){ - if(!(courseName in courses)){ - courses[courseName] = {} - } if(name !== "branch"){ courses[courseName][name] = currentCourse[name] } @@ -118,10 +118,7 @@ parseCircles(){ var meta = this.metadata[this.difficulty] var ms = (meta.offset || 0) * -1000 + this.offset - var bpm = meta.bpm || 0 - if(bpm <= 0){ - bpm = 1 - } + var bpm = Math.abs(meta.bpm) || 120 var scroll = 1 var measure = 4 this.beatInfo.beatInterval = 60000 / bpm @@ -227,7 +224,7 @@ bpm = parseFloat(value) || bpm break case "scroll": - scroll = parseFloat(value) || scroll + scroll = Math.abs(parseFloat(value)) || scroll break case "measure": var [numerator, denominator] = value.split("/") diff --git a/public/src/js/songselect.js b/public/src/js/songselect.js index 1f9bedf..09857f8 100644 --- a/public/src/js/songselect.js +++ b/public/src/js/songselect.js @@ -1753,15 +1753,15 @@ class SongSelect{ } new Promise((resolve, reject) => { - if(currentSong.music){ - songObj.preview_time = prvTime - snd.previewGain.load(currentSong.music, true).then(resolve, reject) - }else{ + if(!currentSong.music){ songObj.preview_time = 0 loadPreview(previewFilename).catch(() => { songObj.preview_time = prvTime return loadPreview("/main.mp3") }).then(resolve, reject) + }else if(currentSong.music !== "muted"){ + songObj.preview_time = prvTime + snd.previewGain.load(currentSong.music, true).then(resolve, reject) } }).then(sound => { if(currentId === this.previewId){ diff --git a/public/src/js/view.js b/public/src/js/view.js index 211b0bd..b1733c8 100644 --- a/public/src/js/view.js +++ b/public/src/js/view.js @@ -1180,6 +1180,10 @@ } setDonBgHeight(){ this.donBg.style.setProperty("--h", getComputedStyle(this.donBg).height) + this.gameDiv.classList.add("fix-animations") + setTimeout(()=>{ + this.gameDiv.classList.remove("fix-animations") + }, 50) } setLayers(elements, file, ab){ if(ab){