[lightsoff/wip/gtkview] More refactoring for current level maintenance



commit c6802e8fdbc1e7abaed2b331b0a5b39312a438e6
Author: Robert Roth <robert roth off gmail com>
Date:   Tue Jul 17 19:30:39 2018 +0300

    More refactoring for current level maintenance

 src/board-view-clutter.vala | 14 +++++++-------
 src/game-view-clutter.vala  | 10 ++++------
 src/game-view-gtk.vala      | 12 ++++++------
 3 files changed, 17 insertions(+), 19 deletions(-)
---
diff --git a/src/board-view-clutter.vala b/src/board-view-clutter.vala
index f8b4e87..ca00eb4 100644
--- a/src/board-view-clutter.vala
+++ b/src/board-view-clutter.vala
@@ -23,7 +23,7 @@ private class Light : Clutter.Group
         {
             value = value != false;
             if (value != _is_lit)
-                toggle ();
+                toggle_pixel ();
         }
     }
 
@@ -53,7 +53,7 @@ private class Light : Clutter.Group
 
     }
 
-    public void toggle (Clutter.Timeline? timeline = null)
+    public void toggle_pixel (Clutter.Timeline? timeline = null)
     {
         _is_lit = !_is_lit;
 
@@ -155,15 +155,15 @@ public class BoardViewClutter : Clutter.Group, BoardView
         }
 
         if ((int) x + 1 < size)
-            lights[(int) x + 1, (int) y].toggle (timeline);
+            lights[(int) x + 1, (int) y].toggle_pixel (timeline);
         if ((int) x - 1 >= 0)
-            lights[(int) x - 1, (int) y].toggle (timeline);
+            lights[(int) x - 1, (int) y].toggle_pixel (timeline);
         if ((int) y + 1 < size)
-            lights[(int) x, (int) y + 1].toggle (timeline);
+            lights[(int) x, (int) y + 1].toggle_pixel (timeline);
         if ((int) y - 1 >= 0)
-            lights[(int) x, (int) y - 1].toggle (timeline);
+            lights[(int) x, (int) y - 1].toggle_pixel (timeline);
 
-        lights[(int) x, (int) y].toggle (timeline);
+        lights[(int) x, (int) y].toggle_pixel (timeline);
 
         if (animate)
             timeline.start ();
diff --git a/src/game-view-clutter.vala b/src/game-view-clutter.vala
index 997ef58..7359e8b 100644
--- a/src/game-view-clutter.vala
+++ b/src/game-view-clutter.vala
@@ -79,8 +79,7 @@ public class ClutterGameView : Clutter.Group, GameView
         board_group = new Clutter.Actor ();
         add_child (board_group);
 
-        current_level = level;
-        board_view = create_board_view (current_level) as BoardViewClutter;
+        board_view = create_board_view (level) as BoardViewClutter;
         board_view.playable = true;
         board_group.add_child (board_view);
 
@@ -96,6 +95,7 @@ public class ClutterGameView : Clutter.Group, GameView
 
     public BoardView create_board_view (int level)
     {
+        current_level = level;
         var view = new BoardViewClutter (off_texture, on_texture);
         view.load_level (level);
         view.game_won.connect (() => game_won_cb());
@@ -237,12 +237,10 @@ public class ClutterGameView : Clutter.Group, GameView
 
     public void reset_game ()
     {
-        if (timeline != null && timeline.is_playing ())
+        if (is_transitioning ())
             return;
 
-        current_level = 1;
-
-        replace_board (board_view, create_board_view (current_level), GameView.ReplaceStyle.REFRESH);
+        replace_board (get_board_view (), create_board_view (1), GameView.ReplaceStyle.REFRESH);
     }
 
     public BoardView get_board_view ()
diff --git a/src/game-view-gtk.vala b/src/game-view-gtk.vala
index eac83e6..40c5aa5 100644
--- a/src/game-view-gtk.vala
+++ b/src/game-view-gtk.vala
@@ -52,22 +52,22 @@ public class GtkGameView : Gtk.Stack, GameView {
 
     public void reset_game ()
     {
-        current_level = 1;
-        replace_board (board_view, create_board_view (current_level), GameView.ReplaceStyle.REFRESH);
+        if (is_transitioning())
+            return;
+        replace_board (get_board_view (), create_board_view (1), GameView.ReplaceStyle.REFRESH);
     }
 
     public GtkGameView (int level)
     {
-                /* Clear level */
-        current_level = level;
-
-        board_view = create_board_view (current_level) as BoardViewGtk;
+        board_view = create_board_view (level) as BoardViewGtk;
         board_view.playable = true;
         add (board_view);
     }
 
     public BoardView create_board_view (int level)
     {
+        current_level = level;
+
         var view = new BoardViewGtk ();
         view.load_level (level);
         view.game_won.connect (() => game_won_cb());


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