From 1f1de4421c7af656b887b4b5ebe170e86e6eecc6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Beno=C3=AEt=20Harrault?= <benoit@harrault.fr>
Date: Sun, 4 Feb 2024 22:53:16 +0100
Subject: [PATCH] Fix delete cells on top line

---
 android/gradle.properties                         |  4 ++--
 fastlane/metadata/android/en-US/changelogs/17.txt |  1 +
 fastlane/metadata/android/fr-FR/changelogs/17.txt |  1 +
 lib/config/default_game_settings.dart             |  2 ++
 lib/cubit/game_cubit.dart                         |  3 ++-
 lib/ui/widgets/game_board.dart                    | 12 +++++++++---
 pubspec.yaml                                      |  2 +-
 7 files changed, 18 insertions(+), 7 deletions(-)
 create mode 100644 fastlane/metadata/android/en-US/changelogs/17.txt
 create mode 100644 fastlane/metadata/android/fr-FR/changelogs/17.txt

diff --git a/android/gradle.properties b/android/gradle.properties
index 777ac2d..cd2d833 100644
--- a/android/gradle.properties
+++ b/android/gradle.properties
@@ -1,5 +1,5 @@
 org.gradle.jvmargs=-Xmx1536M
 android.useAndroidX=true
 android.enableJetifier=true
-app.versionName=0.0.16
-app.versionCode=16
+app.versionName=0.0.17
+app.versionCode=17
diff --git a/fastlane/metadata/android/en-US/changelogs/17.txt b/fastlane/metadata/android/en-US/changelogs/17.txt
new file mode 100644
index 0000000..8248fb3
--- /dev/null
+++ b/fastlane/metadata/android/en-US/changelogs/17.txt
@@ -0,0 +1 @@
+Fix delete cells on top line.
diff --git a/fastlane/metadata/android/fr-FR/changelogs/17.txt b/fastlane/metadata/android/fr-FR/changelogs/17.txt
new file mode 100644
index 0000000..52fa08d
--- /dev/null
+++ b/fastlane/metadata/android/fr-FR/changelogs/17.txt
@@ -0,0 +1 @@
+Correction sur la suppression de cellules sur la première ligne.
diff --git a/lib/config/default_game_settings.dart b/lib/config/default_game_settings.dart
index a8f11fa..7c9e2c8 100644
--- a/lib/config/default_game_settings.dart
+++ b/lib/config/default_game_settings.dart
@@ -30,4 +30,6 @@ class DefaultGameSettings {
 
     return [];
   }
+
+  static int blockMinimumCellsCount = 3;
 }
diff --git a/lib/cubit/game_cubit.dart b/lib/cubit/game_cubit.dart
index 1eb5517..cc446d6 100644
--- a/lib/cubit/game_cubit.dart
+++ b/lib/cubit/game_cubit.dart
@@ -1,6 +1,7 @@
 import 'package:equatable/equatable.dart';
 import 'package:flutter/material.dart';
 import 'package:hydrated_bloc/hydrated_bloc.dart';
+import 'package:jeweled/config/default_game_settings.dart';
 
 import 'package:jeweled/models/game.dart';
 import 'package:jeweled/models/cell_location.dart';
@@ -109,7 +110,7 @@ class GameCubit extends HydratedCubit<GameState> {
 
     if (cellValue != null) {
       List<CellLocation> blockCells = currentGame.getSiblingCells(tappedCellLocation, []);
-      if (blockCells.length >= 3) {
+      if (blockCells.length >= DefaultGameSettings.blockMinimumCellsCount) {
         this.deleteBlock(blockCells);
         this.increaseMovesCount();
         this.increaseScore(getScoreFromBlock(blockCells.length));
diff --git a/lib/ui/widgets/game_board.dart b/lib/ui/widgets/game_board.dart
index c2ca025..e17b1b1 100644
--- a/lib/ui/widgets/game_board.dart
+++ b/lib/ui/widgets/game_board.dart
@@ -79,14 +79,20 @@ class _GameBoard extends State<GameBoard> with TickerProviderStateMixin {
     });
 
     // Build animation for each cell to move
+    bool needAnimation = false;
     cellsToRemove.forEach((cellToRemove) {
       for (int i = 0; i < cellToRemove.row; i++) {
         final int stepsCount = stepsDownCounts[(cellToRemove.row - i) - 1][cellToRemove.col];
         this.animations[(cellToRemove.row - i) - 1][cellToRemove.col] = animation(stepsCount);
+        needAnimation = true;
       }
     });
 
     controller.forward().orCancel;
+
+    if (!needAnimation) {
+      gameCubit.postAnimate();
+    }
   }
 
   @override
@@ -104,16 +110,16 @@ class _GameBoard extends State<GameBoard> with TickerProviderStateMixin {
 
           return GestureDetector(
             onTapUp: (details) {
-              bool canRemoveCell = true;
+              bool animationInProgress = false;
               animations.forEach((row) {
                 row.forEach((cell) {
                   if (cell != null) {
-                    canRemoveCell = false;
+                    animationInProgress = true;
                   }
                 });
               });
 
-              if (canRemoveCell) {
+              if (!animationInProgress) {
                 final double xTap = details.localPosition.dx;
                 final double yTap = details.localPosition.dy;
                 final int col = xTap ~/ (displayWidth / currentGame.settings.boardSize);
diff --git a/pubspec.yaml b/pubspec.yaml
index a03d987..542bbc6 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -3,7 +3,7 @@ description: Jeweled Game
 
 publish_to: 'none'
 
-version: 0.0.16+16
+version: 0.0.17+17
 
 environment:
   sdk: '^3.0.0'
-- 
GitLab