From 800c319e6cce4da2086af2cb69d81d946ee5fe4c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Beno=C3=AEt=20Harrault?= <benoit@harrault.fr>
Date: Fri, 30 Aug 2024 12:59:52 +0200
Subject: [PATCH] Fix collect seeds on previous cells

---
 android/gradle.properties                        |  4 ++--
 fastlane/metadata/android/en-US/changelogs/6.txt |  1 +
 fastlane/metadata/android/fr-FR/changelogs/6.txt |  1 +
 lib/cubit/game_cubit.dart                        | 12 +++++++++---
 pubspec.yaml                                     |  2 +-
 5 files changed, 14 insertions(+), 6 deletions(-)
 create mode 100644 fastlane/metadata/android/en-US/changelogs/6.txt
 create mode 100644 fastlane/metadata/android/fr-FR/changelogs/6.txt

diff --git a/android/gradle.properties b/android/gradle.properties
index aa51064..135006f 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.5
-app.versionCode=5
+app.versionName=0.0.6
+app.versionCode=6
diff --git a/fastlane/metadata/android/en-US/changelogs/6.txt b/fastlane/metadata/android/en-US/changelogs/6.txt
new file mode 100644
index 0000000..26452b2
--- /dev/null
+++ b/fastlane/metadata/android/en-US/changelogs/6.txt
@@ -0,0 +1 @@
+Fix grab seeds.
diff --git a/fastlane/metadata/android/fr-FR/changelogs/6.txt b/fastlane/metadata/android/fr-FR/changelogs/6.txt
new file mode 100644
index 0000000..087e6fa
--- /dev/null
+++ b/fastlane/metadata/android/fr-FR/changelogs/6.txt
@@ -0,0 +1 @@
+Correction sur ramassage des graines.
diff --git a/lib/cubit/game_cubit.dart b/lib/cubit/game_cubit.dart
index c41a09b..0cc2123 100644
--- a/lib/cubit/game_cubit.dart
+++ b/lib/cubit/game_cubit.dart
@@ -107,7 +107,7 @@ class GameCubit extends HydratedCubit<GameState> {
     refresh();
 
     final int lastCellIndex = await animateSeedsDistribution(cellIndex);
-    animateSeedsEarning(lastCellIndex);
+    await animateSeedsEarning(lastCellIndex);
 
     toggleCurrentPlayer();
 
@@ -148,9 +148,11 @@ class GameCubit extends HydratedCubit<GameState> {
     return cellIndex;
   }
 
-  void animateSeedsEarning(int lastCellIndex) async {
+  Future<int> animateSeedsEarning(int lastCellIndex) async {
     printlog('animateSeedsEarning / lastCellIndex: $lastCellIndex');
 
+    int earnedSeedsCount = 0;
+
     if (state.currentGame.isOpponentHouse(lastCellIndex)) {
       final int seedsCount = state.currentGame.board.cells[lastCellIndex];
       printlog('found $seedsCount seed(s) on final house');
@@ -160,17 +162,21 @@ class GameCubit extends HydratedCubit<GameState> {
 
         state.currentGame.board.cells[lastCellIndex] = 0;
         state.currentGame.scores[state.currentGame.currentPlayer] += seedsCount;
+        earnedSeedsCount += seedsCount;
         refresh();
 
         await Future.delayed(const Duration(milliseconds: 500));
 
         // (recursively) check previous cells
         printlog('-> dispatch to previous cell');
-        animateSeedsEarning(state.currentGame.getPreviousCellIndex(lastCellIndex));
+        final int previousCellIndex = state.currentGame.getPreviousCellIndex(lastCellIndex);
+        earnedSeedsCount += await animateSeedsEarning(previousCellIndex);
       } else {
         printlog('-> nothing to do');
       }
     }
+
+    return earnedSeedsCount;
   }
 
   @override
diff --git a/pubspec.yaml b/pubspec.yaml
index 67da327..8d28b01 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -3,7 +3,7 @@ description: Awale game
 
 publish_to: "none"
 
-version: 0.0.5+5
+version: 0.0.6+6
 
 environment:
   sdk: "^3.0.0"
-- 
GitLab