diff --git a/lib/domain/game/game_engine.dart b/lib/domain/game/game_engine.dart index 3f16add..dd82b02 100644 --- a/lib/domain/game/game_engine.dart +++ b/lib/domain/game/game_engine.dart @@ -37,9 +37,15 @@ class GameEngine { } final normalizedGuess = _normalize(guess.trim().toLowerCase()); - final normalizedActual = _normalize(pokemon.name.toLowerCase()); - if (normalizedGuess == normalizedActual) { + // Accept the name in either language so a language switch mid-game never blocks the player. + final acceptedNames = { + pokemon.name, + if (pokemon.nameFr != null) pokemon.nameFr!, + if (pokemon.nameEn != null) pokemon.nameEn!, + }.map((n) => _normalize(n.toLowerCase())).toSet(); + + if (acceptedNames.contains(normalizedGuess)) { final newSession = s.sessionCorrectCount + 1; final gained = s.isShiny ? AppConstants.pointsShiny : AppConstants.pointsNormal; final newScore = s.currentScore + gained; diff --git a/lib/presentation/providers/game_provider.dart b/lib/presentation/providers/game_provider.dart index 408d13e..f7e4dda 100644 --- a/lib/presentation/providers/game_provider.dart +++ b/lib/presentation/providers/game_provider.dart @@ -7,6 +7,7 @@ import '../../domain/game/game_engine.dart'; import '../../domain/game/game_state.dart'; import '../../core/logger.dart'; import 'gen_filter_provider.dart'; +import 'locale_provider.dart'; import 'pokedex_provider.dart'; import 'repository_provider.dart'; @@ -17,7 +18,28 @@ class GameNotifier extends Notifier { final _random = Random(); @override - GameState build() => const GameState(); + GameState build() { + // Re-fetch the current Pokémon whenever the locale changes so the name + // (used for hints and the guess comparison) switches language instantly. + ref.listen(localeProvider, (_, __) => _reloadCurrentPokemon()); + return const GameState(); + } + + Future _reloadCurrentPokemon() async { + final current = state.currentPokemon; + if (current == null || state.status == GameStatus.loading) return; + try { + final updated = await ref.read(pokemonRepositoryProvider).getById(current.id); + if (updated != null) { + state = state.copyWith( + currentPokemon: updated.copyWith( + isCaught: current.isCaught, + isSeen: current.isSeen, + ), + ); + } + } catch (_) {} + } Future startNewGame() async { state = _engine.newGame(state);