Commits

Miki Tebeka  committed b82fec8

Settings in on JSON

  • Participants
  • Parent commits 8b0b387

Comments (0)

Files changed (1)

 };
 
 var LEVEL = null;
-var SCORE = 0;
+var NUM_HIGH_SCORES = 6;
+var HIGH_SCORES = [];
 var BLANK = 'blank.png';
+
 /* We cache the images in the board since calling 'cell_color' with jQuery
-   selectors every time is slow
+   selectors every time is slow and we do that a lot.
 */
 var BOARD = [];
 
     restart();
 }
 
-LEVEL_COOKIE = 'ssbd.last_level';
-SCORE_COOKIE = 'ssbd.hight_scores';
+COOKIE_NAME = 'ssbd.settings';
 
-function get_last_level() {
-    var level = $.cookie(LEVEL_COOKIE);
-    if (level == null) {
-        level = 'medium';
+function load_settings() {
+    var settings = {
+        level: 'medium',
+        scores: []
+    }
+    var str = $.cookie(COOKIE_NAME);
+    if (str != null) {
+        try {
+            settings = eval('(' + str + ')');
+        }
+        catch (err) {
+        }
     }
 
-    return level;
+    return settings;
 }
 
 function save_settings() {
-    $.cookie(LEVEL_COOKIE, $('#level').val());
+    var level = $('#level').val();
+    var str = '{level: "' + level + '", scores: [' + HIGH_SCORES + ']}';
+    $.cookie(COOKIE_NAME, str);
+}
+
+function refresh_scores() {
 }
 
 
     $('#restart').click(restart);
     $(window).unload(save_settings);
 
-    var level = get_last_level();
-    $('#level').val(level);
-    change_level(level);
+    var opts = load_settings();
+
+    $('#level').val(opts.level);
+    change_level(opts.level);
+    
+    HIGH_SCORES = opts.scores;
+    refresh_scores();
 }
 
 $(document).ready(on_ready);