From 12cb90a69c7be0ae513e52cd8b5188f63df8e40d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Harrault?= <benoit@harrault.fr> Date: Thu, 29 Aug 2024 11:54:01 +0200 Subject: [PATCH] Add animations. --- android/gradle.properties | 4 ++-- .../metadata/android/en-US/changelogs/4.txt | 1 + .../metadata/android/fr-FR/changelogs/4.txt | 1 + lib/cubit/game_cubit.dart | 20 ++++++++++++++----- lib/models/game/game.dart | 4 ++++ lib/ui/widgets/game/game_board.dart | 2 ++ lib/ui/widgets/game/game_player.dart | 12 ++++++++++- pubspec.yaml | 2 +- 8 files changed, 37 insertions(+), 9 deletions(-) create mode 100644 fastlane/metadata/android/en-US/changelogs/4.txt create mode 100644 fastlane/metadata/android/fr-FR/changelogs/4.txt diff --git a/android/gradle.properties b/android/gradle.properties index db7a1ee..14eed39 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.3 -app.versionCode=3 +app.versionName=0.0.4 +app.versionCode=4 diff --git a/fastlane/metadata/android/en-US/changelogs/4.txt b/fastlane/metadata/android/en-US/changelogs/4.txt new file mode 100644 index 0000000..f2bbe1d --- /dev/null +++ b/fastlane/metadata/android/en-US/changelogs/4.txt @@ -0,0 +1 @@ +Add animations. diff --git a/fastlane/metadata/android/fr-FR/changelogs/4.txt b/fastlane/metadata/android/fr-FR/changelogs/4.txt new file mode 100644 index 0000000..53426e4 --- /dev/null +++ b/fastlane/metadata/android/fr-FR/changelogs/4.txt @@ -0,0 +1 @@ +Ajout d'animations. diff --git a/lib/cubit/game_cubit.dart b/lib/cubit/game_cubit.dart index ecc7b78..658258b 100644 --- a/lib/cubit/game_cubit.dart +++ b/lib/cubit/game_cubit.dart @@ -1,3 +1,5 @@ +import 'dart:async'; + import 'package:equatable/equatable.dart'; import 'package:flutter/material.dart'; import 'package:hydrated_bloc/hydrated_bloc.dart'; @@ -36,6 +38,7 @@ class GameCubit extends HydratedCubit<GameState> { // Game data currentPlayer: state.currentGame.currentPlayer, scores: state.currentGame.scores, + currentHand: state.currentGame.currentHand, ); // game.dump(); @@ -79,7 +82,7 @@ class GameCubit extends HydratedCubit<GameState> { refresh(); } - void tapOnCell(int cellIndex) { + void tapOnCell(int cellIndex) async { printlog('tapOnCell: $cellIndex'); if (!state.currentGame.isCurrentPlayerHouse(cellIndex)) { @@ -103,7 +106,7 @@ class GameCubit extends HydratedCubit<GameState> { state.currentGame.animationInProgress = true; refresh(); - final int lastCellIndex = animateSeedsDistribution(cellIndex); + final int lastCellIndex = await animateSeedsDistribution(cellIndex); animateSeedsEarning(lastCellIndex); toggleCurrentPlayer(); @@ -118,21 +121,26 @@ class GameCubit extends HydratedCubit<GameState> { refresh(); } - int animateSeedsDistribution(int sourceCellIndex) { + Future<int> animateSeedsDistribution(int sourceCellIndex) async { printlog('animateSeedsDistribution / sourceCellIndex: $sourceCellIndex'); final int seedsCount = state.currentGame.board.cells[sourceCellIndex]; // empty source cell - state.currentGame.board.cells[sourceCellIndex] = 0; printlog('animateSeedsDistribution / empty source cell'); + state.currentGame.board.cells[sourceCellIndex] = 0; + state.currentGame.currentHand = seedsCount; refresh(); + await Future.delayed(const Duration(milliseconds: 500)); + int cellIndex = sourceCellIndex; for (int i = 0; i < seedsCount; i++) { cellIndex = state.currentGame.getNextCellIndex(cellIndex, sourceCellIndex); + state.currentGame.currentHand--; state.currentGame.board.cells[cellIndex] += 1; refresh(); + await Future.delayed(const Duration(milliseconds: 500)); } refresh(); @@ -140,7 +148,7 @@ class GameCubit extends HydratedCubit<GameState> { return cellIndex; } - void animateSeedsEarning(int lastCellIndex) { + void animateSeedsEarning(int lastCellIndex) async { printlog('animateSeedsEarning / lastCellIndex: $lastCellIndex'); if (state.currentGame.isOpponentHouse(lastCellIndex)) { @@ -154,6 +162,8 @@ class GameCubit extends HydratedCubit<GameState> { state.currentGame.scores[state.currentGame.currentPlayer] += seedsCount; refresh(); + await Future.delayed(const Duration(milliseconds: 500)); + // (recursively) check previous cells printlog('-> dispatch to previous cell'); animateSeedsEarning(state.currentGame.getPreviousCellIndex(lastCellIndex)); diff --git a/lib/models/game/game.dart b/lib/models/game/game.dart index 74288db..e82535e 100644 --- a/lib/models/game/game.dart +++ b/lib/models/game/game.dart @@ -21,6 +21,7 @@ class Game { // Game data required this.currentPlayer, required this.scores, + required this.currentHand, }); // Settings @@ -39,6 +40,7 @@ class Game { // Game data int currentPlayer; List<int> scores; + int currentHand; factory Game.createNull() { return Game( @@ -50,6 +52,7 @@ class Game { // Game data currentPlayer: 0, scores: [0, 0], + currentHand: 0, ); } @@ -78,6 +81,7 @@ class Game { // Game data currentPlayer: 0, scores: [0, 0], + currentHand: 0, ); } diff --git a/lib/ui/widgets/game/game_board.dart b/lib/ui/widgets/game/game_board.dart index d8273bf..3fb64ab 100644 --- a/lib/ui/widgets/game/game_board.dart +++ b/lib/ui/widgets/game/game_board.dart @@ -40,6 +40,7 @@ class GameBoardWidget extends StatelessWidget { children: [ GamePlayerWidget( active: !currentGame.isFinished && currentGame.currentPlayer == 0, + seeds: currentGame.currentPlayer == 0 ? currentGame.currentHand : 0, ), Container( margin: const EdgeInsets.all(2), @@ -96,6 +97,7 @@ class GameBoardWidget extends StatelessWidget { ), GamePlayerWidget( active: !currentGame.isFinished && currentGame.currentPlayer == 1, + seeds: currentGame.currentPlayer == 1 ? currentGame.currentHand : 0, ), ], ); diff --git a/lib/ui/widgets/game/game_player.dart b/lib/ui/widgets/game/game_player.dart index fa1f9dc..5d2a945 100644 --- a/lib/ui/widgets/game/game_player.dart +++ b/lib/ui/widgets/game/game_player.dart @@ -4,9 +4,11 @@ class GamePlayerWidget extends StatelessWidget { const GamePlayerWidget({ super.key, required this.active, + required this.seeds, }); final bool active; + final int seeds; @override Widget build(BuildContext context) { @@ -25,7 +27,15 @@ class GamePlayerWidget extends StatelessWidget { ), width: 100, height: 100, - child: const SizedBox.shrink(), + child: Text( + seeds == 0 ? '' : seeds.toString(), + textAlign: TextAlign.center, + style: TextStyle( + fontSize: 40, + fontWeight: FontWeight.bold, + color: Theme.of(context).colorScheme.primary, + ), + ), ); } } diff --git a/pubspec.yaml b/pubspec.yaml index bf03338..c1462bd 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -3,7 +3,7 @@ description: Awale game publish_to: "none" -version: 0.0.3+3 +version: 0.0.4+4 environment: sdk: "^3.0.0" -- GitLab