Skip to content

Instantly share code, notes, and snippets.

@KatieFrogs
Created December 6, 2021 22:28
Show Gist options
  • Save KatieFrogs/2b656eb5b5838e1d803b9e6e199c1746 to your computer and use it in GitHub Desktop.
Save KatieFrogs/2b656eb5b5838e1d803b9e6e199c1746 to your computer and use it in GitHub Desktop.
taiko-web score string decoder and encoder
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(";")
}
@DJTOMATO
Copy link

DJTOMATO commented Dec 6, 2021

<3 ty

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment