[gnome-sudoku] Show board's saved difficulty rating label as the Headerbar subtitle



commit 78bd8b581defe4f21635a4919c4e5971f885dbb6
Author: Parin Porecha <parinporecha gmail com>
Date:   Sun Jun 15 21:00:07 2014 +0530

    Show board's saved difficulty rating label as the Headerbar subtitle
    
    Solving a board and generating a rating by that causes bug -
    https://bugzilla.gnome.org/show_bug.cgi?id=731646
    From now on, Sudokurater will not be used to get the board's difficulty

 src/gnome-sudoku.vala |    7 ++++---
 src/sudoku-board.vala |    2 +-
 src/sudoku-saver.vala |    5 +++++
 3 files changed, 10 insertions(+), 4 deletions(-)
---
diff --git a/src/gnome-sudoku.vala b/src/gnome-sudoku.vala
index e92cf6b..f79ab76 100644
--- a/src/gnome-sudoku.vala
+++ b/src/gnome-sudoku.vala
@@ -198,6 +198,7 @@ public class Sudoku : Gtk.Application
 
         var rater = new SudokuRater(ref completed_board);
         var rating = rater.get_difficulty ();
+        var difficulty_category = board.get_difficulty_category ();
         debug ("\n%s", rating.to_string ());
         undo_action.set_enabled (false);
         redo_action.set_enabled (false);
@@ -206,7 +207,7 @@ public class Sudoku : Gtk.Application
             grid_box.remove (view);
         }
 
-        header_bar_subtitle = rating.get_category ().to_string ();
+        header_bar_subtitle = difficulty_category.to_string ();
         back_cb ();
 
         game = new SudokuGame (board);
@@ -249,12 +250,12 @@ public class Sudoku : Gtk.Application
                 switch (response_id)
                 {
                     case 0:
-                        start_game (sudoku_store.get_random_board (rating.get_category ()));
+                        start_game (sudoku_store.get_random_board (difficulty_category));
                         break;
                     case 1:
                         DifficultyCategory[] new_range = {};
                         for (var i = 0; i < 4; i++)
-                            if (i != (int) rating.get_category ())
+                            if (i != (int) difficulty_category)
                                 new_range += (DifficultyCategory) i;
 
                         start_game (sudoku_store.get_random_board (new_range[Random.int_range (0, 3)]));
diff --git a/src/sudoku-board.vala b/src/sudoku-board.vala
index 5a623a1..49ae020 100644
--- a/src/sudoku-board.vala
+++ b/src/sudoku-board.vala
@@ -67,7 +67,7 @@ public class SudokuBoard : Object
         get { return _filled == _cols * _rows && !broken; }
     }
 
-    public double difficulty_rating { get; private set; }
+    public double difficulty_rating;
 
     private bool in_range (float[] range)
     {
diff --git a/src/sudoku-saver.vala b/src/sudoku-saver.vala
index 68dec85..d9a4883 100644
--- a/src/sudoku-saver.vala
+++ b/src/sudoku-saver.vala
@@ -207,6 +207,11 @@ public class SudokuSaver : Object
         board.previous_played_time = reader.get_double_value ();
         reader.end_member ();
 
+        reader.read_member ("difficulty_rating");
+        return_val_if_fail (reader.is_value (), null);
+        board.difficulty_rating = reader.get_double_value ();
+        reader.end_member ();
+
         return new SudokuGame (board);
     }
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]