From 93a028e2318ba11bc8b803c1c11b7dedf5f788b3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Beno=C3=AEt=20Harrault?= <benoit@harrault.fr>
Date: Wed, 3 Jan 2024 20:33:22 +0100
Subject: [PATCH] Display current members/colors associations

---
 android/gradle.properties                     |  4 +-
 .../metadata/android/en-US/changelogs/16.txt  |  1 +
 .../metadata/android/fr-FR/changelogs/16.txt  |  1 +
 lib/cubit/game_cubit.dart                     | 13 +++
 lib/cubit/game_state.dart                     |  4 +
 lib/models/move.dart                          |  7 ++
 lib/ui/widgets/game.dart                      | 94 +++++++++++++++++--
 pubspec.yaml                                  |  2 +-
 8 files changed, 113 insertions(+), 13 deletions(-)
 create mode 100644 fastlane/metadata/android/en-US/changelogs/16.txt
 create mode 100644 fastlane/metadata/android/fr-FR/changelogs/16.txt

diff --git a/android/gradle.properties b/android/gradle.properties
index 957c40b..777ac2d 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.15
-app.versionCode=15
+app.versionName=0.0.16
+app.versionCode=16
diff --git a/fastlane/metadata/android/en-US/changelogs/16.txt b/fastlane/metadata/android/en-US/changelogs/16.txt
new file mode 100644
index 0000000..e6781f4
--- /dev/null
+++ b/fastlane/metadata/android/en-US/changelogs/16.txt
@@ -0,0 +1 @@
+Display current positions.
diff --git a/fastlane/metadata/android/fr-FR/changelogs/16.txt b/fastlane/metadata/android/fr-FR/changelogs/16.txt
new file mode 100644
index 0000000..76111aa
--- /dev/null
+++ b/fastlane/metadata/android/fr-FR/changelogs/16.txt
@@ -0,0 +1 @@
+Affiche les positions en cours.
diff --git a/lib/cubit/game_cubit.dart b/lib/cubit/game_cubit.dart
index ddc7353..cb60df2 100644
--- a/lib/cubit/game_cubit.dart
+++ b/lib/cubit/game_cubit.dart
@@ -16,8 +16,21 @@ class GameCubit extends HydratedCubit<GameState> {
   void setValues({
     Move? move,
   }) {
+    List<Move> history = state.history ?? [];
+    if (move != null) {
+      history.add(move);
+    }
+
     emit(GameState(
       move: move ?? state.move,
+      history: history,
+    ));
+  }
+
+  void deleteHistory() {
+    emit(GameState(
+      move: state.move,
+      history: [],
     ));
   }
 
diff --git a/lib/cubit/game_state.dart b/lib/cubit/game_state.dart
index f859fd5..204801e 100644
--- a/lib/cubit/game_state.dart
+++ b/lib/cubit/game_state.dart
@@ -4,16 +4,20 @@ part of 'game_cubit.dart';
 class GameState extends Equatable {
   const GameState({
     this.move,
+    this.history,
   });
 
   final Move? move;
+  final List<Move>? history;
 
   @override
   List<dynamic> get props => <dynamic>[
         move,
+        history,
       ];
 
   Map<String, dynamic> get values => <String, dynamic>{
         'move': move,
+        'history': history,
       };
 }
diff --git a/lib/models/move.dart b/lib/models/move.dart
index 24b4fcb..7987bbe 100644
--- a/lib/models/move.dart
+++ b/lib/models/move.dart
@@ -18,6 +18,13 @@ class Move {
     );
   }
 
