[gnome-2048] Improve loading of complete game.



commit f2d4d63462538aa27062ec35b31efe659672be59
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Wed Feb 13 15:20:33 2019 +0100

    Improve loading of complete game.
    
    There's a small timeout for
    showing the "finished game"
    notification (as a subtitle
    in the headerbar), but that
    shouldn't apply if loading.

 src/game-window.vala | 10 +++-------
 src/game.vala        | 17 ++++++++++++++---
 2 files changed, 17 insertions(+), 10 deletions(-)
---
diff --git a/src/game-window.vala b/src/game-window.vala
index 3e16866..e855352 100644
--- a/src/game-window.vala
+++ b/src/game-window.vala
@@ -37,7 +37,6 @@ private class GameWindow : ApplicationWindow
     [GtkChild] private GtkClutter.Embed _embed;
 
     private Game _game;
-    private bool _game_restored;
     private bool _game_should_init = true;
 
     construct
@@ -55,8 +54,7 @@ private class GameWindow : ApplicationWindow
         show_all ();
         _init_gesture ();
 
-        _game_restored = _game.restore_game (ref _settings);
-        if (!_game_restored)
+        if (!_game.restore_game (ref _settings))
             new_game_cb ();
         _game_should_init = false;
     }
@@ -114,10 +112,10 @@ private class GameWindow : ApplicationWindow
     {
         _game = new Game (ref _settings);
         _game.notify ["score"].connect (_header_bar.set_score);
-        _game.finished.connect ((s) => {
+        _game.finished.connect ((show_scores) => {
                 _header_bar.finished ();
 
-                if (!_game_restored)
+                if (show_scores)
                     _show_best_scores ();
 
                 debug ("finished");
@@ -186,7 +184,6 @@ private class GameWindow : ApplicationWindow
     private void new_game_cb (/* SimpleAction action, Variant? variant */)
     {
         _header_bar.clear_subtitle ();
-        _game_restored = false;
 
         _game.new_game (ref _settings);
 
@@ -463,7 +460,6 @@ private class GameWindow : ApplicationWindow
         if (_game_should_init)
             return;
 
-        _game_restored = false;
         _game.move (request);
     }
 }
diff --git a/src/game.vala b/src/game.vala
index 1abbdca..cee4afb 100644
--- a/src/game.vala
+++ b/src/game.vala
@@ -99,6 +99,8 @@ private class Game : Object
     * * others
     \*/
 
+    private bool _just_restored = true;
+
     [CCode (notify = true)] internal long score { internal get; private set; default = 0; }
 
     internal void new_game (ref GLib.Settings settings)
@@ -128,6 +130,8 @@ private class Game : Object
         _state = GameState.SHOWING_FIRST_TILE;
         _create_random_tile ();
         undo_disabled ();
+
+        _just_restored = false;
     }
 
     internal void save_game ()
@@ -177,6 +181,8 @@ private class Game : Object
             settings.apply ();
         }
 
+        _just_restored = true;
+
         debug ("game restored successfully");
         return true;
     }
@@ -504,6 +510,8 @@ private class Game : Object
             _move_trans.start ();
             _store_movement (clone);
         }
+
+        _just_restored = false;
     }
 
     private void _on_move_trans_stopped (Clutter.Timeline trans, bool is_finished)
@@ -537,7 +545,7 @@ private class Game : Object
     * * new tile animation
     \*/
 
-    internal signal void finished ();
+    internal signal void finished (bool show_scores);
     internal signal void target_value_reached (uint val);
 
     private uint _finish_move_id = 0;
@@ -629,13 +637,16 @@ private class Game : Object
             _grid.target_value_reached = false;
         }
 
-        _finish_move_id = GLib.Timeout.add (100, _finish_move);
+        if (_just_restored)
+            finished (/* show scores */ false);
+        else
+            _finish_move_id = GLib.Timeout.add (100, _finish_move);
     }
 
     private bool _finish_move ()
     {
         if (_grid.is_finished ())
-            finished ();
+            finished (/* show scores */ true);
 
         _finish_move_id = 0;
         return false;


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