[gnome-chess/gnome-3-8] Chess clock should start after the first move



commit d01eec864a20906642f1691467f617ccb065f850
Author: Michael Catanzaro <mike catanzaro gmail com>
Date:   Tue May 21 18:55:28 2013 -0500

    Chess clock should start after the first move
    
    White should have unlimited time for his first move.

 src/chess-clock.vala |   20 ++++++++++++++------
 src/chess-game.vala  |    1 -
 src/gnome-chess.vala |    3 +++
 3 files changed, 17 insertions(+), 7 deletions(-)
---
diff --git a/src/chess-clock.vala b/src/chess-clock.vala
index c1b8a98..7549841 100644
--- a/src/chess-clock.vala
+++ b/src/chess-clock.vala
@@ -16,7 +16,9 @@ public class ChessClock : Object
     {
         get
         {
-            if (active_color == Color.WHITE)
+            if (timer == null)
+                return 0;
+            else if (active_color == Color.WHITE)
                 return _white_used + (uint) (timer.elapsed () * 1000);
             else
                 return _white_used;
@@ -33,7 +35,9 @@ public class ChessClock : Object
     {
         get
         {
-            if (active_color == Color.WHITE)
+            if (timer == null)
+                return 0;
+            else if (active_color == Color.WHITE)
                 return _black_used;
             else
                 return _black_used + (uint) (timer.elapsed () * 1000);
@@ -60,7 +64,7 @@ public class ChessClock : Object
         }
     }
 
-    private Timer timer;
+    private Timer? timer;
     private uint expire_timeout = 0;
     private uint tick_timeout = 0;
 
@@ -73,7 +77,6 @@ public class ChessClock : Object
         _black_duration = black_duration * 1000;
         _white_used = white_used;
         _black_used = black_used;
-        timer = new Timer ();
     }
     
     private bool is_started
@@ -86,8 +89,13 @@ public class ChessClock : Object
         if (is_started)
             return;
 
-        /* Start stopwatch */
-        timer.start ();
+        if (timer == null)
+        {
+            /* Starts automatically */
+            timer = new Timer ();
+        }
+        else
+            timer.start ();
 
         /* Notify when this timer has expired */
         if (active_color == Color.WHITE)
diff --git a/src/chess-game.vala b/src/chess-game.vala
index 7f73794..2a0060b 100644
--- a/src/chess-game.vala
+++ b/src/chess-game.vala
@@ -1427,7 +1427,6 @@ public class ChessGame
         {
             _clock.expired.connect (clock_expired_cb);
             _clock.active_color = current_player.color;
-            _clock.start ();
         }
 
         started ();
diff --git a/src/gnome-chess.vala b/src/gnome-chess.vala
index c97cd12..15b0bf7 100644
--- a/src/gnome-chess.vala
+++ b/src/gnome-chess.vala
@@ -491,6 +491,9 @@ public class Application : Gtk.Application
         save_menu.sensitive = in_history;
         game.start ();
 
+        if (moves.length > 0)
+            game.clock.start ();
+
         if (game.result != ChessResult.IN_PROGRESS)
             game_end_cb (game);
 


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