Skip to content

Commit

Permalink
Implement grading
Browse files Browse the repository at this point in the history
  • Loading branch information
Sainan committed May 29, 2024
1 parent 5fa49bd commit 4b0673c
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 7 deletions.
20 changes: 18 additions & 2 deletions RivenParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,7 @@ function rivenIntToFloat(i) {
}

function floatToRivenInt(f) {
return f * 0x3FFFFFFF;
return Math.round(f * 0x3FFFFFFF);
}

function lerp(a, b, t) {
Expand Down Expand Up @@ -1143,6 +1143,21 @@ function unparseCurse(rivenType, omegaAttenuation, lvl, numBuffs, numCurses, tag
return value;
}

function floatToGrade(value) {
value = lerp(-10, +10, value);
if (value >= +9.5) return "S";
if (value >= +7.5) return "A+";
if (value >= +5.5) return "A";
if (value >= +3.5) return "A-";
if (value >= +1.5) return "B+";
if (value >= -1.5) return "B";
if (value >= -3.5) return "B-";
if (value >= -5.5) return "C+";
if (value >= -7.5) return "C";
if (value >= -9.5) return "C-";
return "F";
}

const RivenParser = {
riven_tags,
rivenIntToFloat,
Expand All @@ -1151,7 +1166,8 @@ const RivenParser = {
displayValueToValue,
parseRiven,
unparseBuff,
unparseCurse
unparseCurse,
floatToGrade,
};
if (typeof module != "undefined") {
module.exports = RivenParser;
Expand Down
35 changes: 30 additions & 5 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
#fingerprint {
resize: none;
}

.grade {
min-width: 44px;
}
</style>
</head>
<body>
Expand Down Expand Up @@ -227,7 +231,7 @@ <h5 class="card-header">Fingerprint</h5>
const tag = div.querySelector("select").value;

if (div.parentNode.id == "buffs") {
div.querySelector(".left-value").valueAsNumber = rivenFloatToLeftValue(RivenParser.unparseBuff(
div.querySelector(".left-value").valueAsNumber = floatToLeftValue(RivenParser.unparseBuff(
rivenType,
omegaAttenuation,
lvl,
Expand All @@ -240,7 +244,7 @@ <h5 class="card-header">Fingerprint</h5>
updateName();
}
else {
div.querySelector(".left-value").valueAsNumber = rivenFloatToLeftValue(RivenParser.unparseCurse(
div.querySelector(".left-value").valueAsNumber = floatToLeftValue(RivenParser.unparseCurse(
rivenType,
omegaAttenuation,
lvl,
Expand All @@ -260,6 +264,12 @@ <h5 class="card-header">Fingerprint</h5>
};
div.appendChild(input);
}
{
let span = document.createElement("span");
span.className = "input-group-text grade";
span.textContent = "B";
div.appendChild(span);
}
body.appendChild(div);
}

Expand Down Expand Up @@ -295,16 +305,20 @@ <h5 class="card-header">Fingerprint</h5>
}
}

function leftValueToFloat(val) {
return ((val - 9000) / 2000);
}

function leftValueToRivenInt(val) {
return Math.round(((val - 9000) / 2000) * 0x3FFFFFFF);
return RivenParser.floatToRivenInt(leftValueToFloat(val));
}

function rivenFloatToLeftValue(val) {
function floatToLeftValue(val) {
return Math.round((val * 2000) + 9000);
}

function rivenIntToLeftValue(val) {
return rivenFloatToLeftValue(RivenParser.rivenIntToFloat(val));
return floatToLeftValue(RivenParser.rivenIntToFloat(val));
}

function getFingerprint() {
Expand Down Expand Up @@ -351,6 +365,8 @@ <h5 class="card-header">Fingerprint</h5>
const rivenType = document.getElementById("riven-type").value;
const omegaAttenuation = parseFloat(document.getElementById("omega-attenuation").value);
location.hash = encodeURIComponent(JSON.stringify({ rivenType, omegaAttenuation, fingerprint }));

updateGrades();
}

function calculateStatsForward() {
Expand Down Expand Up @@ -384,6 +400,15 @@ <h5 class="card-header">Fingerprint</h5>
document.getElementById("name-suffix").textContent = name;
}

function updateGrades() {
document.querySelectorAll("#buffs .input-group").forEach(buff => {
buff.querySelector(".grade").textContent = RivenParser.floatToGrade(leftValueToFloat(buff.querySelector(".left-value").valueAsNumber));
});
document.querySelectorAll("#curses .input-group").forEach(curse => {
curse.querySelector(".grade").textContent = RivenParser.floatToGrade(1.0 - leftValueToFloat(curse.querySelector(".left-value").valueAsNumber));
});
}

function handleFingerprintUpdate() {
document.getElementById("fingerprint").classList.remove("is-invalid");
try {
Expand Down

0 comments on commit 4b0673c

Please sign in to comment.