diff --git a/android/gradle.properties b/android/gradle.properties index 24add27a90a4accaf6a1ee28ec651d0d6bda4f8e..eeed3ef5a3d04530f5624cce71b2a57976938aed 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.20 -app.versionCode=20 +app.versionName=0.0.21 +app.versionCode=21 diff --git a/fastlane/metadata/android/en-US/changelogs/21.txt b/fastlane/metadata/android/en-US/changelogs/21.txt new file mode 100644 index 0000000000000000000000000000000000000000..3839fa4157cb85d9f5b8063514a7a3a789c93062 --- /dev/null +++ b/fastlane/metadata/android/en-US/changelogs/21.txt @@ -0,0 +1 @@ +Split parameters in global parameters and game parameters. diff --git a/fastlane/metadata/android/fr-FR/changelogs/21.txt b/fastlane/metadata/android/fr-FR/changelogs/21.txt new file mode 100644 index 0000000000000000000000000000000000000000..885e44fbea05cb56626691150be3266d3b9eeb8d --- /dev/null +++ b/fastlane/metadata/android/fr-FR/changelogs/21.txt @@ -0,0 +1 @@ +Séparation des paramètres en paramètre globaux et paramètres de jeu. diff --git a/lib/config/default_game_settings.dart b/lib/config/default_game_settings.dart index 64fd2221a23fa55d4a65d082fbe5ee1d1aadd322..f57c9587708d3692fb9f1b27d0efbec02c8b749b 100644 --- a/lib/config/default_game_settings.dart +++ b/lib/config/default_game_settings.dart @@ -2,7 +2,6 @@ class DefaultGameSettings { static const List<String> availableParameters = [ 'boardSize', 'colorsCount', - 'colorsTheme', ]; static const int boardSizeValueSmall = 6; @@ -31,28 +30,12 @@ class DefaultGameSettings { colorsCountValueVeryHigh, ]; - static const int defaultColorsThemeValue = 1; - static const List<int> allowedColorsThemeValues = [ - // 0, // 0x9D9D9D,0xFFFFFF,0xBE2633,0xE06F8B,0x493C2B,0xA46422,0xEB8931,0xF7E26B,0x2F484E,0x44891A,0xA3CE27,0x1B2632,0x005784,0x31A2F2,0xB2DCEF,// legacy - 1, // 0x0e0e12,0x1a1a24,0x333346,0x535373,0x8080a4,0xa6a6bf,0xc1c1d2,0xe6e6ec, // https://lospec.com/palette-list/gothic-bit - 2, // 0x615e85,0x9c8dc2,0xd9a3cd,0xebc3a7,0xe0e0dc,0xa3d1af,0x90b4de,0x717fb0, // https://lospec.com/palette-list/sweethope - 3, // 0xd9af80,0xb07972,0x524352,0x686887,0x7f9bb0,0xbfd4b0,0x90b870,0x628c70, // https://lospec.com/palette-list/nostalgic-dreams - 4, // 0x8bc7bf,0x5796a1,0x524bb3,0x471b6e,0x702782,0xb0455a,0xde8b6f,0xebd694, // https://lospec.com/palette-list/arjibi8 - // 5, // 0x40263e,0x5979a6,0x84c2a3,0xefe8c3,0xefefef,0xcbc7d6,0xd06060,0x773971, // https://lospec.com/palette-list/kotomasho-8 - // 6, // 0xf0f0eb,0xffff8f,0x7be098,0x849ad8,0xe8b382,0xd8828e,0xa776c1,0x545155, // https://lospec.com/palette-list/desatur8 - // 7, // 0x211d38,0x2e2a4f,0x3b405e,0x60556e,0x9a6278,0xc7786f,0xcfa98a,0xcdd4a5, // https://lospec.com/palette-list/purplemorning8 - // 8, // 0x332422,0xc95b40,0xff9b5e,0xfcdf76,0x4c2f7f,0x3a66ad,0x39cec2,0xfafff9, // https://lospec.com/palette-list/cold-war-8 - // 9, // 0x111323,0x374566,0x50785d,0x8497b3,0xe8dcd8,0xcfb463,0xb35447,0x692e4b, // https://lospec.com/palette-list/low-8 - ]; - static List<int> getAvailableValues(String parameterCode) { switch (parameterCode) { case 'boardSize': return DefaultGameSettings.allowedBoardSizeValues; case 'colorsCount': return DefaultGameSettings.allowedColorsCountValues; - case 'colorsTheme': - return DefaultGameSettings.allowedColorsThemeValues; } return []; diff --git a/lib/config/default_global_settings.dart b/lib/config/default_global_settings.dart new file mode 100644 index 0000000000000000000000000000000000000000..420faf0edd22548df0c7baafc2a07b55b9a54f86 --- /dev/null +++ b/lib/config/default_global_settings.dart @@ -0,0 +1,28 @@ +class DefaultGlobalSettings { + static const List<String> availableParameters = [ + 'colorsTheme', + ]; + + static const int defaultColorsThemeValue = 1; + static const List<int> allowedColorsThemeValues = [ + // 0, // 0x9D9D9D,0xFFFFFF,0xBE2633,0xE06F8B,0x493C2B,0xA46422,0xEB8931,0xF7E26B,0x2F484E,0x44891A,0xA3CE27,0x1B2632,0x005784,0x31A2F2,0xB2DCEF,// legacy + 1, // 0x0e0e12,0x1a1a24,0x333346,0x535373,0x8080a4,0xa6a6bf,0xc1c1d2,0xe6e6ec, // https://lospec.com/palette-list/gothic-bit + 2, // 0x615e85,0x9c8dc2,0xd9a3cd,0xebc3a7,0xe0e0dc,0xa3d1af,0x90b4de,0x717fb0, // https://lospec.com/palette-list/sweethope + 3, // 0xd9af80,0xb07972,0x524352,0x686887,0x7f9bb0,0xbfd4b0,0x90b870,0x628c70, // https://lospec.com/palette-list/nostalgic-dreams + 4, // 0x8bc7bf,0x5796a1,0x524bb3,0x471b6e,0x702782,0xb0455a,0xde8b6f,0xebd694, // https://lospec.com/palette-list/arjibi8 + // 5, // 0x40263e,0x5979a6,0x84c2a3,0xefe8c3,0xefefef,0xcbc7d6,0xd06060,0x773971, // https://lospec.com/palette-list/kotomasho-8 + // 6, // 0xf0f0eb,0xffff8f,0x7be098,0x849ad8,0xe8b382,0xd8828e,0xa776c1,0x545155, // https://lospec.com/palette-list/desatur8 + // 7, // 0x211d38,0x2e2a4f,0x3b405e,0x60556e,0x9a6278,0xc7786f,0xcfa98a,0xcdd4a5, // https://lospec.com/palette-list/purplemorning8 + // 8, // 0x332422,0xc95b40,0xff9b5e,0xfcdf76,0x4c2f7f,0x3a66ad,0x39cec2,0xfafff9, // https://lospec.com/palette-list/cold-war-8 + // 9, // 0x111323,0x374566,0x50785d,0x8497b3,0xe8dcd8,0xcfb463,0xb35447,0x692e4b, // https://lospec.com/palette-list/low-8 + ]; + + static List<int> getAvailableValues(String parameterCode) { + switch (parameterCode) { + case 'colorsTheme': + return DefaultGlobalSettings.allowedColorsThemeValues; + } + + return []; + } +} diff --git a/lib/cubit/game_cubit.dart b/lib/cubit/game_cubit.dart index f7570750b42a30464ba3298a57b4704521931fc4..2247d394a99054da1992eb0ea8933870a17c5ba3 100644 --- a/lib/cubit/game_cubit.dart +++ b/lib/cubit/game_cubit.dart @@ -1,11 +1,12 @@ import 'package:equatable/equatable.dart'; import 'package:flutter/material.dart'; import 'package:hydrated_bloc/hydrated_bloc.dart'; -import 'package:jeweled/config/default_game_settings.dart'; +import 'package:jeweled/config/default_game_settings.dart'; import 'package:jeweled/models/game.dart'; import 'package:jeweled/models/cell_location.dart'; -import 'package:jeweled/models/game_settings.dart'; +import 'package:jeweled/models/settings_game.dart'; +import 'package:jeweled/models/settings_global.dart'; part 'game_state.dart'; @@ -24,7 +25,8 @@ class GameCubit extends HydratedCubit<GameState> { void refresh() { final Game game = Game( board: state.currentGame.board, - settings: state.currentGame.settings, + gameSettings: state.currentGame.gameSettings, + globalSettings: state.currentGame.globalSettings, shuffledColors: state.currentGame.shuffledColors, isRunning: state.currentGame.isRunning, isFinished: state.currentGame.isFinished, @@ -74,8 +76,8 @@ class GameCubit extends HydratedCubit<GameState> { moveCellsDown() { final Game currentGame = this.state.currentGame; - final int boardSizeHorizontal = currentGame.settings.boardSize; - final int boardSizeVertical = currentGame.settings.boardSize; + final int boardSizeHorizontal = currentGame.gameSettings.boardSize; + final int boardSizeVertical = currentGame.gameSettings.boardSize; for (int row = 0; row < boardSizeVertical; row++) { for (int col = 0; col < boardSizeHorizontal; col++) { @@ -136,9 +138,13 @@ class GameCubit extends HydratedCubit<GameState> { } } - void startNewGame(GameSettings settings) { + void startNewGame({ + required GameSettings gameSettings, + required GlobalSettings globalSettings, + }) { Game newGame = Game.createNew( - gameSettings: settings, + gameSettings: gameSettings, + globalSettings: globalSettings, ); newGame.dump(); diff --git a/lib/cubit/settings_cubit.dart b/lib/cubit/settings_game_cubit.dart similarity index 62% rename from lib/cubit/settings_cubit.dart rename to lib/cubit/settings_game_cubit.dart index 99a2ac2d5b3c7d265fbc2683039727d35caa6ae0..d637cec6a3e16f049ccea497a1ed22653563491e 100644 --- a/lib/cubit/settings_cubit.dart +++ b/lib/cubit/settings_game_cubit.dart @@ -2,24 +2,22 @@ import 'package:equatable/equatable.dart'; import 'package:flutter/material.dart'; import 'package:hydrated_bloc/hydrated_bloc.dart'; -import 'package:jeweled/models/game_settings.dart'; +import 'package:jeweled/models/settings_game.dart'; -part 'settings_state.dart'; +part 'settings_game_state.dart'; -class SettingsCubit extends HydratedCubit<SettingsState> { - SettingsCubit() : super(SettingsState(settings: GameSettings.createDefault())); +class GameSettingsCubit extends HydratedCubit<GameSettingsState> { + GameSettingsCubit() : super(GameSettingsState(settings: GameSettings.createDefault())); void setValues({ int? boardSize, int? colorsCount, - int? colorsTheme, }) { emit( - SettingsState( + GameSettingsState( settings: GameSettings( boardSize: boardSize ?? state.settings.boardSize, colorsCount: colorsCount ?? state.settings.colorsCount, - colorsTheme: colorsTheme ?? state.settings.colorsTheme, ), ), ); @@ -31,48 +29,41 @@ class SettingsCubit extends HydratedCubit<SettingsState> { return GameSettings.getBoardSizeValueFromUnsafe(state.settings.boardSize); case 'colorsCount': return GameSettings.getColorsCountValueFromUnsafe(state.settings.colorsCount); - case 'colorsTheme': - return GameSettings.getColorsThemeValueFromUnsafe(state.settings.colorsTheme); } return 0; } void setParameterValue(String code, int value) { - print('SettingsCubit.setParameterValue'); + print('GameSettingsCubit.setParameterValue'); print('code: ' + code + ' / value: ' + value.toString()); int boardSize = code == 'boardSize' ? value : getParameterValue('boardSize'); int colorsCount = code == 'colorsCount' ? value : getParameterValue('colorsCount'); - int colorsTheme = code == 'colorsTheme' ? value : getParameterValue('colorsTheme'); setValues( boardSize: boardSize, colorsCount: colorsCount, - colorsTheme: colorsTheme, ); } @override - SettingsState? fromJson(Map<String, dynamic> json) { + GameSettingsState? fromJson(Map<String, dynamic> json) { int boardSize = json['boardSize'] as int; int colorsCount = json['colorsCount'] as int; - int colorsTheme = json['colorsTheme'] as int; - return SettingsState( + return GameSettingsState( settings: GameSettings( boardSize: boardSize, colorsCount: colorsCount, - colorsTheme: colorsTheme, ), ); } @override - Map<String, dynamic>? toJson(SettingsState state) { + Map<String, dynamic>? toJson(GameSettingsState state) { return <String, dynamic>{ 'boardSize': state.settings.boardSize, 'colorsCount': state.settings.colorsCount, - 'colorsTheme': state.settings.colorsTheme, }; } } diff --git a/lib/cubit/settings_state.dart b/lib/cubit/settings_game_state.dart similarity index 70% rename from lib/cubit/settings_state.dart rename to lib/cubit/settings_game_state.dart index b7125618710059d16893a9d87e74c6e2565a8603..b773dc69be12673b158e880e2d7e6e7bec465506 100644 --- a/lib/cubit/settings_state.dart +++ b/lib/cubit/settings_game_state.dart @@ -1,8 +1,8 @@ -part of 'settings_cubit.dart'; +part of 'settings_game_cubit.dart'; @immutable -class SettingsState extends Equatable { - const SettingsState({ +class GameSettingsState extends Equatable { + const GameSettingsState({ required this.settings, }); diff --git a/lib/cubit/settings_global_cubit.dart b/lib/cubit/settings_global_cubit.dart new file mode 100644 index 0000000000000000000000000000000000000000..d4a61c8c8f2b95df71eaef47859b9b0dabe0dc3d --- /dev/null +++ b/lib/cubit/settings_global_cubit.dart @@ -0,0 +1,60 @@ +import 'package:equatable/equatable.dart'; +import 'package:flutter/material.dart'; +import 'package:hydrated_bloc/hydrated_bloc.dart'; + +import 'package:jeweled/models/settings_global.dart'; + +part 'settings_global_state.dart'; + +class GlobalSettingsCubit extends HydratedCubit<GlobalSettingsState> { + GlobalSettingsCubit() : super(GlobalSettingsState(settings: GlobalSettings.createDefault())); + + void setValues({ + int? colorsTheme, + }) { + emit( + GlobalSettingsState( + settings: GlobalSettings( + colorsTheme: colorsTheme ?? state.settings.colorsTheme, + ), + ), + ); + } + + int getParameterValue(String code) { + switch (code) { + case 'colorsTheme': + return GlobalSettings.getColorsThemeValueFromUnsafe(state.settings.colorsTheme); + } + return 0; + } + + void setParameterValue(String code, int value) { + print('GlobalSettingsCubit.setParameterValue'); + print('code: ' + code + ' / value: ' + value.toString()); + + int colorsTheme = code == 'colorsTheme' ? value : getParameterValue('colorsTheme'); + + setValues( + colorsTheme: colorsTheme, + ); + } + + @override + GlobalSettingsState? fromJson(Map<String, dynamic> json) { + int colorsTheme = json['colorsTheme'] as int; + + return GlobalSettingsState( + settings: GlobalSettings( + colorsTheme: colorsTheme, + ), + ); + } + + @override + Map<String, dynamic>? toJson(GlobalSettingsState state) { + return <String, dynamic>{ + 'colorsTheme': state.settings.colorsTheme, + }; + } +} diff --git a/lib/cubit/settings_global_state.dart b/lib/cubit/settings_global_state.dart new file mode 100644 index 0000000000000000000000000000000000000000..4e4fbdf707b4e805f2092d0ca6a68a2de1c957c6 --- /dev/null +++ b/lib/cubit/settings_global_state.dart @@ -0,0 +1,19 @@ +part of 'settings_global_cubit.dart'; + +@immutable +class GlobalSettingsState extends Equatable { + const GlobalSettingsState({ + required this.settings, + }); + + final GlobalSettings settings; + + @override + List<dynamic> get props => <dynamic>[ + settings, + ]; + + Map<String, dynamic> get values => <String, dynamic>{ + 'settings': settings, + }; +} diff --git a/lib/main.dart b/lib/main.dart index df1d2ede98d81dc85c3f60fd54d0c5f96c48fd82..5ee1917f0684353e0a71c82e1164f1bad9cf017b 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -8,8 +8,9 @@ import 'package:hydrated_bloc/hydrated_bloc.dart'; import 'package:path_provider/path_provider.dart'; import 'package:jeweled/config/theme.dart'; -import 'package:jeweled/cubit/settings_cubit.dart'; import 'package:jeweled/cubit/game_cubit.dart'; +import 'package:jeweled/cubit/settings_game_cubit.dart'; +import 'package:jeweled/cubit/settings_global_cubit.dart'; import 'package:jeweled/ui/skeleton.dart'; void main() async { @@ -44,7 +45,8 @@ class MyApp extends StatelessWidget { return MultiBlocProvider( providers: [ BlocProvider<GameCubit>(create: (context) => GameCubit()), - BlocProvider<SettingsCubit>(create: (context) => SettingsCubit()), + BlocProvider<GlobalSettingsCubit>(create: (context) => GlobalSettingsCubit()), + BlocProvider<GameSettingsCubit>(create: (context) => GameSettingsCubit()), ], child: MaterialApp( title: 'Jeweled', diff --git a/lib/models/game.dart b/lib/models/game.dart index 4ba3fe74e7c06e6b7cb2964310a4a8fd75deda42..01ca0afacedae4090edee8db34e82510686eb20d 100644 --- a/lib/models/game.dart +++ b/lib/models/game.dart @@ -1,15 +1,17 @@ import 'dart:math'; -import 'package:jeweled/config/default_game_settings.dart'; +import 'package:jeweled/config/default_global_settings.dart'; import 'package:jeweled/models/game_board.dart'; import 'package:jeweled/models/game_cell.dart'; import 'package:jeweled/models/cell_location.dart'; -import 'package:jeweled/models/game_settings.dart'; +import 'package:jeweled/models/settings_game.dart'; +import 'package:jeweled/models/settings_global.dart'; import 'package:jeweled/utils/color_theme.dart'; class Game { final GameBoard board; - final GameSettings settings; + final GameSettings gameSettings; + final GlobalSettings globalSettings; List<int> shuffledColors = []; bool isRunning = false; bool isFinished = false; @@ -19,7 +21,8 @@ class Game { Game({ required this.board, - required this.settings, + required this.gameSettings, + required this.globalSettings, required this.shuffledColors, this.isRunning = false, this.isFinished = false, @@ -31,18 +34,24 @@ class Game { factory Game.createNull() { return Game( board: GameBoard.createNull(), - settings: GameSettings.createDefault(), - shuffledColors: shuffleColors(DefaultGameSettings.defaultColorsThemeValue), + gameSettings: GameSettings.createDefault(), + globalSettings: GlobalSettings.createDefault(), + shuffledColors: shuffleColors(DefaultGlobalSettings.defaultColorsThemeValue), ); } - factory Game.createNew({GameSettings? gameSettings}) { - GameSettings settings = gameSettings ?? GameSettings.createDefault(); + factory Game.createNew({ + GameSettings? gameSettings, + GlobalSettings? globalSettings, + }) { + GameSettings newGameSettings = gameSettings ?? GameSettings.createDefault(); + GlobalSettings newGlobalSettings = globalSettings ?? GlobalSettings.createDefault(); return Game( - board: GameBoard.createRandom(settings), - settings: settings, - shuffledColors: shuffleColors(settings.colorsTheme), + board: GameBoard.createRandom(newGameSettings), + gameSettings: newGameSettings, + globalSettings: newGlobalSettings, + shuffledColors: shuffleColors(newGlobalSettings.colorsTheme), isRunning: true, ); } @@ -100,8 +109,8 @@ class Game { final CellLocation referenceCellLocation, List<CellLocation> siblingCells, ) { - final int boardSizeHorizontal = this.settings.boardSize; - final int boardSizeVertical = this.settings.boardSize; + final int boardSizeHorizontal = this.gameSettings.boardSize; + final int boardSizeVertical = this.gameSettings.boardSize; final int? referenceValue = this.getCellValue(referenceCellLocation); @@ -137,8 +146,8 @@ class Game { } List<List<CellLocation>> getAvailableBlocks(final Game game) { - final int boardSizeHorizontal = game.settings.boardSize; - final int boardSizeVertical = game.settings.boardSize; + final int boardSizeHorizontal = game.gameSettings.boardSize; + final int boardSizeVertical = game.gameSettings.boardSize; final List<List<CellLocation>> blocks = []; @@ -170,8 +179,8 @@ class Game { } bool hasAtLeastOneAvailableBlock() { - final int boardSizeHorizontal = this.settings.boardSize; - final int boardSizeVertical = this.settings.boardSize; + final int boardSizeHorizontal = this.gameSettings.boardSize; + final int boardSizeVertical = this.gameSettings.boardSize; for (int row = 0; row < boardSizeVertical; row++) { for (int col = 0; col < boardSizeHorizontal; col++) { @@ -192,9 +201,9 @@ class Game { bool isInBoard(CellLocation cell) { if (cell.row > 0 && - cell.row < this.settings.boardSize && + cell.row < this.gameSettings.boardSize && cell.col > 0 && - cell.col < this.settings.boardSize) { + cell.col < this.gameSettings.boardSize) { return true; } return false; @@ -208,14 +217,14 @@ class Game { final List<int> values = []; // All eligible values (twice) - final int maxValue = this.settings.colorsCount; + final int maxValue = this.gameSettings.colorsCount; for (int i = 1; i <= maxValue; i++) { values.add(i); values.add(i); } // Add values of current col (twice) - for (int r = 0; r <= this.settings.boardSize; r++) { + for (int r = 0; r <= this.gameSettings.boardSize; r++) { if (this.isInBoard(CellLocation.go(r, col))) { final int? value = this.getCellValue(CellLocation.go(r, col)); if (value != null) { @@ -228,12 +237,12 @@ class Game { // Add values of sibling cols (twice for top rows) for (int deltaCol = -1; deltaCol <= 1; deltaCol++) { final int c = col + deltaCol; - for (int r = 0; r < this.settings.boardSize; r++) { + for (int r = 0; r < this.gameSettings.boardSize; r++) { if (this.isInBoard(CellLocation.go(r, c))) { final int? value = this.getCellValue(CellLocation.go(r, c)); if (value != null) { values.add(value); - if (row < this.settings.boardSize / 3) { + if (row < this.gameSettings.boardSize / 3) { values.add(value); } } @@ -263,7 +272,8 @@ class Game { print(''); print('## Current game dump:'); print(''); - this.settings.dump(); + this.gameSettings.dump(); + this.globalSettings.dump(); print(''); this.board.dump(); print(''); @@ -284,7 +294,8 @@ class Game { Map<String, dynamic>? toJson() { return <String, dynamic>{ 'board': this.board.toJson(), - 'settings': this.settings.toJson(), + 'gameSettings': this.gameSettings.toJson(), + 'globalSettings': this.globalSettings.toJson(), 'shuffledColors': this.shuffledColors, 'isRunning': this.isRunning, 'isFinished': this.isFinished, diff --git a/lib/models/game_board.dart b/lib/models/game_board.dart index 71776f1ae4171dc8033fb51faa6eca65a537651b..a9bf7cb9e9cceb3dd737618c17ea9a84d738abc6 100644 --- a/lib/models/game_board.dart +++ b/lib/models/game_board.dart @@ -1,7 +1,7 @@ import 'dart:math'; import 'package:jeweled/models/game_cell.dart'; -import 'package:jeweled/models/game_settings.dart'; +import 'package:jeweled/models/settings_game.dart'; class GameBoard { final List<List<GameCell>> cells; diff --git a/lib/models/game_settings.dart b/lib/models/settings_game.dart similarity index 73% rename from lib/models/game_settings.dart rename to lib/models/settings_game.dart index 7e636dc4818d1bf6b583c13a234a3553f10fa5ee..6e2cb12098401e1187ff7d5afc89928d9cf8a4be 100644 --- a/lib/models/game_settings.dart +++ b/lib/models/settings_game.dart @@ -3,12 +3,10 @@ import 'package:jeweled/config/default_game_settings.dart'; class GameSettings { final int boardSize; final int colorsCount; - final int colorsTheme; GameSettings({ required this.boardSize, required this.colorsCount, - required this.colorsTheme, }); static int getBoardSizeValueFromUnsafe(int size) { @@ -27,19 +25,10 @@ class GameSettings { return DefaultGameSettings.defaultColorsCountValue; } - static int getColorsThemeValueFromUnsafe(int colorsTheme) { - if (DefaultGameSettings.allowedColorsThemeValues.contains(colorsTheme)) { - return colorsTheme; - } - - return DefaultGameSettings.defaultColorsThemeValue; - } - factory GameSettings.createDefault() { return GameSettings( boardSize: DefaultGameSettings.defaultBoardSizeValue, colorsCount: DefaultGameSettings.defaultColorsCountValue, - colorsTheme: DefaultGameSettings.defaultColorsThemeValue, ); } @@ -47,7 +36,6 @@ class GameSettings { print('Settings: '); print(' boardSize: ' + boardSize.toString()); print(' colorsCount: ' + colorsCount.toString()); - print(' colorsTheme: ' + colorsTheme.toString()); } String toString() { @@ -58,7 +46,6 @@ class GameSettings { return <String, dynamic>{ 'boardSize': this.boardSize, 'colorsCount': this.colorsCount, - 'colorsTheme': this.colorsTheme, }; } } diff --git a/lib/models/settings_global.dart b/lib/models/settings_global.dart new file mode 100644 index 0000000000000000000000000000000000000000..8156993df521018fa50f7522b5ee1d34705e7d90 --- /dev/null +++ b/lib/models/settings_global.dart @@ -0,0 +1,38 @@ +import 'package:jeweled/config/default_global_settings.dart'; + +class GlobalSettings { + final int colorsTheme; + + GlobalSettings({ + required this.colorsTheme, + }); + + static int getColorsThemeValueFromUnsafe(int colorsTheme) { + if (DefaultGlobalSettings.allowedColorsThemeValues.contains(colorsTheme)) { + return colorsTheme; + } + + return DefaultGlobalSettings.defaultColorsThemeValue; + } + + factory GlobalSettings.createDefault() { + return GlobalSettings( + colorsTheme: DefaultGlobalSettings.defaultColorsThemeValue, + ); + } + + void dump() { + print('Settings: '); + print(' colorsTheme: ' + colorsTheme.toString()); + } + + String toString() { + return 'GlobalSettings(' + this.toJson().toString() + ')'; + } + + Map<String, dynamic>? toJson() { + return <String, dynamic>{ + 'colorsTheme': this.colorsTheme, + }; + } +} diff --git a/lib/ui/painters/game_board_painter.dart b/lib/ui/painters/game_board_painter.dart index 1d72bad22e55662a10202bd32d95321aa32f26ed..52ef2114ecd06e37972392f8d8c9f9bf61416c3a 100644 --- a/lib/ui/painters/game_board_painter.dart +++ b/lib/ui/painters/game_board_painter.dart @@ -16,8 +16,8 @@ class GameBoardPainter extends CustomPainter { void paint(Canvas canvas, Size size) { final double canvasSize = min(size.width, size.height); - final int cellsCountHorizontal = game.settings.boardSize; - final int cellsCountVertical = game.settings.boardSize; + final int cellsCountHorizontal = game.gameSettings.boardSize; + final int cellsCountVertical = game.gameSettings.boardSize; final double cellSize = canvasSize / max(cellsCountHorizontal, cellsCountVertical); @@ -33,7 +33,8 @@ class GameBoardPainter extends CustomPainter { final CellLocation cellLocation = CellLocation.go(row, col); final int? cellValue = game.getCellValueShuffled(cellLocation); if (cellValue != null) { - final int colorCode = ColorTheme.getColorCode(cellValue, game.settings.colorsTheme); + final int colorCode = + ColorTheme.getColorCode(cellValue, game.globalSettings.colorsTheme); final Animation<double>? translation = this.animations[row][col]; final double y = yOrigin + (translation?.value ?? 0) * cellSize; diff --git a/lib/ui/painters/parameter_painter.dart b/lib/ui/painters/parameter_painter.dart index dcfdf5948b5f32433d3379061e407827fb3c6283..9bbfd47c691e7e32b81ec91e565af00fdc73660f 100644 --- a/lib/ui/painters/parameter_painter.dart +++ b/lib/ui/painters/parameter_painter.dart @@ -3,7 +3,8 @@ import 'dart:math'; import 'package:flutter/material.dart'; import 'package:jeweled/config/default_game_settings.dart'; -import 'package:jeweled/models/game_settings.dart'; +import 'package:jeweled/models/settings_game.dart'; +import 'package:jeweled/models/settings_global.dart'; import 'package:jeweled/utils/color_extensions.dart'; import 'package:jeweled/utils/color_theme.dart'; @@ -13,12 +14,14 @@ class ParameterPainter extends CustomPainter { required this.value, required this.isSelected, required this.gameSettings, + required this.globalSettings, }); final String code; final int value; final bool isSelected; final GameSettings gameSettings; + final GlobalSettings globalSettings; @override void paint(Canvas canvas, Size size) { @@ -128,7 +131,7 @@ class ParameterPainter extends CustomPainter { final Offset bottomRight = topLeft + Offset(cellSize, cellSize); final squareColor = - Color(ColorTheme.getColorCode(col + row * gridWidth, gameSettings.colorsTheme)); + Color(ColorTheme.getColorCode(col + row * gridWidth, globalSettings.colorsTheme)); paint.color = squareColor; paint.style = PaintingStyle.fill; @@ -194,7 +197,8 @@ class ParameterPainter extends CustomPainter { final Offset bottomRight = topLeft + Offset(width, width); - final squareColor = Color(ColorTheme.getColorCode(colorIndex, gameSettings.colorsTheme)); + final squareColor = + Color(ColorTheme.getColorCode(colorIndex, globalSettings.colorsTheme)); paint.color = squareColor; paint.style = PaintingStyle.fill; canvas.drawRect(Rect.fromPoints(topLeft, bottomRight), paint); diff --git a/lib/ui/widgets/game_board.dart b/lib/ui/widgets/game_board.dart index e17b1b12fd426e0b924b398ce82a4b263b265e71..402b200d14d77d99666d86efab046f9c97c461e9 100644 --- a/lib/ui/widgets/game_board.dart +++ b/lib/ui/widgets/game_board.dart @@ -57,7 +57,7 @@ class _GameBoard extends State<GameBoard> with TickerProviderStateMixin { if (status == AnimationStatus.completed) { gameCubit.postAnimate(); - resetAnimations(currentGame.settings.boardSize); + resetAnimations(currentGame.gameSettings.boardSize); setState(() {}); controller.dispose(); @@ -66,9 +66,9 @@ class _GameBoard extends State<GameBoard> with TickerProviderStateMixin { // Count translation length for each cell to move final List<List<int>> stepsDownCounts = List.generate( - currentGame.settings.boardSize, + currentGame.gameSettings.boardSize, (i) => List.generate( - currentGame.settings.boardSize, + currentGame.gameSettings.boardSize, (i) => 0, ), ); @@ -105,7 +105,7 @@ class _GameBoard extends State<GameBoard> with TickerProviderStateMixin { final Game currentGame = gameState.currentGame; if (this.animations.length == 0) { - resetAnimations(currentGame.settings.boardSize); + resetAnimations(currentGame.gameSettings.boardSize); } return GestureDetector( @@ -122,8 +122,8 @@ class _GameBoard extends State<GameBoard> with TickerProviderStateMixin { if (!animationInProgress) { final double xTap = details.localPosition.dx; final double yTap = details.localPosition.dy; - final int col = xTap ~/ (displayWidth / currentGame.settings.boardSize); - final int row = yTap ~/ (displayWidth / currentGame.settings.boardSize); + final int col = xTap ~/ (displayWidth / currentGame.gameSettings.boardSize); + final int row = yTap ~/ (displayWidth / currentGame.gameSettings.boardSize); final GameCubit gameCubit = BlocProvider.of<GameCubit>(context); animateCells(gameCubit.tapOnCell(CellLocation.go(row, col))); diff --git a/lib/ui/widgets/game_top_indicator.dart b/lib/ui/widgets/game_top_indicator.dart index 6b583b2a9511f49b8703c4e2c982be06f334f6e6..25d93d4aa2238b1ba355c320a270f22fa9719816 100644 --- a/lib/ui/widgets/game_top_indicator.dart +++ b/lib/ui/widgets/game_top_indicator.dart @@ -60,7 +60,7 @@ class GameTopIndicatorWidget extends StatelessWidget { child: Icon(UniconsSolid.refresh), onPressed: () { final GameCubit gameCubit = BlocProvider.of<GameCubit>(context); - gameCubit.shuffleColors(currentGame.settings.colorsTheme); + gameCubit.shuffleColors(currentGame.globalSettings.colorsTheme); }, ) ], diff --git a/lib/ui/widgets/parameters.dart b/lib/ui/widgets/parameters.dart index f756fadf14c34b3a4f882c77a4b5075e4e1245db..3c79260a624a54c05f7d1697ceef0f794f9fb0c0 100644 --- a/lib/ui/widgets/parameters.dart +++ b/lib/ui/widgets/parameters.dart @@ -2,43 +2,47 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:jeweled/config/default_game_settings.dart'; +import 'package:jeweled/config/default_global_settings.dart'; import 'package:jeweled/cubit/game_cubit.dart'; -import 'package:jeweled/cubit/settings_cubit.dart'; -import 'package:jeweled/models/game_settings.dart'; +import 'package:jeweled/cubit/settings_game_cubit.dart'; +import 'package:jeweled/cubit/settings_global_cubit.dart'; import 'package:jeweled/ui/painters/parameter_painter.dart'; class Parameters extends StatelessWidget { const Parameters({super.key}); - @override - Widget build(BuildContext context) { - final double displayWidth = MediaQuery.of(context).size.width; - - final double separatorHeight = 8.0; - - return BlocBuilder<SettingsCubit, SettingsState>( - builder: (BuildContext context, SettingsState settingsState) { - final GameCubit gameCubit = BlocProvider.of<GameCubit>(context); - final SettingsCubit settingsCubit = BlocProvider.of<SettingsCubit>(context); - - final List<Widget> lines = [ - SizedBox(height: separatorHeight), - ]; + final double separatorHeight = 8.0; - DefaultGameSettings.availableParameters.forEach((code) { - final List<int> availableValues = DefaultGameSettings.getAvailableValues(code); + List<Widget> buildParametersLine({ + required String code, + required bool isGlobal, + }) { + final List<Widget> parameterButtons = []; - if (availableValues.length > 1) { - final int currentValue = settingsCubit.getParameterValue(code); + final List<int> availableValues = isGlobal + ? DefaultGlobalSettings.getAvailableValues(code) + : DefaultGameSettings.getAvailableValues(code); - final double itemWidth = displayWidth / availableValues.length - 25; + availableValues.forEach((value) { + final Widget parameterButton = BlocBuilder<GameSettingsCubit, GameSettingsState>( + builder: (BuildContext context, GameSettingsState gameSettingsState) { + return BlocBuilder<GlobalSettingsCubit, GlobalSettingsState>( + builder: (BuildContext context, GlobalSettingsState globalSettingsState) { + final GameSettingsCubit gameSettingsCubit = + BlocProvider.of<GameSettingsCubit>(context); + final GlobalSettingsCubit globalSettingsCubit = + BlocProvider.of<GlobalSettingsCubit>(context); - final List<Widget> parameterButtons = []; + final int currentValue = isGlobal + ? globalSettingsCubit.getParameterValue(code) + : gameSettingsCubit.getParameterValue(code); - availableValues.forEach((value) { final bool isActive = (value == currentValue); - final Widget parameterButton = TextButton( + final double displayWidth = MediaQuery.of(context).size.width; + final double itemWidth = displayWidth / availableValues.length - 25; + + return TextButton( child: Container( margin: EdgeInsets.all(0), padding: EdgeInsets.all(0), @@ -49,33 +53,62 @@ class Parameters extends StatelessWidget { code: code, value: value, isSelected: isActive, - gameSettings: settingsState.settings, + gameSettings: gameSettingsState.settings, + globalSettings: globalSettingsState.settings, ), isComplex: true, ), ), - onPressed: () => settingsCubit.setParameterValue(code, value), + onPressed: () => isGlobal + ? globalSettingsCubit.setParameterValue(code, value) + : gameSettingsCubit.setParameterValue(code, value), ); + }, + ); + }, + ); + + parameterButtons.add(parameterButton); + }); - parameterButtons.add(parameterButton); - }); + return parameterButtons; + } - lines.add(Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: parameterButtons, - )); + @override + Widget build(BuildContext context) { + final List<Widget> lines = []; + + // Game settings + DefaultGameSettings.availableParameters.forEach((code) { + lines.add(Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: buildParametersLine( + code: code, + isGlobal: false, + ), + )); + + lines.add(SizedBox(height: separatorHeight)); + }); + + // Global settings + DefaultGlobalSettings.availableParameters.forEach((code) { + lines.add(Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: buildParametersLine( + code: code, + isGlobal: true, + ), + )); - lines.add(SizedBox(height: separatorHeight)); - } - }); + lines.add(SizedBox(height: separatorHeight)); + }); - lines.add(SizedBox(height: separatorHeight)); - lines.add(buildStartNewGameButton(gameCubit, settingsState.settings)); + lines.add(SizedBox(height: separatorHeight)); + lines.add(buildStartNewGameButton()); - return Column( - children: lines, - ); - }, + return Column( + children: lines, ); } @@ -103,32 +136,45 @@ class Parameters extends StatelessWidget { ); } - static Container buildStartNewGameButton(GameCubit gameCubit, GameSettings settings) { + static Widget buildStartNewGameButton() { const double blockMargin = 3.0; const double blockPadding = 2.0; - return Container( - margin: EdgeInsets.all(blockMargin), - padding: EdgeInsets.all(blockPadding), - child: Table( - defaultColumnWidth: IntrinsicColumnWidth(), - children: [ - TableRow( - children: [ - buildDecorationImageWidget(), - Column( + return BlocBuilder<GameSettingsCubit, GameSettingsState>( + builder: (BuildContext context, GameSettingsState gameSettingsState) { + return BlocBuilder<GlobalSettingsCubit, GlobalSettingsState>( + builder: (BuildContext context, GlobalSettingsState globalSettingsState) { + final GameCubit gameCubit = BlocProvider.of<GameCubit>(context); + + return Container( + margin: EdgeInsets.all(blockMargin), + padding: EdgeInsets.all(blockPadding), + child: Table( + defaultColumnWidth: IntrinsicColumnWidth(), children: [ - TextButton( - child: buildImageContainerWidget('button_start'), - onPressed: () => gameCubit.startNewGame(settings), + TableRow( + children: [ + buildDecorationImageWidget(), + Column( + children: [ + TextButton( + child: buildImageContainerWidget('button_start'), + onPressed: () => gameCubit.startNewGame( + gameSettings: gameSettingsState.settings, + globalSettings: globalSettingsState.settings, + ), + ), + ], + ), + buildDecorationImageWidget(), + ], ), ], ), - buildDecorationImageWidget(), - ], - ), - ], - ), + ); + }, + ); + }, ); } } diff --git a/pubspec.yaml b/pubspec.yaml index 2e61b6f8493d6139990716000eebeb0c5b2b56f9..0ddcc8520f8028902cc20b87115472126045caba 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -3,7 +3,7 @@ description: Jeweled Game publish_to: 'none' -version: 0.0.20+20 +version: 0.0.21+21 environment: sdk: '^3.0.0'