[lightsoff/wip/gtkview] Game-view simplifications



commit cef8ea84745a4d1a89d474b5eb7eba6820fecb50
Author: Robert Roth <robert roth off gmail com>
Date:   Mon Jul 16 23:26:07 2018 +0300

    Game-view simplifications

 src/game-view-clutter.vala | 19 +++++++------------
 src/game-view-gtk.vala     | 20 +++++++-------------
 src/game-view.vala         |  2 +-
 3 files changed, 15 insertions(+), 26 deletions(-)
---
diff --git a/src/game-view-clutter.vala b/src/game-view-clutter.vala
index cbe0957..cd32bf0 100644
--- a/src/game-view-clutter.vala
+++ b/src/game-view-clutter.vala
@@ -132,10 +132,7 @@ public class ClutterGameView : Clutter.Group, GameView
         if (timeline != null && timeline.is_playing ())
             return;
 
-        current_level++;
-
-        new_board_view = create_board_view (current_level);
-        replace_board (board_view, new_board_view, GameView.ReplaceStyle.SLIDE_NEXT);
+        board_view = replace_board (board_view, create_board_view (++current_level), 
GameView.ReplaceStyle.SLIDE_NEXT) as BoardViewClutter;
         level_changed (current_level);
     }
 
@@ -155,17 +152,16 @@ public class ClutterGameView : Clutter.Group, GameView
             return;
         }
 
-        new_board_view = create_board_view (current_level);
-
-        replace_board (board_view, new_board_view, 
+        board_view = replace_board (board_view, create_board_view (current_level),
                        direction == 1 ? GameView.ReplaceStyle.SLIDE_FORWARD 
-                                      : GameView.ReplaceStyle.SLIDE_BACKWARD);
+                                      : GameView.ReplaceStyle.SLIDE_BACKWARD) as BoardViewClutter;
 
         level_changed (current_level);
     }
 
-    public void replace_board (BoardView old_board, BoardView new_board, GameView.ReplaceStyle style, bool 
fast = true)
+    public BoardView replace_board (BoardView old_board, BoardView new_board, GameView.ReplaceStyle style, 
bool fast = true)
     {
+        new_board_view = new_board as BoardViewClutter;
         timeline = new Clutter.Timeline (fast ? 500 : 1500);
         board_group.add_child (new_board as Clutter.Group);
         int direction = 1;
@@ -230,6 +226,7 @@ public class ClutterGameView : Clutter.Group, GameView
         } 
 
         timeline.completed.connect (transition_complete_cb);
+        return new_board;
     }
 
 
@@ -287,9 +284,7 @@ public class ClutterGameView : Clutter.Group, GameView
 
         current_level = 1;
 
-        new_board_view = create_board_view (current_level);
-
-        replace_board (board_view, new_board_view, GameView.ReplaceStyle.REFRESH);
+        board_view = replace_board (board_view, create_board_view (current_level), 
GameView.ReplaceStyle.REFRESH) as BoardViewClutter;
 
         level_changed (current_level);
     }
diff --git a/src/game-view-gtk.vala b/src/game-view-gtk.vala
index daa09c7..2e96769 100644
--- a/src/game-view-gtk.vala
+++ b/src/game-view-gtk.vala
@@ -1,21 +1,18 @@
 public class GtkGameView : Gtk.Stack, GameView {
 
     private BoardViewGtk board_view;
-    private BoardViewGtk? new_board_view = null;
     private int current_level;
 
     public void swap_board (int direction)
     {
         current_level += direction;
-        new_board_view = create_board_view (current_level);
-        replace_board (board_view, new_board_view, 
+        board_view = replace_board (board_view, create_board_view (current_level),
                        direction == 1 ? GameView.ReplaceStyle.SLIDE_FORWARD 
-                                      : GameView.ReplaceStyle.SLIDE_BACKWARD);
-        board_view = new_board_view;
+                                      : GameView.ReplaceStyle.SLIDE_BACKWARD) as BoardViewGtk;
         level_changed (current_level);
     }
 
-    public void replace_board (BoardView old_board, BoardView new_board, GameView.ReplaceStyle style, bool 
fast = true)
+    public BoardView replace_board (BoardView old_board, BoardView new_board, GameView.ReplaceStyle style, 
bool fast = true)
     {
         transition_duration = fast ? 500 : 1000;
         switch (style)
@@ -36,6 +33,7 @@ public class GtkGameView : Gtk.Stack, GameView {
         add_named (new_board as Gtk.Widget, new_level);
         set_visible_child (new_board as Gtk.Widget);
         notify["transition-running"].connect(() => remove (old_board as Gtk.Widget));
+        return new_board;
     }
 
     public bool hide_cursor ()
@@ -51,12 +49,11 @@ public class GtkGameView : Gtk.Stack, GameView {
     {
         return false;
     }
+
     public void reset_game ()
     {
         current_level = 1;
-        new_board_view = create_board_view (current_level);
-        replace_board (board_view, new_board_view, GameView.ReplaceStyle.REFRESH);
-        board_view = new_board_view;
+        board_view = replace_board (board_view, create_board_view (current_level), 
GameView.ReplaceStyle.REFRESH) as BoardViewGtk;
         level_changed (current_level);
     }
 
@@ -90,10 +87,7 @@ public class GtkGameView : Gtk.Stack, GameView {
     // and transition between the two boards in a random direction.
     private bool game_won_cb ()
     {
-        current_level++;
-        new_board_view = create_board_view (current_level);
-        replace_board (board_view, new_board_view, GameView.ReplaceStyle.SLIDE_NEXT, false);
-        board_view = new_board_view;
+        board_view = replace_board (board_view, create_board_view (++current_level), 
GameView.ReplaceStyle.SLIDE_NEXT, false) as BoardViewGtk;
         level_changed (current_level);
         return false;
     }
diff --git a/src/game-view.vala b/src/game-view.vala
index 3dfb0c9..f8909df 100644
--- a/src/game-view.vala
+++ b/src/game-view.vala
@@ -18,7 +18,7 @@ public interface GameView : GLib.Object {
 
     public abstract void swap_board (int direction);
 
-    public abstract void replace_board (BoardView board_biew, BoardView new_board_view, ReplaceStyle style, 
bool fast = true);
+    public abstract BoardView replace_board (BoardView board_biew, BoardView new_board_view, ReplaceStyle 
style, bool fast = true);
 
     public abstract bool hide_cursor ();
     public abstract bool activate_cursor ();


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