# HG changeset patch # User Oleksandr Gavenko # Date 1410370077 -10800 # Node ID 716508d5494c8b2846fe9909c94062e944c052e9 # Parent 359719178176df39802a7b68256d4c2690d9ff40 Save board between browser sessions. diff -r 359719178176 -r 716508d5494c 2048.html --- a/2048.html Wed Sep 10 20:16:06 2014 +0300 +++ b/2048.html Wed Sep 10 20:27:57 2014 +0300 @@ -398,7 +398,7 @@ board.putRandom(board.current); ui.board.update(board.current); ui.score.update(board.current); - localStorage.savedBoard = board.current; + localStorage.savedBoard = JSON.stringify(board.current); } //////////////////////////////////////////////////////////////// @@ -587,8 +587,10 @@ ui.brdEngine = BoardArr2d; // TODO make user selectable if (localStorage.savedBoard) { - board.current = localStorage.savedBoard; - ui.board.update(board.current); + try { + board.current = JSON.parse(localStorage.savedBoard); + ui.board.update(board.current); + } catch (ex) { } } else { ui.action.start(); }