+  factory Move.createFrom({TwisterMember? member, TwisterColor? color}) {
+    return Move(
+      color: color,
+      member: member,
+    );
+  }
+
   factory Move.pickRandom() {
     return Move(
       color: TwisterColor.pickRandom(),
diff --git a/lib/ui/widgets/game.dart b/lib/ui/widgets/game.dart
index 5019d58..b6ac6a9 100644
--- a/lib/ui/widgets/game.dart
+++ b/lib/ui/widgets/game.dart
@@ -7,6 +7,8 @@ import 'package:flutter_bloc/flutter_bloc.dart';
 
 import 'package:twister/cubit/game_cubit.dart';
 import 'package:twister/models/move.dart';
+import 'package:twister/models/twister_color.dart';
+import 'package:twister/models/twister_member.dart';
 import 'package:twister/ui/widgets/show_move.dart';
 
 class Game extends StatefulWidget {
@@ -64,20 +66,92 @@ class _GameState extends State<Game> {
     player.play(AssetSource(newMove.toSoundAsset()));
   }
 
+  Widget buildCurrentStateWidget(List<Move>? history) {
+    Map<String, TwisterColor?> currentState = {};
+
+    history?.forEach((move) {
+      currentState[move.member.toString()] = move.color;
+    });
+
+    TwisterMember leftHand = TwisterMember(value: TwisterAllowedMembers.leftHand);
+    TwisterMember rightHand = TwisterMember(value: TwisterAllowedMembers.rightHand);
+    TwisterMember leftFoot = TwisterMember(value: TwisterAllowedMembers.leftFoot);
+    TwisterMember rightFoot = TwisterMember(value: TwisterAllowedMembers.rightFoot);
+
+    Move leftHandMove = Move.createFrom(
+      member: leftHand,
+      color: currentState[leftHand.toString()],
+    );
+    Move rightHandMove = Move.createFrom(
+      member: rightHand,
+      color: currentState[rightHand.toString()],
+    );
+    Move leftFootMove = Move.createFrom(
+      member: leftFoot,
+      color: currentState[leftFoot.toString()],
+    );
+    Move rightFootMove = Move.createFrom(
+      member: rightFoot,
+      color: currentState[rightFoot.toString()],
+    );
+
+    return Padding(
+      padding: EdgeInsets.all(30),
+      child: Table(
+        children: [
+          TableRow(
+            children: [
+              Padding(
+                padding: EdgeInsets.all(10),
+                child: ShowMove(move: leftHandMove),
+              ),
+              Padding(
+                padding: EdgeInsets.all(10),
+                child: ShowMove(move: rightHandMove),
+              ),
+            ],
+          ),
+          TableRow(
+            children: [
+              Padding(
+                padding: EdgeInsets.all(10),
+                child: ShowMove(move: leftFootMove),
+              ),
+              Padding(
+                padding: EdgeInsets.all(10),
+                child: ShowMove(move: rightFootMove),
+              ),
+            ],
+          )
+        ],
+      ),
+    );
+  }
+
   @override
   Widget build(BuildContext context) {
     return BlocBuilder<GameCubit, GameState>(
       builder: (BuildContext context, GameState gameState) {
-        return GestureDetector(
-          child: shuffling
-              ? Transform.rotate(
-                  angle: 2 * pi * Random().nextDouble(),
-                  child: ShowMove(move: shuffledMove ?? Move.createNull()),
-                )
-              : ShowMove(move: gameState.move ?? Move.createNull()),
-          onTap: () {
-            animate();
-          },
+        return Column(
+          children: [
+            GestureDetector(
+              child: shuffling
+                  ? Transform.rotate(
+                      angle: 2 * pi * Random().nextDouble(),
+                      child: ShowMove(move: shuffledMove ?? Move.createNull()),
+                    )
+                  : ShowMove(move: gameState.move ?? Move.createNull()),
+              onTap: () {
+                animate();
+              },
+            ),
+            GestureDetector(
+              child: buildCurrentStateWidget(gameState.history),
+              onTap: () {
+                BlocProvider.of<GameCubit>(context).deleteHistory();
+              },
+            ),
+          ],
         );
       },
     );
diff --git a/pubspec.yaml b/pubspec.yaml
index a262749..b40b5b8 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -3,7 +3,7 @@ description: twister game companion
 
 publish_to: 'none'
 
-version: 0.0.15+15
+version: 0.0.16+16
 
 environment:
   sdk: '^3.0.0'
-- 
GitLab