Skip to content
Snippets Groups Projects
Commit bcd6a446 authored by Benoît Harrault's avatar Benoît Harrault
Browse files

Normalize game architecture

parent 66d03459
No related branches found
No related tags found
1 merge request!36Resolve "Normalize game architecture"
Pipeline #5694 passed
This commit is part of merge request !36. Comments created here will be created in the context of that merge request.
Showing
with 148 additions and 122 deletions
org.gradle.jvmargs=-Xmx1536M org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true android.useAndroidX=true
android.enableJetifier=true android.enableJetifier=true
app.versionName=0.0.31 app.versionName=0.1.0
app.versionCode=31 app.versionCode=32
{ {
"app_name": "Jeweled", "app_name": "Jeweled",
"bottom_nav_game": "Game",
"bottom_nav_settings": "Settings",
"bottom_nav_about": "About",
"settings_title": "Settings", "settings_title": "Settings",
"settings_label_theme": "Theme mode", "settings_label_theme": "Theme mode",
"about_title": "About", "about_title": "About",
"about_content": "Simple and classic Jeweled game.", "about_content": "Simple and classic Jeweled game.",
"about_version": "Version: {version}" "about_version": "Version: {version}",
"": ""
} }
{ {
"app_name": "Jeweled", "app_name": "Jeweled",
"bottom_nav_game": "Jeu",
"bottom_nav_settings": "Réglages",
"bottom_nav_about": "Infos",
"settings_title": "Réglages", "settings_title": "Réglages",
"settings_label_theme": "Thème de couleurs", "settings_label_theme": "Thème de couleurs",
"about_title": "Informations", "about_title": "Informations",
"about_content": "Jeweled, jeu simple et classique d'associations.", "about_content": "Jeweled, jeu simple et classique d'associations.",
"about_version": "Version : {version}" "about_version": "Version : {version}",
"": ""
} }
File moved
File moved
File moved
File moved
File moved
File moved
description: This file stores settings for Dart & Flutter DevTools.
documentation: https://docs.flutter.dev/tools/devtools/extensions#configure-extension-enablement-states
extensions:
Improve/normalize game architecture.
Amélioration/normalisation de l'architecture du jeu.
<?xml version="1.0" encoding="UTF-8"?>
<svg enable-background="new 0 0 100 100" version="1.1" viewBox="0 0 102 102" xml:space="preserve" xmlns="http://www.w3.org/2000/svg"><rect x="1" y="1" width="100" height="100" ry="0" fill="#be6ade" stroke="#000" stroke-width="2"/></svg>
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class ColorTheme { class ColorTheme {
static Map<int, List<int>> itemColors = { static Map<String, List<int>> itemColors = {
// legacy // legacy
// 0:[0x9D9D9D,0xFFFFFF,0xBE2633,0xE06F8B,0x493C2B,0xA46422,0xEB8931,0xF7E26B,0x2F484E,0x44891A,0xA3CE27,0x1B2632,0x005784,0x31A2F2,0xB2DCEF,], // 0:[0x9D9D9D,0xFFFFFF,0xBE2633,0xE06F8B,0x493C2B,0xA46422,0xEB8931,0xF7E26B,0x2F484E,0x44891A,0xA3CE27,0x1B2632,0x005784,0x31A2F2,0xB2DCEF,],
// https://lospec.com/palette-list/gothic-bit // https://lospec.com/palette-list/gothic-bit
1: [ 'gothic-bit': [
0x0e0e12, 0x0e0e12,
0x1a1a24, 0x1a1a24,
0x333346, 0x333346,
...@@ -18,7 +18,7 @@ class ColorTheme { ...@@ -18,7 +18,7 @@ class ColorTheme {
], ],
// https://lospec.com/palette-list/sweethope // https://lospec.com/palette-list/sweethope
2: [ 'sweethope': [
0x615e85, 0x615e85,
0x9c8dc2, 0x9c8dc2,
0xd9a3cd, 0xd9a3cd,
...@@ -30,7 +30,7 @@ class ColorTheme { ...@@ -30,7 +30,7 @@ class ColorTheme {
], ],
// https://lospec.com/palette-list/nostalgic-dreams // https://lospec.com/palette-list/nostalgic-dreams
3: [ 'nostalgic-dreams': [
0xd9af80, 0xd9af80,
0xb07972, 0xb07972,
0x524352, 0x524352,
...@@ -42,7 +42,7 @@ class ColorTheme { ...@@ -42,7 +42,7 @@ class ColorTheme {
], ],
// https://lospec.com/palette-list/arjibi8 // https://lospec.com/palette-list/arjibi8
4: [ 'arjibi8': [
0x8bc7bf, 0x8bc7bf,
0x5796a1, 0x5796a1,
0x524bb3, 0x524bb3,
...@@ -71,9 +71,9 @@ class ColorTheme { ...@@ -71,9 +71,9 @@ class ColorTheme {
static int defaultItemColor = 0x808080; static int defaultItemColor = 0x808080;
static int getColorsCount(final int skin) { static int getColorsCount(String colorsTheme) {
if (itemColors.containsKey(skin) && null != itemColors[skin]) { if (itemColors.containsKey(colorsTheme) && null != itemColors[colorsTheme]) {
List<int> skinColors = itemColors[skin] ?? []; List<int> skinColors = itemColors[colorsTheme] ?? [];
return skinColors.length; return skinColors.length;
} }
...@@ -81,16 +81,18 @@ class ColorTheme { ...@@ -81,16 +81,18 @@ class ColorTheme {
return 0; return 0;
} }
static int getColorCode(int? value, final int skin) { static int getColorCode(int? value, String colorsTheme) {
if (value != null && itemColors.containsKey(skin) && null != itemColors[skin]) { if (value != null &&
List<int> skinColors = itemColors[skin] ?? []; itemColors.containsKey(colorsTheme) &&
return (skinColors[value % getColorsCount(skin)]) | 0xFF000000; null != itemColors[colorsTheme]) {
List<int> skinColors = itemColors[colorsTheme] ?? [];
return (skinColors[value % getColorsCount(colorsTheme)]) | 0xFF000000;
} }
return defaultItemColor | 0xFF000000; return defaultItemColor | 0xFF000000;
} }
static Color getColor(int? value, final int skin) { static Color getColor(int? value, String colorsTheme) {
return Color(getColorCode(value, skin)); return Color(getColorCode(value, colorsTheme));
} }
static Color getBorderColor() { static Color getBorderColor() {
......
import 'package:jeweled/utils/tools.dart'; import 'package:jeweled/utils/tools.dart';
class DefaultGameSettings { class DefaultGameSettings {
// available game parameters codes
static const String parameterCodeBoardSize = 'boardSize';
static const String parameterCodeColorsCount = 'colorsCount';
static const List<String> availableParameters = [ static const List<String> availableParameters = [
'boardSize', parameterCodeBoardSize,
'colorsCount', parameterCodeColorsCount,
]; ];
static const int boardSizeValueSmall = 6; // board size: available values
static const int boardSizeValueMedium = 10; static const String boardSizeValueSmall = '6';
static const int boardSizeValueLarge = 14; static const String boardSizeValueMedium = '10';
static const int boardSizeValueExtraLarge = 18; static const String boardSizeValueLarge = '14';
static const String boardSizeValueExtraLarge = '18';
static const int defaultBoardSizeValue = boardSizeValueMedium; static const List<String> allowedBoardSizeValues = [
static const List<int> allowedBoardSizeValues = [
boardSizeValueSmall, boardSizeValueSmall,
boardSizeValueMedium, boardSizeValueMedium,
boardSizeValueLarge, boardSizeValueLarge,
boardSizeValueExtraLarge, boardSizeValueExtraLarge,
]; ];
// board size: default value
static const int colorsCountValueLow = 5; static const String defaultBoardSizeValue = boardSizeValueMedium;
static const int colorsCountValueMedium = 6;
static const int colorsCountValueHigh = 7; // colors count: available values
static const int colorsCountValueVeryHigh = 8; static const String colorsCountValueLow = '5';
static const String colorsCountValueMedium = '6';
static const int defaultColorsCountValue = colorsCountValueMedium; static const String colorsCountValueHigh = '7';
static const List<int> allowedColorsCountValues = [ static const String colorsCountValueVeryHigh = '8';
static const List<String> allowedColorsCountValues = [
colorsCountValueLow, colorsCountValueLow,
colorsCountValueMedium, colorsCountValueMedium,
colorsCountValueHigh, colorsCountValueHigh,
colorsCountValueVeryHigh, colorsCountValueVeryHigh,
]; ];
// colors count: default value
static const String defaultColorsCountValue = colorsCountValueMedium;
static List<int> getAvailableValues(String parameterCode) { // available values from parameter code
static List<String> getAvailableValues(String parameterCode) {
switch (parameterCode) { switch (parameterCode) {
case 'boardSize': case parameterCodeBoardSize:
return DefaultGameSettings.allowedBoardSizeValues; return DefaultGameSettings.allowedBoardSizeValues;
case 'colorsCount': case parameterCodeColorsCount:
return DefaultGameSettings.allowedColorsCountValues; return DefaultGameSettings.allowedColorsCountValues;
} }
...@@ -44,5 +50,10 @@ class DefaultGameSettings { ...@@ -44,5 +50,10 @@ class DefaultGameSettings {
return []; return [];
} }
// parameters displayed with assets (instead of painter)
static List<String> displayedWithAssets = [
//
];
static int blockMinimumCellsCount = 3; static int blockMinimumCellsCount = 3;
} }
import 'package:jeweled/utils/tools.dart'; import 'package:jeweled/utils/tools.dart';
class DefaultGlobalSettings { class DefaultGlobalSettings {
// available global parameters codes
static const String parameterCodeColorsTheme = 'colorsTheme';
static const String parameterCodeGraphicsTheme = 'graphicTheme';
static const List<String> availableParameters = [ static const List<String> availableParameters = [
'colorsTheme', parameterCodeColorsTheme,
'graphicTheme', parameterCodeGraphicsTheme,
]; ];
static const int defaultColorsThemeValue = 1; static const String colorThemeGothicBit = 'gothic-bit';
static const List<int> allowedColorsThemeValues = [ static const String colorThemeSweethope = 'sweethope';
// 0, // 0x9D9D9D,0xFFFFFF,0xBE2633,0xE06F8B,0x493C2B,0xA46422,0xEB8931,0xF7E26B,0x2F484E,0x44891A,0xA3CE27,0x1B2632,0x005784,0x31A2F2,0xB2DCEF,// legacy static const String colorThemeNostalgicDreams = 'nostalgic-dreams';
1, // 0x0e0e12,0x1a1a24,0x333346,0x535373,0x8080a4,0xa6a6bf,0xc1c1d2,0xe6e6ec, // https://lospec.com/palette-list/gothic-bit static const String colorThemeArjibi8 = 'arjibi8';
2, // 0x615e85,0x9c8dc2,0xd9a3cd,0xebc3a7,0xe0e0dc,0xa3d1af,0x90b4de,0x717fb0, // https://lospec.com/palette-list/sweethope static const String defaultColorsThemeValue = colorThemeSweethope;
3, // 0xd9af80,0xb07972,0x524352,0x686887,0x7f9bb0,0xbfd4b0,0x90b870,0x628c70, // https://lospec.com/palette-list/nostalgic-dreams static const List<String> allowedColorsThemeValues = [
4, // 0x8bc7bf,0x5796a1,0x524bb3,0x471b6e,0x702782,0xb0455a,0xde8b6f,0xebd694, // https://lospec.com/palette-list/arjibi8 colorThemeGothicBit,
// 5, // 0x40263e,0x5979a6,0x84c2a3,0xefe8c3,0xefefef,0xcbc7d6,0xd06060,0x773971, // https://lospec.com/palette-list/kotomasho-8 colorThemeSweethope,
// 6, // 0xf0f0eb,0xffff8f,0x7be098,0x849ad8,0xe8b382,0xd8828e,0xa776c1,0x545155, // https://lospec.com/palette-list/desatur8 colorThemeNostalgicDreams,
// 7, // 0x211d38,0x2e2a4f,0x3b405e,0x60556e,0x9a6278,0xc7786f,0xcfa98a,0xcdd4a5, // https://lospec.com/palette-list/purplemorning8 colorThemeArjibi8,
// 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 const int graphicThemeSolidBackground = 0; static const String graphicThemeSolidBackground = 'SolidBackground';
static const int graphicThemeGradientAndBorder = 1; static const String graphicThemeGradientAndBorder = 'GradientAndBorder';
static const int graphicThemeEmojis = 2; static const String graphicThemeEmojis = 'Emojis';
static const int graphicThemePatterns = 3; static const String graphicThemePatterns = 'Patterns';
static const List<String> allowedGraphicThemeValues = [
static const int defaultGraphicThemeValue = graphicThemeSolidBackground;
static const List<int> allowedGraphicThemeValues = [
graphicThemeSolidBackground, graphicThemeSolidBackground,
graphicThemeGradientAndBorder, graphicThemeGradientAndBorder,
graphicThemeEmojis, graphicThemeEmojis,
graphicThemePatterns, graphicThemePatterns,
]; ];
static const String defaultGraphicThemeValue = graphicThemeSolidBackground;
static const List<String> graphicThemeContentEmojiStrings = [ static const List<String> graphicThemeContentEmojiStrings = [
'🍏', '🍏',
'🤍', '🤍',
...@@ -54,15 +55,21 @@ class DefaultGlobalSettings { ...@@ -54,15 +55,21 @@ class DefaultGlobalSettings {
'⧧', '⧧',
]; ];
static List<int> getAvailableValues(String parameterCode) { // available values from parameter code
static List<String> getAvailableValues(String parameterCode) {
switch (parameterCode) { switch (parameterCode) {
case 'colorsTheme': case parameterCodeColorsTheme:
return DefaultGlobalSettings.allowedColorsThemeValues; return DefaultGlobalSettings.allowedColorsThemeValues;
case 'graphicTheme': case parameterCodeGraphicsTheme:
return DefaultGlobalSettings.allowedGraphicThemeValues; return DefaultGlobalSettings.allowedGraphicThemeValues;
} }
printlog('Did not find any available value for global parameter "$parameterCode".'); printlog('Did not find any available value for global parameter "$parameterCode".');
return []; return [];
} }
// parameters displayed with assets (instead of painter)
static List<String> displayedWithAssets = [
//
];
} }
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:unicons/unicons.dart'; import 'package:unicons/unicons.dart';
import 'package:jeweled/ui/screens/about_page.dart'; import 'package:jeweled/ui/screens/page_game.dart';
import 'package:jeweled/ui/screens/game_page.dart'; import 'package:jeweled/ui/screens/page_settings.dart';
import 'package:jeweled/ui/screens/settings_page.dart'; import 'package:jeweled/ui/screens/page_about.dart';
class MenuItem { class MenuItem {
final String code;
final Icon icon; final Icon icon;
final Widget page; final Widget page;
const MenuItem({ const MenuItem({
required this.code,
required this.icon, required this.icon,
required this.page, required this.page,
}); });
...@@ -20,23 +18,20 @@ class MenuItem { ...@@ -20,23 +18,20 @@ class MenuItem {
class Menu { class Menu {
static const indexGame = 0; static const indexGame = 0;
static const menuItemGame = MenuItem( static const menuItemGame = MenuItem(
code: 'bottom_nav_game',
icon: Icon(UniconsLine.home), icon: Icon(UniconsLine.home),
page: GamePage(), page: PageGame(),
); );
static const indexSettings = 1; static const indexSettings = 1;
static const menuItemSettings = MenuItem( static const menuItemSettings = MenuItem(
code: 'bottom_nav_settings',
icon: Icon(UniconsLine.setting), icon: Icon(UniconsLine.setting),
page: SettingsPage(), page: PageSettings(),
); );
static const indexAbout = 2; static const indexAbout = 2;
static const menuItemAbout = MenuItem( static const menuItemAbout = MenuItem(
code: 'bottom_nav_about',
icon: Icon(UniconsLine.info_circle), icon: Icon(UniconsLine.info_circle),
page: AboutPage(), page: PageAbout(),
); );
static Map<int, MenuItem> items = { static Map<int, MenuItem> items = {
......
...@@ -39,11 +39,9 @@ final ColorScheme lightColorScheme = ColorScheme.light( ...@@ -39,11 +39,9 @@ final ColorScheme lightColorScheme = ColorScheme.light(
secondary: primarySwatch.shade500, secondary: primarySwatch.shade500,
onSecondary: Colors.white, onSecondary: Colors.white,
error: errorColor, error: errorColor,
background: textSwatch.shade200,
onBackground: textSwatch.shade500,
onSurface: textSwatch.shade500, onSurface: textSwatch.shade500,
surface: textSwatch.shade50, surface: textSwatch.shade50,
surfaceVariant: Colors.white, surfaceContainerHighest: Colors.white,
shadow: textSwatch.shade900.withOpacity(.1), shadow: textSwatch.shade900.withOpacity(.1),
); );
...@@ -52,11 +50,9 @@ final ColorScheme darkColorScheme = ColorScheme.dark( ...@@ -52,11 +50,9 @@ final ColorScheme darkColorScheme = ColorScheme.dark(
secondary: primarySwatch.shade500, secondary: primarySwatch.shade500,
onSecondary: Colors.white, onSecondary: Colors.white,
error: errorColor, error: errorColor,
background: const Color(0xFF171724),
onBackground: textSwatch.shade400,
onSurface: textSwatch.shade300, onSurface: textSwatch.shade300,
surface: const Color(0xFF262630), surface: const Color(0xFF262630),
surfaceVariant: const Color(0xFF282832), surfaceContainerHighest: const Color(0xFF282832),
shadow: textSwatch.shade900.withOpacity(.2), shadow: textSwatch.shade900.withOpacity(.2),
); );
...@@ -192,5 +188,3 @@ final ThemeData darkTheme = lightTheme.copyWith( ...@@ -192,5 +188,3 @@ final ThemeData darkTheme = lightTheme.copyWith(
), ),
), ),
); );
final ThemeData appTheme = darkTheme;
...@@ -3,10 +3,10 @@ import 'package:flutter/material.dart'; ...@@ -3,10 +3,10 @@ import 'package:flutter/material.dart';
import 'package:hydrated_bloc/hydrated_bloc.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/game/cell_location.dart';
import 'package:jeweled/models/cell_location.dart'; import 'package:jeweled/models/game/game.dart';
import 'package:jeweled/models/settings_game.dart'; import 'package:jeweled/models/settings/settings_game.dart';
import 'package:jeweled/models/settings_global.dart'; import 'package:jeweled/models/settings/settings_global.dart';
import 'package:jeweled/utils/tools.dart'; import 'package:jeweled/utils/tools.dart';
part 'game_state.dart'; part 'game_state.dart';
...@@ -14,7 +14,7 @@ part 'game_state.dart'; ...@@ -14,7 +14,7 @@ part 'game_state.dart';
class GameCubit extends HydratedCubit<GameState> { class GameCubit extends HydratedCubit<GameState> {
GameCubit() GameCubit()
: super(GameState( : super(GameState(
currentGame: Game.createNull(), currentGame: Game.createEmpty(),
)); ));
void updateState(Game game) { void updateState(Game game) {
...@@ -25,23 +25,55 @@ class GameCubit extends HydratedCubit<GameState> { ...@@ -25,23 +25,55 @@ class GameCubit extends HydratedCubit<GameState> {
void refresh() { void refresh() {
final Game game = Game( final Game game = Game(
board: state.currentGame.board, // Settings
gameSettings: state.currentGame.gameSettings, gameSettings: state.currentGame.gameSettings,
globalSettings: state.currentGame.globalSettings, globalSettings: state.currentGame.globalSettings,
shuffledColors: state.currentGame.shuffledColors, // State
isRunning: state.currentGame.isRunning, isRunning: state.currentGame.isRunning,
isStarted: state.currentGame.isStarted,
isFinished: state.currentGame.isFinished, isFinished: state.currentGame.isFinished,
animationInProgress: state.currentGame.animationInProgress,
// Base data
board: state.currentGame.board,
// Game data
shuffledColors: state.currentGame.shuffledColors,
availableBlocksCount: state.currentGame.availableBlocksCount, availableBlocksCount: state.currentGame.availableBlocksCount,
movesCount: state.currentGame.movesCount,
score: state.currentGame.score, score: state.currentGame.score,
movesCount: state.currentGame.movesCount,
); );
// game.dump(); // game.dump();
updateState(game); updateState(game);
} }
void startNewGame({
required GameSettings gameSettings,
required GlobalSettings globalSettings,
}) {
final Game newGame = Game.createNew(
gameSettings: gameSettings,
globalSettings: globalSettings,
);
newGame.dump();
updateState(newGame);
postAnimate();
}
void quitGame() { void quitGame() {
state.currentGame.updateGameIsRunning(false); state.currentGame.isRunning = false;
refresh();
}
void resumeSavedGame() {
state.currentGame.isRunning = true;
refresh();
}
void deleteSavedGame() {
state.currentGame.isRunning = false;
state.currentGame.isFinished = true;
refresh(); refresh();
} }
...@@ -51,6 +83,7 @@ class GameCubit extends HydratedCubit<GameState> { ...@@ -51,6 +83,7 @@ class GameCubit extends HydratedCubit<GameState> {
} }
void increaseMovesCount() { void increaseMovesCount() {
state.currentGame.isStarted = true;
state.currentGame.increaseMovesCount(); state.currentGame.increaseMovesCount();
refresh(); refresh();
} }
...@@ -66,19 +99,19 @@ class GameCubit extends HydratedCubit<GameState> { ...@@ -66,19 +99,19 @@ class GameCubit extends HydratedCubit<GameState> {
} }
void updateGameIsFinished(bool gameIsFinished) { void updateGameIsFinished(bool gameIsFinished) {
state.currentGame.updateGameIsFinished(gameIsFinished); state.currentGame.isFinished = gameIsFinished;
refresh(); refresh();
} }
void shuffleColors(final int colorsTheme) { void shuffleColors(final String colorsTheme) {
state.currentGame.shuffleColorsAgain(colorsTheme); state.currentGame.shuffleColorsAgain(colorsTheme);
} }
moveCellsDown() { moveCellsDown() {
final Game currentGame = state.currentGame; final Game currentGame = state.currentGame;
final int boardSizeHorizontal = currentGame.gameSettings.boardSize; final int boardSizeHorizontal = currentGame.gameSettings.boardSizeValue;
final int boardSizeVertical = currentGame.gameSettings.boardSize; final int boardSizeVertical = currentGame.gameSettings.boardSizeValue;
for (int row = 0; row < boardSizeVertical; row++) { for (int row = 0; row < boardSizeVertical; row++) {
for (int col = 0; col < boardSizeHorizontal; col++) { for (int col = 0; col < boardSizeHorizontal; col++) {
...@@ -139,24 +172,9 @@ class GameCubit extends HydratedCubit<GameState> { ...@@ -139,24 +172,9 @@ class GameCubit extends HydratedCubit<GameState> {
} }
} }
void startNewGame({
required GameSettings gameSettings,
required GlobalSettings globalSettings,
}) {
Game newGame = Game.createNew(
gameSettings: gameSettings,
globalSettings: globalSettings,
);
newGame.dump();
updateState(newGame);
postAnimate();
}
@override @override
GameState? fromJson(Map<String, dynamic> json) { GameState? fromJson(Map<String, dynamic> json) {
Game currentGame = json['currentGame'] as Game; final Game currentGame = json['currentGame'] as Game;
return GameState( return GameState(
currentGame: currentGame, currentGame: currentGame,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment