-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
175 lines (142 loc) · 5.25 KB
/
Copy pathscript.js
File metadata and controls
175 lines (142 loc) · 5.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
// currently works.
window.addEventListener("DOMContentLoaded", function () {
console.log("test");
calcPP();
var ez = document.getElementById("EZ");
var hr = document.getElementById("HR");
var ht = document.getElementById("HT");
var dt = document.getElementById("DT");
var hd = document.getElementById("HD");
var fl = document.getElementById("FL");
var clear = document.getElementById("clear-mods");
ez.addEventListener("click", uncheck(hr));
hr.addEventListener("click", uncheck(ez));
ht.addEventListener("click", uncheck(dt));
dt.addEventListener("click", uncheck(ht));
clear.addEventListener("click", uncheckAll(ez, ht, hd, hr, dt, fl));
var inputs = document.getElementsByTagName('input');
for (var i in inputs) {
switch (inputs[i].type) {
case "number":
inputs[i].addEventListener("input", calcPP);
break;
case "checkbox":
inputs[i].addEventListener("click", calcPP);
break;
}
}
});
function uncheckAll(ez, ht, hd, hr, dt, fl) {
return function () {
ez.checked = false;
ht.checked = false;
hd.checked = false;
hr.checked = false;
dt.checked = false;
fl.checked = false;
calcPP(); // recalculate PP
}
}
function uncheck(elem) {
return function () {
elem.checked = false;
};
}
// scales OD based on selected mods.
function scaleOd(od) {
if (document.getElementById("EZ").checked) { // ez is selected
od /= 2;
}
if (document.getElementById("HR").checked) { // hr is selected
od *= 1.4;
}
od = Math.max(Math.min(od, 10), 0); // OD is less than 10 and greater than 0
return od;
}
// calculates hit window
function calcHitWindow(od) {
od = scaleOd(od); // scale OD first
let hitWindow = 35; // base window in ms
if (od > 5) {
hitWindow += (20 - 35) * (od - 5) / 5; // tighten hit window
}
else if (od < 5) {
hitWindow -= (35 - 50) * (5 - od) / 5; // loosen hit window
}
// adjust hit window based on selected mods
if (document.getElementById("HT").checked) {
hitWindow /= 0.75;
}
if (document.getElementById("DT").checked) {
hitWindow /= 1.5;
}
return Math.round(hitWindow * 100) / 100; // 2 decimals NOTE: messes with accuracy of calculations
}
// calculates difficulty value
function calcDifficultyValue(starRating, maxCombo, effectiveMissCount, accuracy) {
let difficultyValue;
let lengthBonus;
difficultyValue = Math.pow(5 * Math.max(1.0, starRating / 0.115) - 4.0, 2.25) / 1150.0;
lengthBonus = 1 + 0.1 * Math.min(1.0, maxCombo / 1500.0);
difficultyValue *= lengthBonus;
difficultyValue *= Math.pow(0.986, effectiveMissCount);
difficultyValue *= Math.pow(accuracy, 2.0);
// FL bonus
if (document.getElementById("FL").checked) {
difficultyValue *= 1.05 * lengthBonus
}
return difficultyValue;
}
// calculates accuracy value
function calcAccuracyValue(hitWindow300, accuracy) {
if (hitWindow300 <= 0) {
return 0;
}
let accuracyValue;
let lengthBonus;
accuracyValue = Math.pow(60.0 / hitWindow300, 1.1) * Math.pow(accuracy, 8.0) * Math.pow(starRating, 0.4) * 27.0;
lengthBonus = Math.min(1.15, Math.pow(maxCombo / 1500.0, 0.3));
accuracyValue *= lengthBonus;
// HDFL bonus
if (document.getElementById("HD").checked && document.getElementById("FL").checked) {
accuracyValue *= Math.max(1.050, 1.075 * lengthBonus);
}
return accuracyValue;
}
// The effectiveMissCount is calculated by gaining a ratio for totalSuccessfulHits and increasing the miss penalty for shorter object counts lower than 1000.
function calcEffectiveMissCount(maxCombo, missCount) {
let effectiveMissCount;
let userCombo = maxCombo - missCount;
effectiveMissCount = Math.max(1.0, 1000.0 / userCombo) * missCount;
return effectiveMissCount;
}
function calcPP() {
// get user input values
starRating = document.getElementById("strain").value;// strain
od = document.getElementById("od-input").value; // OD value
maxCombo = document.getElementById("numcircles").value;
missCount = document.getElementById("misses").value;
hitWindow300 = calcHitWindow(od); // OD for 300 in ms
accuracy = document.getElementById("acc").value / 100;
// calculate individual values
let totalValue;
let multiplier = 1.13;
let effectiveMissCount = calcEffectiveMissCount(maxCombo, missCount);
let difficultyValue = calcDifficultyValue(starRating, maxCombo, effectiveMissCount, accuracy);
let accuracyValue = calcAccuracyValue(hitWindow300, accuracy);
// calculate mod bonuses
if (document.getElementById("HD").checked) {
multiplier *= 1.075;
difficultyValue *= 1.025;
}
if (document.getElementById("EZ").checked) {
multiplier *= 0.975;
difficultyValue *= 0.985;
}
if (document.getElementById("HR").checked) {
difficultyValue *= 1.05;
}
// final PP calculation
totalValue = Math.pow(Math.pow(difficultyValue, 1.1) + Math.pow(accuracyValue, 1.1), 1.0 / 1.1) * multiplier;
document.getElementById("pp").innerHTML = Math.round(totalValue * 1000) / 1000 + " pp"
}