[gnome-mines/wip/libgames-support: 1/5] Using libgames-support to track scores.



commit afb2530814b91c50e4b8d40a987517d301097338
Author: Nikhar Agrawal <nikharagrawal2006 gmail com>
Date:   Mon Mar 2 19:40:25 2015 +0530

    Using libgames-support to track scores.
    
    Changes made in a new branch.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=730057

 configure.ac          |    1 +
 src/Makefile.am       |    3 +-
 src/gnome-mines.vala  |   55 ++++++++++------
 src/history.vala      |  118 ---------------------------------
 src/score-dialog.vala |  174 -------------------------------------------------
 5 files changed, 36 insertions(+), 315 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 7e4fd69..bc012f8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -26,6 +26,7 @@ PKG_CHECK_MODULES(GNOME_MINES, [
   glib-2.0 >= $GLIB_REQUIRED
   gtk+-3.0 >= $GTK_REQUIRED
   librsvg-2.0 >= $RSVG_REQUIRED
+  libgames-support
 ])
 
 AC_SUBST([GLIB_REQUIRED])
diff --git a/src/Makefile.am b/src/Makefile.am
index 742d462..8089049 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -3,10 +3,8 @@ bin_PROGRAMS = gnome-mines
 gnome_mines_SOURCES =  \
        config.vapi     \
        gnome-mines.vala \
-       history.vala \
        minefield.vala \
        minefield-view.vala \
-       score-dialog.vala \
        tile.vala \
        theme-selector-dialog.vala
 
@@ -24,6 +22,7 @@ gnome_mines_VALAFLAGS = \
        --pkg librsvg-2.0 \
        --pkg pango \
        --pkg pangocairo \
+       --pkg games-support \
        --target-glib $(GLIB_REQUIRED)
 
 gnome_mines_LDADD = \
diff --git a/src/gnome-mines.vala b/src/gnome-mines.vala
index 886bbb4..641c45d 100644
--- a/src/gnome-mines.vala
+++ b/src/gnome-mines.vala
@@ -63,8 +63,8 @@ public class Mines : Gtk.Application
     /* true when the next configure event should be ignored. */
     private bool window_skip_configure;
 
-    /* Game history */
-    private History history;
+    /* Game scores */
+    private Games.Scores.Context context;
 
     /* Minefield being played */
     private Minefield minefield;
@@ -311,8 +311,8 @@ public class Mines : Gtk.Application
         /* Initialize Custom Game Screen */
         startup_custom_game_screen (ui_builder);
 
-        history = new History (Path.build_filename (Environment.get_user_data_dir (), "gnome-mines", 
"history"));
-        history.load ();
+        context = new Games.Scores.Context ("gnome-mines", "Mines", window, 
Games.Scores.Style.TIME_ASCENDING);
+        context.category_request.connect  (create_category_from_key);
 
         flag_label = (Gtk.Label) ui_builder.get_object ("flag_label");
         clock_label = (Gtk.Label) ui_builder.get_object ("clock_label");
@@ -328,6 +328,16 @@ public class Mines : Gtk.Application
             start_game ();
     }
 
+    private Games.Scores.Category? create_category_from_key (string key)
+    {
+        var tokens = key.split ("-");
+
+        if (tokens.length != 3)
+            return null;
+
+        return new Games.Scores.Category (key, tokens[0] + " × " + tokens[1] + ", " + tokens[2] + " mines");
+    }
+
     private void startup_new_game_screen (Gtk.Builder builder)
     {
         new_game_screen =  (Gtk.AspectFrame) builder.get_object ("new_game_screen");
@@ -519,16 +529,16 @@ public class Mines : Gtk.Application
         return result;
     }
 
-    private int show_scores (HistoryEntry? selected_entry = null, bool show_close = false)
+    private void show_scores ()
     {
-        var dialog = new ScoreDialog (history, selected_entry, show_close);
-        dialog.modal = true;
-        dialog.transient_for = window;
-
-        var result = dialog.run ();
-        dialog.destroy ();
-
-        return result;
+        try
+        {
+            context.run_dialog ();
+        }
+        catch (Error e)
+        {
+            warning ("%s", e.message);
+        }
     }
 
     private void scores_cb ()
@@ -737,16 +747,19 @@ public class Mines : Gtk.Application
 
     private void cleared_cb (Minefield minefield)
     {
-        var date = new DateTime.now_local ();
         var duration = (uint) (minefield.elapsed + 0.5);
-        var entry = new HistoryEntry (date, minefield.width, minefield.height, minefield.n_mines, duration);
-        history.add (entry);
-        history.save ();
+        string key = minefield.width.to_string () + "-" + minefield.height.to_string () + "-" + 
minefield.n_mines.to_string ();
 
-        if (show_scores (entry, true) == Gtk.ResponseType.OK)
-            show_new_game_screen ();
-        else
-            game_ended ();
+        try
+        {
+            context.add_score (duration, create_category_from_key (key)) ;
+        }
+        catch (Error e)
+        {
+            warning ("%s", e.message);
+        }
+
+       show_new_game_screen ();
     }
 
     private void clock_started_cb ()


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