ScoreStorage: Use hashes instead of song titles
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
var assets = {
|
||||
"js": [
|
||||
"lib/fontdetect.min.js",
|
||||
"lib/md5.min.js",
|
||||
"loadsong.js",
|
||||
"parseosu.js",
|
||||
"titlescreen.js",
|
||||
|
||||
@@ -274,6 +274,13 @@
|
||||
if(songObj.stars.length !== 0){
|
||||
this.songs[index] = songObj
|
||||
}
|
||||
var hash = md5.base64(event.target.result).slice(0, -2)
|
||||
songObj.hash = hash
|
||||
scoreStorage.songTitles[songObj.title] = hash
|
||||
var score = scoreStorage.get(hash)
|
||||
if(score){
|
||||
score.title = songObj.title
|
||||
}
|
||||
}).catch(() => {})
|
||||
reader.readAsText(file, "sjis")
|
||||
return promise
|
||||
@@ -297,7 +304,8 @@
|
||||
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()] || "muted"
|
||||
music: this.otherFiles[dir + osu.generalInfo.AudioFilename.toLowerCase()] || "muted",
|
||||
hash: md5.base64(event.target.result).slice(0, -2)
|
||||
}
|
||||
var filename = file.name.slice(0, file.name.lastIndexOf("."))
|
||||
var title = osu.metadata.TitleUnicode || osu.metadata.Title
|
||||
|
||||
10
public/src/js/lib/md5.min.js
vendored
Normal file
10
public/src/js/lib/md5.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@@ -204,9 +204,21 @@ class Loader{
|
||||
}
|
||||
|
||||
settings = new Settings()
|
||||
scoreStorage = new ScoreStorage()
|
||||
pageEvents.setKbd()
|
||||
|
||||
scoreStorage = new ScoreStorage()
|
||||
for(var i in assets.songsDefault){
|
||||
var song = assets.songsDefault[i]
|
||||
if(!song.hash){
|
||||
song.hash = song.title
|
||||
}
|
||||
scoreStorage.songTitles[song.title] = song.hash
|
||||
var score = scoreStorage.get(song.hash)
|
||||
if(score){
|
||||
score.title = song.title
|
||||
}
|
||||
}
|
||||
|
||||
Promise.all(this.promises).then(() => {
|
||||
this.canvasTest.drawAllImages().then(result => {
|
||||
perf.allImg = result
|
||||
|
||||
@@ -863,8 +863,9 @@ class Scoresheet{
|
||||
saveScore(){
|
||||
if(!this.controller.autoPlayEnabled && this.resultsObj.points > 0){
|
||||
var title = this.controller.selectedSong.originalTitle
|
||||
var hash = this.controller.selectedSong.hash
|
||||
var difficulty = this.resultsObj.difficulty
|
||||
var oldScore = scoreStorage.get(title, difficulty)
|
||||
var oldScore = scoreStorage.get(hash, difficulty, true)
|
||||
if(!oldScore || oldScore.points <= this.resultsObj.points){
|
||||
var crown = ""
|
||||
if(this.controller.game.rules.clearReached(this.resultsObj.gauge)){
|
||||
@@ -877,7 +878,7 @@ class Scoresheet{
|
||||
delete this.resultsObj.title
|
||||
delete this.resultsObj.difficulty
|
||||
delete this.resultsObj.gauge
|
||||
scoreStorage.add(title, difficulty, this.resultsObj)
|
||||
scoreStorage.add(hash, difficulty, this.resultsObj, true, title)
|
||||
}
|
||||
}
|
||||
this.scoreSaved = true
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
class ScoreStorage{
|
||||
constructor(){
|
||||
this.scores = {}
|
||||
this.songTitles = {}
|
||||
this.difficulty = ["oni", "ura", "hard", "normal", "easy"]
|
||||
this.scoreKeys = ["points", "good", "ok", "bad", "maxCombo", "drumroll"]
|
||||
this.crownValue = ["", "silver", "gold"]
|
||||
@@ -15,8 +16,8 @@ class ScoreStorage{
|
||||
this.scoreStrings = JSON.parse(localScores)
|
||||
}
|
||||
}catch(e){}
|
||||
for(var song in this.scoreStrings){
|
||||
var scoreString = this.scoreStrings[song]
|
||||
for(var hash in this.scoreStrings){
|
||||
var scoreString = this.scoreStrings[hash]
|
||||
var songAdded = false
|
||||
if(typeof scoreString === "string" && scoreString){
|
||||
var diffArray = scoreString.split(";")
|
||||
@@ -36,18 +37,18 @@ class ScoreStorage{
|
||||
score[name] = value
|
||||
}
|
||||
if(!songAdded){
|
||||
this.scores[song] = []
|
||||
this.scores[hash] = {title: null}
|
||||
songAdded = true
|
||||
}
|
||||
this.scores[song][this.difficulty[i]] = score
|
||||
this.scores[hash][this.difficulty[i]] = score
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
save(){
|
||||
for(var song in this.scores){
|
||||
this.writeString(song)
|
||||
for(var hash in this.scores){
|
||||
this.writeString(hash)
|
||||
}
|
||||
this.write()
|
||||
}
|
||||
@@ -56,8 +57,8 @@ class ScoreStorage{
|
||||
localStorage.setItem("scoreStorage", JSON.stringify(this.scoreStrings))
|
||||
}catch(e){}
|
||||
}
|
||||
writeString(song){
|
||||
var score = this.scores[song]
|
||||
writeString(hash){
|
||||
var score = this.scores[hash]
|
||||
var diffArray = []
|
||||
var notEmpty = false
|
||||
for(var i = this.difficulty.length; i--;){
|
||||
@@ -77,25 +78,39 @@ class ScoreStorage{
|
||||
diffArray.unshift("")
|
||||
}
|
||||
}
|
||||
this.scoreStrings[song] = diffArray.join(";")
|
||||
this.scoreStrings[hash] = diffArray.join(";")
|
||||
}
|
||||
get(song, difficulty){
|
||||
titleHash(song){
|
||||
if(song in this.songTitles){
|
||||
return this.songTitles[song]
|
||||
}else{
|
||||
return song
|
||||
}
|
||||
}
|
||||
get(song, difficulty, isHash){
|
||||
if(!song){
|
||||
return this.scores
|
||||
}else if(song in this.scores){
|
||||
}else{
|
||||
var hash = isHash ? song : this.titleHash(song)
|
||||
if(difficulty){
|
||||
return this.scores[song][difficulty]
|
||||
if(hash in this.scores){
|
||||
return this.scores[hash][difficulty]
|
||||
}
|
||||
}else{
|
||||
return this.scores[song]
|
||||
return this.scores[hash]
|
||||
}
|
||||
}
|
||||
}
|
||||
add(song, difficulty, scoreObject){
|
||||
if(!(song in this.scores)){
|
||||
this.scores[song] = {}
|
||||
add(song, difficulty, scoreObject, isHash, setTitle){
|
||||
var hash = isHash ? song : this.titleHash(song)
|
||||
if(!(hash in this.scores)){
|
||||
this.scores[hash] = {}
|
||||
}
|
||||
this.scores[song][difficulty] = scoreObject
|
||||
this.writeString(song)
|
||||
if(setTitle){
|
||||
this.scores[hash].title = setTitle
|
||||
}
|
||||
this.scores[hash][difficulty] = scoreObject
|
||||
this.writeString(hash)
|
||||
this.write()
|
||||
}
|
||||
template(){
|
||||
@@ -106,28 +121,29 @@ class ScoreStorage{
|
||||
}
|
||||
return template
|
||||
}
|
||||
remove(song, difficulty){
|
||||
if(song in this.scores){
|
||||
remove(song, difficulty, isHash){
|
||||
var hash = isHash ? song : this.titleHash(song)
|
||||
if(hash in this.scores){
|
||||
if(difficulty){
|
||||
if(difficulty in this.scores[song]){
|
||||
delete this.scores[song][difficulty]
|
||||
if(difficulty in this.scores[hash]){
|
||||
delete this.scores[hash][difficulty]
|
||||
var noDiff = true
|
||||
for(var i in this.difficulty){
|
||||
if(this.scores[song][this.difficulty[i]]){
|
||||
if(this.scores[hash][this.difficulty[i]]){
|
||||
noDiff = false
|
||||
break
|
||||
}
|
||||
}
|
||||
if(noDiff){
|
||||
delete this.scores[song]
|
||||
delete this.scoreStrings[song]
|
||||
delete this.scores[hash]
|
||||
delete this.scoreStrings[hash]
|
||||
}else{
|
||||
this.writeString(song)
|
||||
this.writeString(hash)
|
||||
}
|
||||
}
|
||||
}else{
|
||||
delete this.scores[song]
|
||||
delete this.scoreStrings[song]
|
||||
delete this.scores[hash]
|
||||
delete this.scoreStrings[hash]
|
||||
}
|
||||
this.write()
|
||||
}
|
||||
|
||||
@@ -125,7 +125,8 @@ class SongSelect{
|
||||
music: song.music,
|
||||
volume: song.volume,
|
||||
maker: song.maker,
|
||||
canJump: true
|
||||
canJump: true,
|
||||
hash: song.hash || song.title
|
||||
})
|
||||
}
|
||||
this.songs.sort((a, b) => {
|
||||
@@ -746,7 +747,8 @@ class SongSelect{
|
||||
"type": selectedSong.type,
|
||||
"offset": selectedSong.offset,
|
||||
"songSkin": selectedSong.songSkin,
|
||||
"stars": selectedSong.stars[difficulty]
|
||||
"stars": selectedSong.stars[difficulty],
|
||||
"hash": selectedSong.hash
|
||||
}, autoplay, multiplayer, touch)
|
||||
}
|
||||
toOptions(moveBy){
|
||||
@@ -1256,6 +1258,15 @@ class SongSelect{
|
||||
this.currentSongCache.clear()
|
||||
}
|
||||
|
||||
if(selectedWidth === this.songAsset.width){
|
||||
this.drawSongCrown({
|
||||
ctx: ctx,
|
||||
song: currentSong,
|
||||
x: winW / 2 - selectedWidth / 2 + xOffset,
|
||||
y: songTop + this.songAsset.height - selectedHeight
|
||||
})
|
||||
}
|
||||
|
||||
this.draw.songFrame({
|
||||
ctx: ctx,
|
||||
x: winW / 2 - selectedWidth / 2 + xOffset,
|
||||
@@ -1387,7 +1398,7 @@ class SongSelect{
|
||||
}
|
||||
var drawDifficulty = (ctx, i, currentUra) => {
|
||||
if(currentSong.stars[i] || currentUra){
|
||||
var score = scoreStorage.get(currentSong.originalTitle)
|
||||
var score = scoreStorage.get(currentSong.hash)
|
||||
var crownDiff = currentUra ? "ura" : this.difficultyId[i]
|
||||
var crownType = ""
|
||||
if(score && score[crownDiff]){
|
||||
@@ -1926,35 +1937,7 @@ class SongSelect{
|
||||
drawClosedSong(config){
|
||||
var ctx = config.ctx
|
||||
|
||||
if(!config.song.action && config.song.originalTitle){
|
||||
var score = scoreStorage.get(config.song.originalTitle)
|
||||
for(var i = this.difficultyId.length; i--;){
|
||||
var diff = this.difficultyId[i]
|
||||
if(!score){
|
||||
break
|
||||
}
|
||||
if(config.song.stars[i] && score[diff] && score[diff].crown){
|
||||
this.draw.crown({
|
||||
ctx: ctx,
|
||||
type: score[diff].crown,
|
||||
x: config.x + this.songAsset.width / 2,
|
||||
y: config.y - 13,
|
||||
scale: 0.3,
|
||||
ratio: this.ratio / this.pixelRatio
|
||||
})
|
||||
this.draw.diffIcon({
|
||||
ctx: ctx,
|
||||
diff: i,
|
||||
x: config.x + this.songAsset.width / 2 + 8,
|
||||
y: config.y - 8,
|
||||
scale: diff === "hard" || diff === "normal" ? 0.45 : 0.5,
|
||||
border: 6.5,
|
||||
small: true
|
||||
})
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
this.drawSongCrown(config)
|
||||
config.width = this.songAsset.width
|
||||
config.height = this.songAsset.height
|
||||
config.border = this.songAsset.border
|
||||
@@ -2004,6 +1987,39 @@ class SongSelect{
|
||||
}
|
||||
}
|
||||
|
||||
drawSongCrown(config){
|
||||
if(!config.song.action && config.song.hash){
|
||||
var ctx = config.ctx
|
||||
var score = scoreStorage.get(config.song.hash)
|
||||
for(var i = this.difficultyId.length; i--;){
|
||||
var diff = this.difficultyId[i]
|
||||
if(!score){
|
||||
break
|
||||
}
|
||||
if(config.song.stars[i] && score[diff] && score[diff].crown){
|
||||
this.draw.crown({
|
||||
ctx: ctx,
|
||||
type: score[diff].crown,
|
||||
x: config.x + this.songAsset.width / 2,
|
||||
y: config.y - 13,
|
||||
scale: 0.3,
|
||||
ratio: this.ratio / this.pixelRatio
|
||||
})
|
||||
this.draw.diffIcon({
|
||||
ctx: ctx,
|
||||
diff: i,
|
||||
x: config.x + this.songAsset.width / 2 + 8,
|
||||
y: config.y - 8,
|
||||
scale: diff === "hard" || diff === "normal" ? 0.45 : 0.5,
|
||||
border: 6.5,
|
||||
small: true
|
||||
})
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
startPreview(loadOnly){
|
||||
var currentSong = this.songs[this.selectedSong]
|
||||
var id = currentSong.id
|
||||
|
||||
Reference in New Issue
Block a user