[gnome-klotski] Rename a method.



commit 09ba4cd6bb8d91cca0d96ff7ec27f6907a2bb3f2
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Sun Feb 9 05:05:24 2020 +0100

    Rename a method.

 src/puzzle-view.vala | 10 +++++-----
 src/puzzle.vala      |  7 ++++---
 2 files changed, 9 insertions(+), 8 deletions(-)
---
diff --git a/src/puzzle-view.vala b/src/puzzle-view.vala
index e1ef9df..706f29b 100644
--- a/src/puzzle-view.vala
+++ b/src/puzzle-view.vala
@@ -239,16 +239,16 @@ private class PuzzleView : Gtk.DrawingArea
             piece_y = (uint8) new_piece_y;
             char new_piece_id = puzzle.get_piece_id (puzzle.map, piece_x, piece_y);
 
-            if (piece_id != '\0' && piece_unmoved)
+            bool already_moving = piece_id != '\0';
+            if (already_moving && piece_unmoved)
             {
                 piece_id = '\0';
                 return false;
             }
-            if (new_piece_id == ' ' || new_piece_id == '.' || new_piece_id == '-'
-                || new_piece_id == '#' || new_piece_id == piece_id)
+            if (Puzzle.is_static_tile (new_piece_id) || new_piece_id == piece_id)
                 return false;
 
-            if (piece_id != '\0')
+            if (already_moving) // TODO skip the new piece selection if it cannot be moved
                 validate_move ();
 
             piece_unmoved = true;
@@ -271,7 +271,7 @@ private class PuzzleView : Gtk.DrawingArea
         if (piece_unmoved)
             return;
 
-        if (puzzle.movable (piece_id) && puzzle.mapcmp (puzzle.move_map, puzzle.map))
+        if (!Puzzle.is_static_tile (piece_id) && puzzle.mapcmp (puzzle.move_map, puzzle.map))
         {
             if (last_piece_id == '\0' || last_piece_id != piece_id)
             {
diff --git a/src/puzzle.vala b/src/puzzle.vala
index 8ad560d..45e4f18 100644
--- a/src/puzzle.vala
+++ b/src/puzzle.vala
@@ -235,18 +235,19 @@ private class Puzzle : Object
         return false;
     }
 
-    internal bool movable (int id)
+    internal static inline bool is_static_tile (int id)
     {
         if (id == '#' || id == '.' || id == ' ' || id == '-')
+            return true;
+        else
             return false;
-        return true;
     }
 
     internal bool move_piece (char id, uint8 x1, uint8 y1, uint8 x2, uint8 y2)
     {
         var return_value = false;
 
-        if (!movable (id))
+        if (is_static_tile (id))
             return false;
 
         if (get_piece_id (map, x2, y2) == id)


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