From 5545c7f4a08f72064a027c5435c06116631d9259 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Beno=C3=AEt=20Harrault?= <benoit@harrault.fr>
Date: Wed, 3 Jan 2024 19:06:34 +0100
Subject: [PATCH] Animate while picking next move

---
 android/gradle.properties                     |  4 +-
 .../metadata/android/en-US/changelogs/15.txt  |  1 +
 .../metadata/android/fr-FR/changelogs/15.txt  |  1 +
 lib/ui/widgets/game.dart                      | 63 ++++++++++++++++---
 pubspec.yaml                                  |  2 +-
 5 files changed, 60 insertions(+), 11 deletions(-)
 create mode 100644 fastlane/metadata/android/en-US/changelogs/15.txt
 create mode 100644 fastlane/metadata/android/fr-FR/changelogs/15.txt

diff --git a/android/gradle.properties b/android/gradle.properties
index 81949df..957c40b 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.14
-app.versionCode=14
+app.versionName=0.0.15
+app.versionCode=15
diff --git a/fastlane/metadata/android/en-US/changelogs/15.txt b/fastlane/metadata/android/en-US/changelogs/15.txt
new file mode 100644
index 0000000..3271f20
--- /dev/null
+++ b/fastlane/metadata/android/en-US/changelogs/15.txt
@@ -0,0 +1 @@
+Animate while picking next move.
diff --git a/fastlane/metadata/android/fr-FR/changelogs/15.txt b/fastlane/metadata/android/fr-FR/changelogs/15.txt
new file mode 100644
index 0000000..58cb13f
--- /dev/null
+++ b/fastlane/metadata/android/fr-FR/changelogs/15.txt
@@ -0,0 +1 @@
+Animation pendant la sélection du prochain mouvement.
diff --git a/lib/ui/widgets/game.dart b/lib/ui/widgets/game.dart
index 51d9077..5019d58 100644
--- a/lib/ui/widgets/game.dart
+++ b/lib/ui/widgets/game.dart
@@ -1,3 +1,6 @@
+import 'dart:async';
+import 'dart:math';
+
 import 'package:audioplayers/audioplayers.dart';
 import 'package:flutter/material.dart';
 import 'package:flutter_bloc/flutter_bloc.dart';
@@ -15,21 +18,65 @@ class Game extends StatefulWidget {
 
 class _GameState extends State<Game> {
   final player = AudioPlayer();
+  bool shuffling = false;
+  Move? shuffledMove;
+
+  void animate() {
+    const interval = const Duration(milliseconds: 200);
+    int iterationsLeft = 10;
+
+    shuffling = true;
+    shuffledMove = null;
+
+    setState(() {});
+    Timer.periodic(
+      interval,
+      (Timer timer) {
+        if (iterationsLeft > 1) {
+          shuffledMove = Move.pickRandom();
+        }
+
+        if (iterationsLeft == 1) {
+          shuffledMove = null;
+        }
+
+        if (iterationsLeft == 0) {
+          shuffledMove = null;
+          pickNewMove();
+
+          timer.cancel();
+          shuffling = false;
+        }
+
+        setState(() {});
+        iterationsLeft--;
+      },
+    );
+  }
+
+  void pickNewMove() {
+    Move newMove = Move.pickRandom();
+
+    BlocProvider.of<GameCubit>(context).setValues(
+      move: newMove,
+    );
+
+    player.play(AssetSource(newMove.toSoundAsset()));
+  }
 
   @override
   Widget build(BuildContext context) {
     return BlocBuilder<GameCubit, GameState>(
       builder: (BuildContext context, GameState gameState) {
         return GestureDetector(
-          child: ShowMove(move: gameState.move ?? Move.createNull()),
+          child: shuffling
+              ? Transform.rotate(
+                  angle: 2 * pi * Random().nextDouble(),
+                  child: ShowMove(move: shuffledMove ?? Move.createNull()),
+                )
+              : ShowMove(move: gameState.move ?? Move.createNull()),
           onTap: () {
-            Move newMove = Move.pickRandom();
-
-            BlocProvider.of<GameCubit>(context).setValues(
-              move: newMove,
-            );
-
-            player.play(AssetSource(newMove.toSoundAsset()));
+            animate();
           },
         );
       },
diff --git a/pubspec.yaml b/pubspec.yaml
index f751a47..a262749 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -3,7 +3,7 @@ description: twister game companion
 
 publish_to: 'none'
 
-version: 0.0.14+14
+version: 0.0.15+15
 
 environment:
   sdk: '^3.0.0'
-- 
GitLab