[swell-foop/arnaudb/cursor-fixes: 2/2] Fix keyboard cursor move.



commit 9eb9278cb6992ee2c647cfc04e33bc8ff20b68f5
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Wed May 13 21:55:32 2020 +0200

    Fix keyboard cursor move.
    
    On empty tiles on loaded game.

 src/game-view.vala | 4 +++-
 src/game.vala      | 9 +++------
 2 files changed, 6 insertions(+), 7 deletions(-)
---
diff --git a/src/game-view.vala b/src/game-view.vala
index 0f47413..3aa3eb5 100644
--- a/src/game-view.vala
+++ b/src/game-view.vala
@@ -265,7 +265,9 @@ private class GameView : Clutter.Group
     private TileActor? find_tile_at_position (int position_x, int position_y)
     {
         foreach (TileActor actor in tiles)
-            if (actor.tile.grid_x == position_x &&
+            if (actor != null
+             && actor.tile != null
+             && actor.tile.grid_x == position_x &&
                 actor.tile.grid_y == position_y)
                 return actor;
         return null;
diff --git a/src/game.vala b/src/game.vala
index 50a8be7..1c0f842 100644
--- a/src/game.vala
+++ b/src/game.vala
@@ -68,7 +68,7 @@ private class Tile : Object
  */
 private class Game : Object
 {
-    private Tile[,] tiles;
+    private Tile? [,] tiles;
     private bool is_started = false;
 
     /* Game score */
@@ -125,7 +125,7 @@ private class Game : Object
     {
         var cl = new List<Tile> ();
 
-        if (li.visited || li.closed)
+        if (li == null || li.visited || li.closed)
             return cl;
 
         var x = li.grid_x;
@@ -344,10 +344,7 @@ private class Game : Object
                 Variant tmp_variant_3 = tmp_variant_2.get_child_value (j);
                 uint8 color = tmp_variant_3.get_byte ();
                 if (color == 0)
-                {
-                    tiles [rows - i - 1, j] = new Tile (j, (int) (rows - i - 1), 0);
-                    tiles [rows - i - 1, j].closed = true;
-                }
+                    tiles [rows - i - 1, j] = null;
                 else
                     tiles [rows - i - 1, j] = new Tile (j, (int) (rows - i - 1), color - 1);
             }


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