[libgames-support] Scores are now loading again.



commit 22b345cf91d76410d225cb1a202694d0f572ee77
Author: Nikhar Agrawal <nikharagrawal2006 gmail com>
Date:   Mon Feb 23 20:11:13 2015 +0530

    Scores are now loading again.
    
    Basically undid one of the previous commits.
    https://bugzilla.gnome.org/show_bug.cgi?id=744988

 scores/context.vala |   36 +++++++++++++++++++++++++++---------
 1 files changed, 27 insertions(+), 9 deletions(-)
---
diff --git a/scores/context.vala b/scores/context.vala
index 8f983b7..ef0f6dd 100644
--- a/scores/context.vala
+++ b/scores/context.vala
@@ -41,6 +41,7 @@ public class Context : Object
     private Gee.HashMap<Category?, Gee.PriorityQueue<Score> > scores_per_category = new 
Gee.HashMap<Category?, Gee.PriorityQueue<Score> > ((owned) category_hash, (owned) category_equal);
 
     private string user_score_dir;
+    private bool scores_loaded_from_file = false;
 
     /*Comparison and hash functions for Map and Priority Queue.*/
     private CompareDataFunc<Score?> scorecmp;
@@ -77,15 +78,6 @@ public class Context : Object
         this.dialog_label = dialog_label;
 
         user_score_dir = Path.build_filename (Environment.get_user_data_dir (), base_name, null);
-
-        try
-        {
-            load_scores_from_files ();
-        }
-        catch (Error e)
-        {
-            warning ("%s", e.message);
-        }
     }
 
     internal List<Category?> get_categories ()
@@ -150,6 +142,19 @@ public class Context : Object
     /* Return true if a dialog was launched on attaining high score */
     public bool add_score (long score_value, Category category) throws Error
     {
+        if (!scores_loaded_from_file)
+        {
+            try
+            {
+                load_scores_from_files ();
+                scores_loaded_from_file = true;
+            }
+            catch (Error e)
+            {
+                warning ("%s", e.message);
+            }
+        }
+
         var high_score_added = false;
        /* We need to check for game_window to be not null because thats a way to identify if add_score is 
being called by the test file.
           If it's being called by test file, then the dialog wouldn't be run and hence player name wouldn't 
be updated. So, in that case,
@@ -288,6 +293,19 @@ public class Context : Object
     internal void run_dialog_internal (Score? new_high_score) throws Error
         requires (game_window != null)
     {
+        if (!scores_loaded_from_file)
+        {
+            try
+            {
+                load_scores_from_files ();
+                scores_loaded_from_file = true;
+            }
+            catch (Error e)
+            {
+                warning ("%s", e.message);
+            }
+        }
+
         var dialog = new Dialog (this, dialog_label, style, new_high_score, current_category, game_window);
         dialog.run ();
         dialog.destroy ();


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