Skip to content

Commit

Permalink
Listen key letters
Browse files Browse the repository at this point in the history
  • Loading branch information
Carapacik committed Nov 21, 2023
1 parent bac1e7b commit f503fd2
Show file tree
Hide file tree
Showing 19 changed files with 282 additions and 173 deletions.
9 changes: 5 additions & 4 deletions lib/src/core/localization/generated/intl/messages_all.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import 'messages_en.dart' as messages_en;
import 'messages_ru.dart' as messages_ru;

typedef Future<dynamic> LibraryLoader();

Map<String, LibraryLoader> _deferredLibraries = {
'en': () => new SynchronousFuture(null),
'ru': () => new SynchronousFuture(null),
Expand All @@ -39,8 +38,9 @@ MessageLookupByLibrary? _findExact(String localeName) {

/// User programs should call this before using [localeName] for messages.
Future<bool> initializeMessages(String localeName) {
var availableLocale =
Intl.verifiedLocale(localeName, (locale) => _deferredLibraries[locale] != null, onFailure: (_) => null);
var availableLocale = Intl.verifiedLocale(
localeName, (locale) => _deferredLibraries[locale] != null,
onFailure: (_) => null);
if (availableLocale == null) {
return new SynchronousFuture(false);
}
Expand All @@ -60,7 +60,8 @@ bool _messagesExistFor(String locale) {
}

MessageLookupByLibrary? _findGeneratedMessagesFor(String locale) {
var actualLocale = Intl.verifiedLocale(locale, _messagesExistFor, onFailure: (_) => null);
var actualLocale =
Intl.verifiedLocale(locale, _messagesExistFor, onFailure: (_) => null);
if (actualLocale == null) return null;
return _findExact(actualLocale);
}
20 changes: 12 additions & 8 deletions lib/src/core/localization/generated/intl/messages_en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,30 @@ class MessageLookup extends MessageLookupByLibrary {
static String m0(number) => "Level ${number}";

final messages = _notInlinedMessages(_notInlinedMessages);

static Map<String, Function> _notInlinedMessages(_) => <String, Function>{
"about": MessageLookupByLibrary.simpleMessage("About"),
"appDictionary": MessageLookupByLibrary.simpleMessage("App dictionary"),
"appLanguage": MessageLookupByLibrary.simpleMessage("App language"),
"appTitle": MessageLookupByLibrary.simpleMessage("Wordly Plus"),
"casual": MessageLookupByLibrary.simpleMessage("Default"),
"colorMode": MessageLookupByLibrary.simpleMessage("Color mode"),
"currentStreak": MessageLookupByLibrary.simpleMessage("Current\nStreak"),
"currentStreak":
MessageLookupByLibrary.simpleMessage("Current\nStreak"),
"daily": MessageLookupByLibrary.simpleMessage("Daily"),
"en": MessageLookupByLibrary.simpleMessage("English"),
"guessDistribution": MessageLookupByLibrary.simpleMessage("Guess distribution"),
"guessDistribution":
MessageLookupByLibrary.simpleMessage("Guess distribution"),
"highContrast": MessageLookupByLibrary.simpleMessage("High contrast"),
"levelNumber": m0,
"levels": MessageLookupByLibrary.simpleMessage("Levels"),
"loseMessage": MessageLookupByLibrary.simpleMessage("You lost"),
"maxStreak": MessageLookupByLibrary.simpleMessage("Max\nStreak"),
"message_new_word":
MessageLookupByLibrary.simpleMessage("subject=Wordle%20-%20New%20word&body=Word%20-%0AMeaning%20-"),
"message_new_word": MessageLookupByLibrary.simpleMessage(
"subject=Wordle%20-%20New%20word&body=Word%20-%0AMeaning%20-"),
"nextLevel": MessageLookupByLibrary.simpleMessage("Next level"),
"nextWord": MessageLookupByLibrary.simpleMessage("Next wordle in"),
"notPlayed": MessageLookupByLibrary.simpleMessage("You haven\'t played a single game"),
"notPlayed": MessageLookupByLibrary.simpleMessage(
"You haven\'t played a single game"),
"other": MessageLookupByLibrary.simpleMessage("Other"),
"played": MessageLookupByLibrary.simpleMessage("Played"),
"ru": MessageLookupByLibrary.simpleMessage("Russian"),
Expand All @@ -62,7 +64,9 @@ class MessageLookup extends MessageLookupByLibrary {
"viewStatistic": MessageLookupByLibrary.simpleMessage("View statistic"),
"winMessage": MessageLookupByLibrary.simpleMessage("You win!"),
"winRate": MessageLookupByLibrary.simpleMessage("Win\nrate"),
"wordNotFound": MessageLookupByLibrary.simpleMessage("Word not found in dictionary"),
"wordTooShort": MessageLookupByLibrary.simpleMessage("Word is not correct length")
"wordNotFound": MessageLookupByLibrary.simpleMessage(
"Word not found in dictionary"),
"wordTooShort":
MessageLookupByLibrary.simpleMessage("Word is not correct length")
};
}
26 changes: 16 additions & 10 deletions lib/src/core/localization/generated/intl/messages_ru.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class MessageLookup extends MessageLookupByLibrary {
static String m0(number) => "Уровень ${number}";

final messages = _notInlinedMessages(_notInlinedMessages);

static Map<String, Function> _notInlinedMessages(_) => <String, Function>{
"about": MessageLookupByLibrary.simpleMessage("О приложении"),
"appDictionary": MessageLookupByLibrary.simpleMessage("Язык словаря"),
Expand All @@ -34,17 +33,21 @@ class MessageLookup extends MessageLookupByLibrary {
"currentStreak": MessageLookupByLibrary.simpleMessage("Текущая\nСерия"),
"daily": MessageLookupByLibrary.simpleMessage("Ежедневный"),
"en": MessageLookupByLibrary.simpleMessage("Английский"),
"guessDistribution": MessageLookupByLibrary.simpleMessage("Распределение догадок"),
"highContrast": MessageLookupByLibrary.simpleMessage("Высокий контраст"),
"guessDistribution":
MessageLookupByLibrary.simpleMessage("Распределение догадок"),
"highContrast":
MessageLookupByLibrary.simpleMessage("Высокий контраст"),
"levelNumber": m0,
"levels": MessageLookupByLibrary.simpleMessage("Уровни"),
"loseMessage": MessageLookupByLibrary.simpleMessage("Вы проиграли"),
"maxStreak": MessageLookupByLibrary.simpleMessage("Макс.\nСерия"),
"message_new_word":
MessageLookupByLibrary.simpleMessage("subject=Словень%20-%20Новое%20слово&body=Слово%20-%0AЗначение%20-"),
"message_new_word": MessageLookupByLibrary.simpleMessage(
"subject=Словень%20-%20Новое%20слово&body=Слово%20-%0AЗначение%20-"),
"nextLevel": MessageLookupByLibrary.simpleMessage("Следующий уровень"),
"nextWord": MessageLookupByLibrary.simpleMessage("Следующее слово через"),
"notPlayed": MessageLookupByLibrary.simpleMessage("Вы не сыграли ни одной игры"),
"nextWord":
MessageLookupByLibrary.simpleMessage("Следующее слово через"),
"notPlayed":
MessageLookupByLibrary.simpleMessage("Вы не сыграли ни одной игры"),
"other": MessageLookupByLibrary.simpleMessage("Другой"),
"played": MessageLookupByLibrary.simpleMessage("Сыграно"),
"ru": MessageLookupByLibrary.simpleMessage("Русский"),
Expand All @@ -59,10 +62,13 @@ class MessageLookup extends MessageLookupByLibrary {
"themeSystem": MessageLookupByLibrary.simpleMessage("Системная"),
"tutorial": MessageLookupByLibrary.simpleMessage("Как играть"),
"viewLevels": MessageLookupByLibrary.simpleMessage("Посмотреть уровни"),
"viewStatistic": MessageLookupByLibrary.simpleMessage("Посмотреть статистику"),
"viewStatistic":
MessageLookupByLibrary.simpleMessage("Посмотреть статистику"),
"winMessage": MessageLookupByLibrary.simpleMessage("Вы победили!"),
"winRate": MessageLookupByLibrary.simpleMessage("Показатель\nпобед"),
"wordNotFound": MessageLookupByLibrary.simpleMessage("Слово не найдено в словаре"),
"wordTooShort": MessageLookupByLibrary.simpleMessage("Слово неправильной длины")
"wordNotFound":
MessageLookupByLibrary.simpleMessage("Слово не найдено в словаре"),
"wordTooShort":
MessageLookupByLibrary.simpleMessage("Слово неправильной длины")
};
}
16 changes: 9 additions & 7 deletions lib/src/core/localization/generated/l10n.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions lib/src/core/localization/localization.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:wordly/src/core/localization/generated/l10n.dart';
Expand Down Expand Up @@ -35,6 +36,19 @@ final class Localization extends GeneratedLocalization {
/// Locale which is currently used.
final Locale locale;

/// Computes the default locale.
///
/// This is the locale that is used when no locale is specified.
static Locale computeDefaultLocale() {
final locale = PlatformDispatcher.instance.locale;

if (const AppLocalizationDelegate().isSupported(locale)) {
return locale;
}

return const Locale('en');
}

/// Obtain [Localization] instance from [BuildContext].
static Localization of(BuildContext context) =>
Localizations.of<Localization>(context, Localization) ??
Expand Down
15 changes: 15 additions & 0 deletions lib/src/core/utils/extensions/context_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,21 @@ extension ContextExtension on BuildContext {
'out_of_scope',
));

/// Maybe inherit specific aspect from [InheritedModel].
T? maybeInheritFrom<A extends Object, T extends InheritedModel<A>>(
A? aspect,
) =>
InheritedModel.inheritFrom<T>(this, aspect: aspect);

/// Inherit specific aspect from [InheritedModel].
T inheritFrom<A extends Object, T extends InheritedModel<A>>({A? aspect}) =>
InheritedModel.inheritFrom<T>(this, aspect: aspect) ??
(throw ArgumentError(
'Out of scope, not found inherited model '
'a $T of the exact type',
'out_of_scope',
));

Dependencies get dependencies => DependenciesScope.of(this);

ThemeData get theme => Theme.of(this);
Expand Down
15 changes: 10 additions & 5 deletions lib/src/core/utils/logger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:logging/logging.dart' as logging;

/// Logger instance
/// Logger instance declared as global variable
///
/// Usage:
/// ```dart
/// logger.info('Hello World!');
/// ```
final Logger logger = LoggerLogging();

/// Typedef for the log formatter
Expand Down Expand Up @@ -138,7 +143,7 @@ abstract base class Logger {

/// Default logger using logging package
final class LoggerLogging extends Logger {
final _logger = logging.Logger('SizzleLogger');
final _logger = logging.Logger('WordlyLogger');

@override
void debug(String message) => _logger.fine(message);
Expand Down Expand Up @@ -167,7 +172,7 @@ final class LoggerLogging extends Logger {
}
logging.hierarchicalLoggingEnabled = true;

_logger.onRecord.where((event) => event.loggerName == 'SizzleLogger').listen((event) {
_logger.onRecord.where((event) => event.loggerName == 'WordlyLogger').listen((event) {
final logMessage = event.toLogMessage();
final message =
options.formatter?.call(logMessage, options) ?? _formatLoggerMessage(log: logMessage, options: options);
Expand Down Expand Up @@ -201,12 +206,12 @@ String _formatLoggerMessage({
buffer.write(log.message);
if (log.error != null) {
buffer
..write(' | ')
..writeln()
..write(log.error);
}
if (log.stackTrace != null) {
buffer
..write(' | ')
..writeln()
..writeln(log.stackTrace);
}

Expand Down
2 changes: 0 additions & 2 deletions lib/src/core/utils/pattern_match.dart

This file was deleted.

14 changes: 6 additions & 8 deletions lib/src/core/utils/preferences_dao.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import 'package:shared_preferences/shared_preferences.dart';
/// {@endtemplate}
abstract base class PreferencesDao {
/// {@macro preferences_dao}
PreferencesDao(this._sharedPreferences);

const PreferencesDao({required SharedPreferences sharedPreferences}) : _sharedPreferences = sharedPreferences;
final SharedPreferences _sharedPreferences;

/// Obtain [bool] entry from the preferences.
Expand Down Expand Up @@ -71,8 +70,12 @@ final class _PreferencesEntry<T extends Object> extends PreferencesEntry<T> {
required SharedPreferences sharedPreferences,
required this.key,
}) : _sharedPreferences = sharedPreferences;

final SharedPreferences _sharedPreferences;

@override
final String key;

@override
T? read() {
final value = _sharedPreferences.get(key);
Expand All @@ -85,14 +88,9 @@ final class _PreferencesEntry<T extends Object> extends PreferencesEntry<T> {
return value;
}

throw Exception(
'The value of $key is not of type ${T.runtimeType}',
);
throw Exception('The value of $key is not of type ${T.runtimeType}');
}

@override
final String key;

@override
Future<void> set(T value) => switch (value) {
final int value => _sharedPreferences.setInt(key, value),
Expand Down
2 changes: 1 addition & 1 deletion lib/src/feature/app/data/theme_datasource.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ abstract interface class ThemeDataSource {
/// {@macro theme_datasource}
final class ThemeDataSourceImpl extends PreferencesDao implements ThemeDataSource {
/// {@macro theme_datasource}
ThemeDataSourceImpl(super._sharedPreferences);
ThemeDataSourceImpl({required super.sharedPreferences});

PreferencesEntry<String> get _themeMode => stringEntry('theme_mode');

Expand Down
12 changes: 6 additions & 6 deletions lib/src/feature/game/logic/game_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:wordly/src/feature/game/data/game_repository.dart';
import 'package:wordly/src/feature/game/model/game_mode.dart';
import 'package:wordly/src/feature/game/model/game_result.dart';
import 'package:wordly/src/feature/game/model/keyboard.dart';
import 'package:wordly/src/feature/game/model/letter_info.dart';
import 'package:wordly/src/feature/game/model/word_error.dart';
import 'package:wordly/src/feature/level/data/level_repository.dart';
Expand Down Expand Up @@ -132,12 +133,11 @@ class GameBloc extends Bloc<GameEvent, GameState> {
return;
}

// TODO(Carapacik): letter
// final letter = KeyboardKeys.fromLogicalKey(event.keyDown.logicalKey);
// if (letter != null) {
// add(GameEvent.letterPressed(letter));
// return;
// }
final letter = GameKeyboardKey.toLetter(key.logicalKey, state.dictionary);
if (letter != null) {
add(GameEvent.letterPressed(letter));
return;
}
}

void _changeDictionary(_GameEventChangeDictionary event, Emitter<GameState> emit) {
Expand Down
Loading

0 comments on commit f503fd2

Please sign in to comment.