Browse code

Solución de errores; falta ver por código duplicado

NikaZhenya authored on 27/09/2018 18:29:29
Showing 1 changed files
... ...
@@ -9,8 +9,7 @@ var foo = (function() {
9 9
     var game_opt
10 10
 
11 11
     // Variables que van cambiando
12
-    var incomplete_word = '',
13
-        touch_old = null,
12
+    var touch_old = null,
14 13
         touch_timer,
15 14
         game_timer,
16 15
         bar_timer
... ...
@@ -626,18 +625,19 @@ var foo = (function() {
626 625
             if (current_w[i] == correct_w[i]) {
627 626
                 // Guarda la palabra si tiene separación silábica
628 627
                 if (correct_w[i].charAt(correct_w[i].length - 1) == '-') {
629
-                    incomplete_word = correct_w[i]
628
+                    localStorage.setItem('incomplete_word', correct_w[i])
630 629
                 // Se completa una palabra si estaba separada
631
-                } else if (incomplete_word != null && incomplete_word != '') {
632
-                    word = (incomplete_word + correct_w[i]).replace('-', '')
633
-                    incomplete_word = ''
630
+                } else if (localStorage.getItem('incomplete_word') != null && localStorage.getItem('incomplete_word') != 'null' && localStorage.getItem('incomplete_word') != '') {
631
+                    word = (localStorage.getItem('incomplete_word') + correct_w[i]).replace('-', '')
632
+                    localStorage.removeItem('incomplete_word')
634 633
                 // Palabra no interrumpida por separación silábica
635
-                } else if (incomplete_word != null) {
634
+                } else if (localStorage.getItem('incomplete_word') != 'null') {
636 635
                     word = correct_w[i]
637 636
                 }
638 637
 
639 638
                 // Resetea
640
-                if (incomplete_word == null) incomplete_word = ''
639
+                if (localStorage.getItem('incomplete_word') == 'null')
640
+                    localStorage.removeItem('incomplete_word')
641 641
 
642 642
                 // Añade la palabra
643 643
                 if (word != '') add_word(word)
... ...
@@ -646,9 +646,9 @@ var foo = (function() {
646 646
             } else {
647 647
                 // Cuando era una palabra con separación silábica se marca nulo para detectarla y rechazar el resto de la palabra
648 648
                 if (correct_w[i].charAt(correct_w[i].length - 1) == '-')
649
-                    incomplete_word = null
649
+                    localStorage.setItem('incomplete_word', null)
650 650
                 // Resetea
651
-                else incomplete_word = ''
651
+                else localStorage.removeItem('incomplete_word')
652 652
             }
653 653
         }
654 654
     }
... ...
@@ -727,6 +727,9 @@ var foo = (function() {
727 727
             exec_fn(game_opt.on_win)
728 728
         }
729 729
 
730
+        // Ya no es necesario y puede ser conflictivo
731
+        localStorage.removeItem('incomplete_word')
732
+
730 733
         game_opt.win = true
731 734
     }
732 735
 
... ...
@@ -1254,9 +1257,11 @@ var foo = (function() {
1254 1257
 
1255 1258
                             // Se fija variable
1256 1259
                             if (div.id.split('-')[1] == 'score') {
1257
-                                game_opt.score     = JSON.parse(localStorage[opt.type + '_' + game_opt.lang])[div.id.split('-')[1]]
1260
+                                game_opt.score = JSON.parse(localStorage[opt.type + '_' + game_opt.lang])[div.id.split('-')[1]]
1258 1261
                                 foo.data.score = game_opt.score
1259 1262
                                 p.innerHTML    = game_opt.score
1263
+
1264
+                                foo.data.new_words = localStorage.getItem(opt.type + '_words_' + game_opt.lang) != null ? JSON.parse(localStorage.getItem(opt.type + '_words_' + game_opt.lang)).words : []
1260 1265
                             } else {
1261 1266
                                 game_opt.time      = JSON.parse(localStorage[opt.type + '_' + game_opt.lang])[div.id.split('-')[1]]
1262 1267
                                 foo.data.time  = game_opt.time