-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
414 lines (361 loc) · 17.5 KB
/
script.js
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
//Declare constant value
////amount when perfect
const THIRD_TO_LAST_LESSON_AMOUNT_BASE = 120;
const THIRD_TO_LAST_SP_AMOUNT_BASE = 200;
const SECOND_TO_LAST_LESSON_AMOUNT_BASE = 150;
const SECOND_TO_LAST_SP_AMOUNT_BASE = 220;
const OIKOMI_CLEAR_AMOUNT = 165;
const OIKOMI_PERFECT_EACH_AMOUNT = 145;
let THIRD_TO_LAST_LESSON_AMOUNT;
let THIRD_TO_LAST_SP_AMOUNT;
let SECOND_TO_LAST_LESSON_AMOUNT;
let SECOND_TO_LAST_SP_AMOUNT;
let PARAMETER_LIMIT;
const PARAMETER_NAMES = Object.freeze(["vocal", "dance", "visual"]);
const WEEK_ORDER = Object.freeze(["primary", "third_to_last", "second_to_last", "last"]);
const WEEK_DETAIL = Object.freeze(new Map(
[
["primary", 0],
["third_to_last", 1],
["second_to_last", 2],
["last", 3],
]));
//for test
//console.log(new Date().toLocaleTimeString())
//@see 最終プロデュース評価 - 学園アイドルマスターwiki (学マスwiki) https://seesaawiki.jp/gakumasu/d/%BA%C7%BD%AA%A5%D7%A5%ED%A5%C7%A5%E5%A1%BC%A5%B9%C9%BE%B2%C1
// BORDER S: 13000, A+: 11500, A: 10000 //(S+: 14500)
const RANK_EVALUATION_BORDERS = Object.freeze(new Map(
[
["a", 10000],//A
["a_plus", 11500],//A+
["s", 13000],//S
["s_plus", 14500]//S+
]
));
const SCORE_RATES = Object.freeze(new Map(
[
[5000, { rate: 0.30, max: 1500 }],
[10000, { rate: 0.15, max: 750 }],
[20000, { rate: 0.08, max: 800 }],
[30000, { rate: 0.04, max: 400 }],
[40000, { rate: 0.02, max: 200 }],
[50000, { rate: 0.01, max: Number.POSITIVE_INFINITY }], //last
]
));
const PREPARED_LANG_SET = new Set(["ja", "en"]);
let translations;
const loadLanguage = (lang) => {
if (!PREPARED_LANG_SET.has(lang)) lang = "ja";
fetch(`./lang/${lang}.json`)
.then(response => {
if (!response.ok) {
throw new Error(response.status);
}
return response.json();
})
.then(data => {
translations = data;
document.querySelectorAll('[localization-key]').forEach((element) => {
const key = element.getAttribute('localization-key');
const translated = translations[key];
element.innerHTML = translated;
});
document.title.innerText = translations["title"];
})
.catch(error => console.error('Error loading language file:', error));
}
window.onload = () => {
const lang = window.navigator.language.substring(0, 2);
loadLanguage(lang);
const form = document.forms.mainForm;
const primary_vocal = document.getElementById("primary_vocal");
primary_vocal.value = "";
const primary_dance = document.getElementById("primary_dance");
primary_dance.value = "";
const primary_visual = document.getElementById("primary_visual");
primary_visual.value = "";
const vocal_bonus = document.getElementById("vocal_bonus");
const dance_bonus = document.getElementById("dance_bonus");
const visual_bonus = document.getElementById("visual_bonus");
const third_to_last_vocal = document.getElementById("third_to_last_vocal");
const third_to_last_dance = document.getElementById("third_to_last_dance");
const third_to_last_visual = document.getElementById("third_to_last_visual");
const second_to_last_vocal = document.getElementById("second_to_last_vocal");
const second_to_last_dance = document.getElementById("second_to_last_dance");
const second_to_last_visual = document.getElementById("second_to_last_visual");
const last_vocal = document.getElementById("last_vocal");
const last_dance = document.getElementById("last_dance");
const last_visual = document.getElementById("last_visual");
const get_as_number = (input_id) => {
return Number(document.getElementById(input_id).value);
}
const get_lesson_kind = (radio) => {
const value = radio.value;
const sp = value.substring(0, 3) == "sp_";
const parameter_name = sp ? value.substring(3) : value;
return [parameter_name, sp];
}
const calc_amount = (original, bonus) => original + Math.floor(original * bonus / 100.0);
const auto_calculate_parameter = (evt) => {
const name = evt.currentTarget.name;
const week_name = name.substring(0, name.length - 7);
const idx = WEEK_DETAIL.get(week_name);
const start_week = WEEK_ORDER[idx - 1]
calculate_parameter(start_week);
}
const calc_lesson_parameter = () => {
const lesson_limit_up_amount = get_as_number("lesson_limit_up");
THIRD_TO_LAST_LESSON_AMOUNT = THIRD_TO_LAST_LESSON_AMOUNT_BASE + lesson_limit_up_amount;
THIRD_TO_LAST_SP_AMOUNT = THIRD_TO_LAST_SP_AMOUNT_BASE + lesson_limit_up_amount;
SECOND_TO_LAST_LESSON_AMOUNT = SECOND_TO_LAST_LESSON_AMOUNT_BASE + lesson_limit_up_amount;
SECOND_TO_LAST_SP_AMOUNT = SECOND_TO_LAST_SP_AMOUNT_BASE + lesson_limit_up_amount;
}
const lesson_limit_up = document.getElementById("lesson_limit_up");
lesson_limit_up.addEventListener("input", calc_lesson_parameter);
const difficulty_change = (difficulty_level) => {
if (difficulty_level == "pro") {
PARAMETER_LIMIT = 1500;
lesson_limit_up.disabled = true;
lesson_limit_up.placeholder = "-";
THIRD_TO_LAST_LESSON_AMOUNT = THIRD_TO_LAST_LESSON_AMOUNT_BASE;
THIRD_TO_LAST_SP_AMOUNT = THIRD_TO_LAST_SP_AMOUNT_BASE;
SECOND_TO_LAST_LESSON_AMOUNT = SECOND_TO_LAST_LESSON_AMOUNT_BASE;
SECOND_TO_LAST_SP_AMOUNT = SECOND_TO_LAST_SP_AMOUNT_BASE;
} else {
PARAMETER_LIMIT = 1800;
lesson_limit_up.disabled = false;
lesson_limit_up.placeholder = "000";
calc_lesson_parameter();
}
window.sessionStorage.setItem("difficulty_level", difficulty_level);
};
document.getElementsByName('difficulty').forEach(input => {
input.addEventListener("change", (evt) => {
difficulty_change(evt.currentTarget.value);
});
});
//difficulty level
let difficulty_level = window.sessionStorage.getItem("difficulty_level");
if (difficulty_level == null) difficulty_level = "pro";//first
document.getElementById("difficulty_" + difficulty_level).checked = true;
difficulty_change(difficulty_level);
const calculate_parameter = (start_week = "primary") => {
const start_idx = WEEK_DETAIL.get(start_week);
const parameters = {
"vocal": get_as_number(start_week + "_vocal"),
"vocal_bonus": get_as_number("vocal_bonus"),
"dance": get_as_number(start_week + "_dance"),
"dance_bonus": get_as_number("dance_bonus"),
"visual": get_as_number(start_week + "_visual"),
"visual_bonus": get_as_number("visual_bonus")
}
if (parameters["vocal"] == 0 && parameters["dance"] == 0 && parameters["visual"] == 0 &&
parameters["vocal_bonus"] == 0 && parameters["dance_bonus"] == 0 && parameters["visual_bonus"] == 0) return;
//last 4 week
if (start_idx < WEEK_DETAIL.get("third_to_last")) {
const [chosen_parameter, sp] = get_lesson_kind(form.third_to_last_lesson);
const amount = sp ? THIRD_TO_LAST_SP_AMOUNT : THIRD_TO_LAST_LESSON_AMOUNT;
parameters[chosen_parameter] += calc_amount(amount, parameters[chosen_parameter + "_bonus"]);
third_to_last_vocal.value = parameters["vocal"];
third_to_last_dance.value = parameters["dance"];
third_to_last_visual.value = parameters["visual"];
}
//last 3 week
if (start_idx < WEEK_DETAIL.get("second_to_last")) {
const [chosen_parameter, sp] = get_lesson_kind(form.second_to_last_lesson);
const amount = sp ? SECOND_TO_LAST_SP_AMOUNT : SECOND_TO_LAST_LESSON_AMOUNT;
parameters[chosen_parameter] += calc_amount(amount, parameters[chosen_parameter + "_bonus"]);
second_to_last_vocal.value = parameters["vocal"];
second_to_last_dance.value = parameters["dance"];
second_to_last_visual.value = parameters["visual"];
}
//oikomi
if (start_idx < WEEK_DETAIL.get("last")) {
const chosen_parameter = form.last_lesson.value;
parameters[chosen_parameter] += calc_amount(OIKOMI_CLEAR_AMOUNT, parameters[chosen_parameter + "_bonus"]);
PARAMETER_NAMES.forEach(param => {
parameters[param] += calc_amount(OIKOMI_PERFECT_EACH_AMOUNT, parameters[param + "_bonus"]);
})
last_vocal.value = parameters["vocal"];
last_dance.value = parameters["dance"];
last_visual.value = parameters["visual"];
}
//final
let sum_param = 0;
PARAMETER_NAMES.forEach(name => {
parameters[name] += parameter_ranking_bonus;
if (parameters[name] > PARAMETER_LIMIT) {
parameters.is_over = true;
parameters[name] = PARAMETER_LIMIT;
}
sum_param += parameters[name];
});
PARAMETER_NAMES.forEach(param => {
document.getElementById("final_" + param).innerText = parameters[param];
});
// document.getElementById("parameter_sum").innerText = sum_param;
calc_required_scores(sum_param);
}
const calc_required_scores = (sum_param) => {
const param_evaluation = Math.floor(2.3 * sum_param);
const init_evaluation = param_evaluation + ranking_evaluation;
let zero_score_exists = false;
for (const [rank, rank_border] of RANK_EVALUATION_BORDERS) {
let evaluation = init_evaluation;
let required_score = 0;
if (evaluation >= rank_border) {
zero_score_exists = true;
required_score = 0;
document.getElementById(rank + "_score").innerText = "0(*)";
document.getElementById("_" + rank + "_score").innerText = "0(*)";
document.getElementById(rank + "_param").innerText = param_evaluation +
"(" + Math.round(param_evaluation / rank_border * 100) + "%)";
document.getElementById(rank + "_exam").innerText = "-";
document.getElementById(rank + "_pos_rate").innerText = ranking_evaluation + "(" + Math.round(ranking_evaluation / rank_border * 100) + "%)";
} else {
let required_score = 0;
for (const [score_boundary, detail] of SCORE_RATES) {
const tmp = evaluation + detail.max;
if (tmp < rank_border) {
evaluation = tmp;
required_score = score_boundary;
continue;
} else {
const left_required_evaluation = rank_border - evaluation;
const left_required_score = Math.ceil(left_required_evaluation / detail.rate);
required_score = required_score + left_required_score;
break;
//TODO loop by every rank needs duplicate calculation but this prior simplicity of code.
}
}
document.getElementById(rank + "_score").innerText = required_score;
document.getElementById("_" + rank + "_score").innerText = required_score;
document.getElementById(rank + "_param").innerText = param_evaluation +
"(" + Math.round(param_evaluation / rank_border * 100) + "%)";
document.getElementById(rank + "_exam").innerText = (rank_border - init_evaluation) +
"(" + Math.round((rank_border - init_evaluation) / rank_border * 100) + "%)";
document.getElementById(rank + "_pos_rate").innerText = ranking_evaluation + "(" + Math.round(ranking_evaluation / rank_border * 100) + "%)";
}
}
if (zero_score_exists) document.getElementById("zero_score_description").style.display = "block";
else document.getElementById("zero_score_description").style.display = "none";
return;
};
const auto_select_evt = (evt) => {
auto_select(evt.currentTarget.name);
};
const auto_select = (start_week) => {
const start_idx = WEEK_DETAIL.get(start_week);
if (start_week == "last") {
calculate_parameter(start_week);
return;
}
document.querySelectorAll('input[type="radio"]').forEach(radio => {
radio.removeEventListener("change", auto_calculate_parameter);
});
const prior_parameters = Array.from(PARAMETER_NAMES)
.sort((a, b) => get_as_number(b + "_bonus") - get_as_number(a + "_bonus"));
const prior_param = prior_parameters[0];
const prior_param_init_value = get_as_number(start_week + "_" + prior_param) + parameter_ranking_bonus;
if (prior_param_init_value == 0) return;
const prior_param_bonus = get_as_number(prior_param + "_bonus");
const second_param = prior_parameters[1];
let prior_value = prior_param_init_value;
//oikomi
if (start_idx < WEEK_DETAIL.get("last")) {
const tmp = prior_value + calc_amount(OIKOMI_CLEAR_AMOUNT, prior_param_bonus) + calc_amount(OIKOMI_PERFECT_EACH_AMOUNT, prior_param_bonus);
//Some events will raise parameters so set safety margin.
if (tmp > PARAMETER_LIMIT - parameter_ranking_bonus) {
document.getElementById("last_lesson_" + second_param).checked = true;
} else {
document.getElementById("last_lesson_" + prior_param).checked = true;
prior_value = tmp;
}
}
//last 3 week
if (start_idx < WEEK_DETAIL.get("second_to_last")) {
const tmp = prior_value + calc_amount(SECOND_TO_LAST_SP_AMOUNT, prior_param_bonus);
//Some events will raise parameters so set additional 20 safety margin.
if (tmp > PARAMETER_LIMIT - parameter_ranking_bonus - 20) {
document.getElementById("second_to_last_lesson_sp_" + second_param).checked = true;
} else {
document.getElementById("second_to_last_lesson_sp_" + prior_param).checked = true;
prior_value = tmp;
}
}
//last 4 week
if (start_idx < WEEK_DETAIL.get("third_to_last")) {
const tmp = prior_value + calc_amount(THIRD_TO_LAST_SP_AMOUNT, prior_param_bonus);
//Some events will raise parameters so set additional 40 safety margin.
if (tmp > PARAMETER_LIMIT - parameter_ranking_bonus - 40) {
document.getElementById("third_to_last_lesson_sp_" + second_param).checked = true;
} else {
document.getElementById("third_to_last_lesson_sp_" + prior_param).checked = true;
}
}
//Set event again
document.querySelectorAll('input[type="radio"]').forEach(radio => {
radio.addEventListener("change", auto_calculate_parameter);
});
calculate_parameter(start_week);
}
document.getElementById("reset").addEventListener("click", (_evt) => {
document.querySelectorAll(".auto_calculated").forEach((elm) => elm.innerText = "");
});
//auto_select
document.querySelectorAll('input[type="number"]').forEach(input => {
input.addEventListener("click", (evt) => {
evt.target.select();
});
input.addEventListener("input", auto_select_evt);
});
//auto_calculate
document.querySelectorAll('input[type="radio"]').forEach(radio => {
radio.addEventListener("change", auto_calculate_parameter);
});
////Settings
//is_detail_open
let is_detail_open = window.sessionStorage.getItem("is_detail_open");
//string -> boolean
if (is_detail_open == null) is_detail_open = true;//first
else is_detail_open = (is_detail_open == "true")
const score_detail = document.getElementById("score_detail");
score_detail.toggleAttribute("open", is_detail_open);
score_detail.addEventListener("toggle", (_event) => {
window.sessionStorage.setItem("is_detail_open", score_detail.open);
});
const auto_select_checkbox = document.getElementById("auto_select");
auto_select_checkbox.addEventListener("change", () => {
if (auto_select_checkbox.checked) {
document.querySelectorAll('input[type="number"]').forEach(input => {
input.removeEventListener("input", auto_calculate_parameter);
input.addEventListener("input", auto_select_evt);
});
//auto_select("primary");
} else {
document.querySelectorAll('input[type="number"]').forEach(input => {
input.removeEventListener("input", auto_select_evt);
input.addEventListener("input", auto_calculate_parameter);
});
}
});
let ranking_evaluation = 1700;
let parameter_ranking_bonus = 30;
document.getElementById("ranking-select").addEventListener("change", (evt) => {
switch (evt.target.value) {
case '1st':
ranking_evaluation = 1700;
parameter_ranking_bonus = 30;
break
case '2nd':
ranking_evaluation = 900;
parameter_ranking_bonus = 20;
break
case '3rd':
ranking_evaluation = 500;
parameter_ranking_bonus = 10;
break
};
calculate_parameter(start_week = 'last');
});
}