1
- // NOTE: because Quick Fire and Classic share a lot of features,
2
- // the code behind Quick Fire mode was added to this file instead
3
- // of a separate folders-quickfire.js
1
+ // NOTE: this file contains the code behind the Classic, Classic Infinite, and
2
+ // Quick Fire modes on VTP6. They were bundled together because they share a lot of
3
+ // features with each other, and so some code can be reused.
4
+
5
+ // NOTE: this is going to be very confusing, but whenever the code mentions
6
+ // `classic` mode, this means "Classic Infinite" mode. "Classic" mode is referred to
7
+ // as `legacy` mode in the code. This is because what is now "Classic Infinite" mode
8
+ // was originally called "Classic" mode, and what is now "Classic" mode was added
9
+ // in later at the request of a VTP6 user.
4
10
5
11
let full_terms_list = [ ] ;
6
12
let randomised_terms = [ ] ;
@@ -27,7 +33,9 @@ function set_progress_bar_background(val) {
27
33
. style . width = `${ 100 - val } %` ;
28
34
}
29
35
30
- function new_question ( ) {
36
+ function new_question ( reload = true ) {
37
+ if ( randomised_terms . length === 0 && ! reload ) return false ;
38
+
31
39
[ question , answer ] = randomised_terms . shift ( ) ;
32
40
document . getElementById ( "classic-question-text" ) . innerHTML = sanitise ( question ) ;
33
41
@@ -38,9 +46,10 @@ function new_question() {
38
46
if ( OPTIONS [ "all" ] ) document . getElementById ( "classic-question-text" ) . innerHTML +=
39
47
` (<span id="classic-all-num">0</span>/${ split_answer . length } )` ;
40
48
41
- if ( randomised_terms . length === 0 ) randomised_terms = random_shuffle ( full_terms_list ) ;
49
+ if ( randomised_terms . length === 0 && reload ) randomised_terms = random_shuffle ( [ ... full_terms_list ] ) ;
42
50
43
51
textbox . focus ( ) ;
52
+ return true ;
44
53
}
45
54
46
55
function update_bar_text ( ) {
@@ -158,6 +167,71 @@ function check_input_classic() {
158
167
update_bar_text ( ) ;
159
168
}
160
169
170
+ function check_input_legacy ( ) {
171
+ let result = check_input ( userans = textbox . value ) ;
172
+ let cont = true ;
173
+
174
+ if ( result === undefined ) return ;
175
+
176
+ textbox . classList . remove ( "correct" ) ;
177
+ textbox . classList . remove ( "wrong" ) ;
178
+ textbox . offsetWidth ;
179
+
180
+ if ( OPTIONS [ "all" ] ) {
181
+ if ( result ) {
182
+ textbox . classList . add ( "correct" ) ;
183
+ split_answer = split_answer . filter ( l =>
184
+ ! l . map ( remove_punctuation )
185
+ . includes ( remove_punctuation ( userans ) )
186
+ ) ;
187
+ if ( split_answer . length === 0 ) {
188
+ correct ++ ;
189
+ document . getElementById ( "typo-text" ) . innerHTML = `
190
+ <span class="green">Correct!</span>
191
+ ` ;
192
+ cont = new_question ( false ) ;
193
+ } else {
194
+ let n = document . getElementById ( "classic-all-num" ) ;
195
+ n . innerHTML = + n . innerHTML + 1 ;
196
+ document . getElementById ( "typo-text" ) . innerHTML = `
197
+ <span class="green">Keep going!</span>
198
+ ` ;
199
+ }
200
+ } else {
201
+ wrong ++ ;
202
+ textbox . classList . add ( "wrong" ) ;
203
+ document . getElementById ( "typo-text" ) . innerHTML = `
204
+ <span class="red">Wrong:</span>
205
+ ${ answer }
206
+ ` ;
207
+ wrongtbl . push ( [ question , answer , userans ] ) ;
208
+ cont = new_question ( false ) ;
209
+ }
210
+ } else {
211
+ if ( result ) {
212
+ correct ++ ;
213
+ textbox . classList . add ( "correct" ) ;
214
+ document . getElementById ( "typo-text" ) . innerHTML = `
215
+ <span class="green">Correct!</span>
216
+ ` ;
217
+ } else {
218
+ wrong ++ ;
219
+ textbox . classList . add ( "wrong" ) ;
220
+ document . getElementById ( "typo-text" ) . innerHTML = `
221
+ <span class="red">Wrong:</span>
222
+ ${ answer }
223
+ ` ;
224
+ wrongtbl . push ( [ question , answer , userans ] ) ;
225
+ }
226
+ cont = new_question ( false ) ;
227
+ }
228
+ update_bar_text ( ) ;
229
+
230
+ if ( ! cont ) {
231
+ finish_legacy_game ( ) ;
232
+ }
233
+ }
234
+
161
235
function check_input_quickfire ( ) {
162
236
let result = check_input ( userans = textbox . value ) ;
163
237
@@ -289,6 +363,99 @@ function finish_classic_game() {
289
363
}
290
364
}
291
365
366
+ function finish_legacy_game ( ) {
367
+ if ( randomised_terms . length === 0 || window . confirm ( "Are you sure you want to finish the game?" ) ) {
368
+ document . getElementById ( "classic-div" ) . remove ( ) ;
369
+ let finish_div = document . createElement ( "div" ) ;
370
+ finish_div . innerHTML = `
371
+ <div id="score-div">
372
+ <h3>${ correct } /${ correct + wrong } (${ ( correct / ( ( correct + wrong ) || 1 ) * 100 ) . toPrecision ( 3 ) } %)</h3>
373
+ </div>
374
+ <div id="restart-button-div">
375
+ <button class="start-button" id="classic-retry-button"
376
+ ${ wrongtbl . length === 0 ? 'disabled' : '' } >Mistakes</button>
377
+ <button class="start-button" id="classic-restart-button">Restart!</button>
378
+ </div>
379
+ <table id="wrong-table">
380
+ <tr>
381
+ <th>Term</th>
382
+ <th>Definition</th>
383
+ <th>Your Answer</th>
384
+ </tr>
385
+ </table>
386
+ ` ;
387
+ finish_div . id = "finish-div" ;
388
+ document . getElementById ( "content" )
389
+ . insertBefore ( finish_div , document . getElementById ( "margin" ) ) ;
390
+
391
+ [ ...wrongtbl ] . forEach ( row => {
392
+ let [ a , b , c ] = row ;
393
+ let tr = document . createElement ( "tr" ) ;
394
+ tr . innerHTML = `
395
+ <td>${ a } </td> <td>${ b } </td>
396
+ <td><em>${ c } </em></td>
397
+ ` ;
398
+ document . getElementById ( "wrong-table" ) . appendChild ( tr ) ;
399
+ } ) ;
400
+
401
+ document . getElementById ( "classic-restart-button" )
402
+ . addEventListener ( "click" , ( ) => {
403
+ document . getElementById ( "finish-div" ) . remove ( ) ;
404
+ document . getElementById ( "settings-bar" ) . hidden = false ;
405
+ document . getElementById ( "units-flex" ) . style . display = "flex" ;
406
+
407
+ full_terms_list = [ ] ;
408
+ randomised_terms = [ ] ;
409
+
410
+ [ question , answer ] = [ "" , "" ] ;
411
+
412
+ split_answer = [ ] ;
413
+
414
+ textbox = undefined ;
415
+
416
+ correct = 0 ;
417
+ wrong = 0 ;
418
+
419
+ wrongtbl = [ ] ;
420
+
421
+ quickfire_timer = 150 ;
422
+ quickfire_timer_id = 0 ;
423
+ quickfire_increment = 30 ;
424
+ } ) ;
425
+
426
+ document . getElementById ( "classic-retry-button" )
427
+ . addEventListener ( "click" , ( ) => {
428
+ let mistakes = [ ...wrongtbl ] . map ( ( [ x , y , _ ] ) => [ x , y ] ) ;
429
+
430
+ document . getElementById ( "finish-div" ) . remove ( ) ;
431
+ document . getElementById ( "settings-bar" ) . hidden = false ;
432
+ document . getElementById ( "units-flex" ) . style . display = "flex" ;
433
+
434
+ full_terms_list = [ ] ;
435
+ randomised_terms = [ ] ;
436
+
437
+ [ question , answer ] = [ "" , "" ] ;
438
+
439
+ split_answer = [ ] ;
440
+
441
+ textbox = undefined ;
442
+
443
+ correct = 0 ;
444
+ wrong = 0 ;
445
+
446
+ wrongtbl = [ ] ;
447
+
448
+ quickfire_timer = 150 ;
449
+ quickfire_timer_id = 0 ;
450
+ quickfire_increment = 30 ;
451
+
452
+ folders_start_legacy ( [ ...mistakes ] ) ;
453
+ document . getElementById ( "settings-bar" ) . hidden = true ;
454
+ document . getElementById ( "units-flex" ) . style . display = "none" ;
455
+ } )
456
+ }
457
+ }
458
+
292
459
function set_quickfire_high_score ( score ) {
293
460
let currenths = get_cookies ( ) [ "vtp6HighScore_quick_fire" ] ;
294
461
if ( currenths === undefined || score > + currenths ) {
@@ -411,6 +578,53 @@ function folders_start_classic(terms) {
411
578
new_question ( ) ;
412
579
}
413
580
581
+ function folders_start_legacy ( terms ) {
582
+ full_terms_list = [ ...terms ] ;
583
+ randomised_terms = random_shuffle ( terms ) ;
584
+
585
+ let classic_div = document . createElement ( "div" ) ;
586
+ classic_div . innerHTML = `
587
+ <div id="progress-bar-div">
588
+ <div id="progress-bar-container"><div id="progress-bar"></div></div>
589
+ <span id="progress-bar-text">0/0 (0.00%)</span>
590
+ </div>
591
+ <h1 id="classic-question">
592
+ <button class="start-button" id="skip-button">Skip →</button>
593
+ <span id="classic-question-text"></span>
594
+ <button class="start-button" id="finish-button">Finish!</button>
595
+ </h1>
596
+ <div id="input-div">
597
+ <input type="text" id="classic-input"
598
+ placeholder="Type the definition here..."
599
+ autocomplete="off" autocorrect="off"
600
+ spellcheck="false" />
601
+ <button class="start-button" id="square-finish-button"><img id="finish-image" /></button>
602
+ </div>
603
+ <p id="typo-text"> </p>
604
+ ` ;
605
+ classic_div . id = "classic-div" ;
606
+ document . getElementById ( "content" )
607
+ . insertBefore ( classic_div , document . getElementById ( "margin" ) ) ;
608
+
609
+ textbox = document . getElementById ( "classic-input" ) ;
610
+
611
+ document . getElementById ( "skip-button" ) . addEventListener ( "click" , ( ) =>
612
+ ( textbox . value = "" ) || check_input_legacy ( )
613
+ ) ;
614
+
615
+ document . getElementById ( "finish-button" ) . addEventListener ( "click" , finish_legacy_game ) ;
616
+ document . getElementById ( "square-finish-button" ) . addEventListener ( "click" , finish_legacy_game ) ;
617
+
618
+ textbox . addEventListener ( "keyup" , ( { key } ) => {
619
+ if ( key === "Enter" ) {
620
+ check_input_legacy ( ) ;
621
+ }
622
+ } ) ;
623
+
624
+ window . scrollTo ( 0 , 0 ) ;
625
+ new_question ( false ) ;
626
+ }
627
+
414
628
function folders_start_quickfire ( terms ) {
415
629
full_terms_list = [ ...terms ] ;
416
630
randomised_terms = random_shuffle ( terms ) ;
0 commit comments