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)
This commit is contained in:
LoveEevee 2019-03-06 00:48:30 +03:00
parent a9006e7ca2
commit 7ee8773e61
9 changed files with 75 additions and 43 deletions

View File

@ -94,3 +94,6 @@
z-index: 2; z-index: 2;
transition: 1s background-color linear; transition: 1s background-color linear;
} }
.fix-animations *{
animation: none !important;
}

View File

@ -48,9 +48,9 @@
this.regex = { this.regex = {
comma: /[,.]/, comma: /[,.]/,
ideographicComma: /[、。]/, ideographicComma: /[、。]/,
apostrophe: /[']/, apostrophe: /[']/,
degree: /[゚°]/, degree: /[゚°]/,
brackets: /[\(\)\[\]「」『』【】]/, brackets: /[\(\)\[\]「」『』【】:;]/,
tilde: /[\-~〜_]/, tilde: /[\-~〜_]/,
tall: /[bdfghj-l-t♪]/, tall: /[bdfghj-l-t♪]/,
i: /[i]/, i: /[i]/,
@ -625,8 +625,6 @@
drawn.push({text: symbol, x: -2, y: 0, w: 20, scale: [0.6, 0.5]}) drawn.push({text: symbol, x: -2, y: 0, w: 20, scale: [0.6, 0.5]})
}else if(symbol === " "){ }else if(symbol === " "){
drawn.push({text: symbol, x: 0, y: 0, w: 10}) 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 === '"'){ }else if(symbol === '"'){
drawn.push({text: symbol, x: 2, y: 0, w: 10}) drawn.push({text: symbol, x: 2, y: 0, w: 10})
}else if(symbol === "∀"){ }else if(symbol === "∀"){
@ -637,6 +635,8 @@
} }
}else if(symbol === ""){ }else if(symbol === ""){
drawn.push({text: symbol, x: -9, y: 0, w: 37}) 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)){ }else if(r.comma.test(symbol)){
// Comma, full stop // Comma, full stop
if(bold){ if(bold){

View File

@ -68,7 +68,9 @@ class Controller{
} }
stopMainLoop(){ stopMainLoop(){
this.mainLoopRunning = false this.mainLoopRunning = false
this.mainAsset.stop() if(this.mainAsset){
this.mainAsset.stop()
}
if(this.multiplayer !== 2){ if(this.multiplayer !== 2){
clearInterval(this.gameInterval) clearInterval(this.gameInterval)
} }

View File

@ -465,7 +465,8 @@ class Game{
var started = this.fadeOutStarted var started = this.fadeOutStarted
if(started){ if(started){
var ms = this.elapsedTime 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.musicFadeOut === 0){
if(this.controller.multiplayer === 1){ if(this.controller.multiplayer === 1){
p2.send("gameresults", this.getGlobalScore()) p2.send("gameresults", this.getGlobalScore())
@ -491,7 +492,7 @@ class Game{
playMainMusic(){ playMainMusic(){
var ms = this.elapsedTime + this.controller.offset var ms = this.elapsedTime + this.controller.offset
if(!this.mainMusicPlaying && (!this.fadeOutStarted || ms < this.fadeOutStarted + 1600)){ 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.mainAsset.play((ms < 0 ? -ms : 0) / 1000, false, Math.max(0, ms / 1000))
} }
this.mainMusicPlaying = true this.mainMusicPlaying = true
@ -502,7 +503,9 @@ class Game{
assets.sounds["se_pause"].play() assets.sounds["se_pause"].play()
this.paused = true this.paused = true
this.latestDate = Date.now() this.latestDate = Date.now()
this.mainAsset.stop() if(this.mainAsset){
this.mainAsset.stop()
}
this.mainMusicPlaying = false this.mainMusicPlaying = false
this.view.pauseMove(0, true) this.view.pauseMove(0, true)
this.view.gameDiv.classList.add("game-paused") this.view.gameDiv.classList.add("game-paused")

View File

@ -184,25 +184,26 @@
id: index + 1, id: index + 1,
type: "tja", type: "tja",
chart: data, chart: data,
stars: [] stars: [],
music: "muted"
} }
var titleLang = {}
var subtitleLang = {}
var dir = file.webkitRelativePath.toLowerCase() var dir = file.webkitRelativePath.toLowerCase()
dir = dir.slice(0, dir.lastIndexOf("/") + 1) dir = dir.slice(0, dir.lastIndexOf("/") + 1)
var hasCategory = false var hasCategory = false
for(var diff in tja.metadata){ for(var diff in tja.metadata){
var meta = tja.metadata[diff] 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 || "" var subtitle = meta.subtitle || ""
if(subtitle.startsWith("--")){ if(subtitle.startsWith("--") || subtitle.startsWith("++")){
subtitle = subtitle.slice(2) subtitle = subtitle.slice(2).trim()
} }
songObj.subtitle = songObj.subtitle_en = subtitle songObj.subtitle = subtitle
songObj.preview = meta.demostart || 0 songObj.preview = meta.demostart || 0
if(meta.level){ songObj.stars[this.courseTypes[diff]] = (meta.level || "0") + (meta.branch ? " B" : "")
songObj.stars[this.courseTypes[diff]] = meta.level + (meta.branch ? " B" : "")
}
if(meta.wave){ if(meta.wave){
songObj.music = this.otherFiles[dir + meta.wave.toLowerCase()] songObj.music = this.otherFiles[dir + meta.wave.toLowerCase()] || songObj.music
} }
if(meta.genre){ if(meta.genre){
songObj.category = this.categories[meta.genre.toLowerCase()] || meta.genre songObj.category = this.categories[meta.genre.toLowerCase()] || meta.genre
@ -210,11 +211,33 @@
if(meta.taikowebskin){ if(meta.taikowebskin){
songObj.song_skin = this.getSkin(dir, 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){ if(!songObj.category){
songObj.category = category || this.getCategory(file) 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 this.songs[index] = songObj
} }
}).catch(() => {}) }).catch(() => {})
@ -237,10 +260,10 @@
type: "osu", type: "osu",
chart: data, chart: data,
subtitle: osu.metadata.ArtistUnicode || osu.metadata.Artist, 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, preview: osu.generalInfo.PreviewTime / 1000,
stars: [null, null, null, parseInt(osu.difficulty.overallDifficulty) || 1], 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 filename = file.name.slice(0, file.name.lastIndexOf("."))
var title = osu.metadata.TitleUnicode || osu.metadata.Title var title = osu.metadata.TitleUnicode || osu.metadata.Title
@ -251,13 +274,11 @@
suffix = " " + matches[0] suffix = " " + matches[0]
} }
songObj.title = title + suffix 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{ }else{
songObj.title = filename songObj.title = filename
} }
if(songObj.music){ this.songs[index] = songObj
this.songs[index] = songObj
}
songObj.category = category || this.getCategory(file) songObj.category = category || this.getCategory(file)
}).catch(() => {}) }).catch(() => {})
reader.readAsText(file) reader.readAsText(file)

View File

@ -97,16 +97,18 @@ class LoadSong{
if(songObj.sound){ if(songObj.sound){
songObj.sound.gain = snd.musicGain songObj.sound.gain = snd.musicGain
resolve() 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 => { snd.musicGain.load(songObj.music, true).then(sound => {
songObj.sound = sound songObj.sound = sound
resolve() resolve()
}, reject) }, reject)
}else{ }else{
snd.musicGain.load(gameConfig.songs_baseurl + id + "/main.mp3").then(sound => { resolve()
songObj.sound = sound
resolve()
}, reject)
} }
})) }))
if(songObj.chart){ if(songObj.chart){
@ -119,10 +121,10 @@ class LoadSong{
Promise.all(promises).then(() => { Promise.all(promises).then(() => {
this.setupMultiplayer() this.setupMultiplayer()
}, error => { }, error => {
console.error(error)
if(Array.isArray(error) && error[1] instanceof HTMLElement){ if(Array.isArray(error) && error[1] instanceof HTMLElement){
error = error[0] + ": " + error[1].outerHTML error = error[0] + ": " + error[1].outerHTML
} }
console.error(error)
pageEvents.send("load-song-error", error) pageEvents.send("load-song-error", error)
errorMessage(new Error(error).stack) errorMessage(new Error(error).stack)
alert("An error occurred, please refresh") alert("An error occurred, please refresh")

View File

@ -44,7 +44,7 @@
var hasSong = false var hasSong = false
var courses = {} var courses = {}
var currentCourse = {} var currentCourse = {}
var courseName = this.difficulty var courseName = "oni"
for(var lineNum = 0; lineNum < this.data.length; lineNum++){ for(var lineNum = 0; lineNum < this.data.length; lineNum++){
var line = this.data[lineNum] var line = this.data[lineNum]
@ -55,10 +55,10 @@
inSong = true inSong = true
if(!hasSong){ if(!hasSong){
if(!(courseName in courses)){
courses[courseName] = {}
}
for(var name in currentCourse){ for(var name in currentCourse){
if(!(courseName in courses)){
courses[courseName] = {}
}
if(name !== "branch"){ if(name !== "branch"){
courses[courseName][name] = currentCourse[name] courses[courseName][name] = currentCourse[name]
} }
@ -118,10 +118,7 @@
parseCircles(){ parseCircles(){
var meta = this.metadata[this.difficulty] var meta = this.metadata[this.difficulty]
var ms = (meta.offset || 0) * -1000 + this.offset var ms = (meta.offset || 0) * -1000 + this.offset
var bpm = meta.bpm || 0 var bpm = Math.abs(meta.bpm) || 120
if(bpm <= 0){
bpm = 1
}
var scroll = 1 var scroll = 1
var measure = 4 var measure = 4
this.beatInfo.beatInterval = 60000 / bpm this.beatInfo.beatInterval = 60000 / bpm
@ -227,7 +224,7 @@
bpm = parseFloat(value) || bpm bpm = parseFloat(value) || bpm
break break
case "scroll": case "scroll":
scroll = parseFloat(value) || scroll scroll = Math.abs(parseFloat(value)) || scroll
break break
case "measure": case "measure":
var [numerator, denominator] = value.split("/") var [numerator, denominator] = value.split("/")

View File

@ -1753,15 +1753,15 @@ class SongSelect{
} }
new Promise((resolve, reject) => { new Promise((resolve, reject) => {
if(currentSong.music){ if(!currentSong.music){
songObj.preview_time = prvTime
snd.previewGain.load(currentSong.music, true).then(resolve, reject)
}else{
songObj.preview_time = 0 songObj.preview_time = 0
loadPreview(previewFilename).catch(() => { loadPreview(previewFilename).catch(() => {
songObj.preview_time = prvTime songObj.preview_time = prvTime
return loadPreview("/main.mp3") return loadPreview("/main.mp3")
}).then(resolve, reject) }).then(resolve, reject)
}else if(currentSong.music !== "muted"){
songObj.preview_time = prvTime
snd.previewGain.load(currentSong.music, true).then(resolve, reject)
} }
}).then(sound => { }).then(sound => {
if(currentId === this.previewId){ if(currentId === this.previewId){

View File

@ -1180,6 +1180,10 @@
} }
setDonBgHeight(){ setDonBgHeight(){
this.donBg.style.setProperty("--h", getComputedStyle(this.donBg).height) 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){ setLayers(elements, file, ab){
if(ab){ if(ab){