Created
December 6, 2021 22:28
-
-
Save KatieFrogs/2b656eb5b5838e1d803b9e6e199c1746 to your computer and use it in GitHub Desktop.
taiko-web score string decoder and encoder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function scoreDecoder(scoreString){ | |
var difficulty = ["oni", "ura", "hard", "normal", "easy"] | |
var scoreKeys = ["points", "good", "ok", "bad", "maxCombo", "drumroll"] | |
var crownValue = ["", "silver", "gold"] | |
var songAdded = false | |
var output = {title: null} | |
if(typeof scoreString === "string" && scoreString){ | |
var diffArray = scoreString.split(";") | |
for(var i in difficulty){ | |
if(diffArray[i]){ | |
var crown = parseInt(diffArray[i].slice(0, 1)) || 0 | |
var score = { | |
crown: crownValue[crown] || "" | |
} | |
var scoreArray = diffArray[i].slice(1).split(",") | |
for(var j in scoreKeys){ | |
var name = scoreKeys[j] | |
var value = parseInt(scoreArray[j], 36) || 0 | |
if(value < 0){ | |
value = 0 | |
} | |
score[name] = value | |
} | |
output[difficulty[i]] = score | |
} | |
} | |
return output | |
} | |
} | |
function scoreEncoder(score){ | |
var difficulty = ["oni", "ura", "hard", "normal", "easy"] | |
var scoreKeys = ["points", "good", "ok", "bad", "maxCombo", "drumroll"] | |
var crownValue = ["", "silver", "gold"] | |
var diffArray = [] | |
var notEmpty = false | |
for(var i = difficulty.length; i--;){ | |
var diff = difficulty[i] | |
if(score[diff]){ | |
var scoreArray = [] | |
var crown = crownValue.indexOf(score[diff].crown).toString() | |
for(var j in scoreKeys){ | |
var name = scoreKeys[j] | |
var value = score[diff][name] | |
value = Math.floor(value).toString(36) | |
scoreArray.push(value) | |
} | |
diffArray.unshift(crown + scoreArray.join(",")) | |
notEmpty = true | |
}else if(notEmpty){ | |
diffArray.unshift("") | |
} | |
} | |
return diffArray.join(";") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
<3 ty