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
android.useAndroidX=true
android.enableJetifier=true
app.versionName=0.0.31
app.versionCode=31
app.versionName=0.1.0
app.versionCode=32
{
"app_name": "Jeweled",
"bottom_nav_game": "Game",
"bottom_nav_settings": "Settings",
"bottom_nav_about": "About",
"settings_title": "Settings",
"settings_label_theme": "Theme mode",
"about_title": "About",
"about_content": "Simple and classic Jeweled game.",
"about_version": "Version: {version}"
"about_version": "Version: {version}",
"": ""
}
{
"app_name": "Jeweled",
"bottom_nav_game": "Jeu",
"bottom_nav_settings": "Réglages",
"bottom_nav_about": "Infos",
"settings_title": "Réglages",
"settings_label_theme": "Thème de couleurs",
"about_title": "Informations",
"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';
class ColorTheme {
static Map<int, List<int>> itemColors = {
static Map<String, List<int>> itemColors = {
// legacy
// 0:[0x9D9D9D,0xFFFFFF,0xBE2633,0xE06F8B,0x493C2B,0xA46422,0xEB8931,0xF7E26B,0x2F484E,0x44891A,0xA3CE27,0x1B2632,0x005784,0x31A2F2,0xB2DCEF,],
// https://lospec.com/palette-list/gothic-bit
1: [
'gothic-bit': [
0x0e0e12,
0x1a1a24,
0x333346,
......@@ -18,7 +18,7 @@ class ColorTheme {
],
// https://lospec.com/palette-list/sweethope
2: [
'sweethope': [
0x615e85,
0x9c8dc2,
0xd9a3cd,
......@@ -30,7 +30,7 @@ class ColorTheme {
],
// https://lospec.com/palette-list/nostalgic-dreams
3: [
'nostalgic-dreams': [
0xd9af80,
0xb07972,
0x524352,
......@@ -42,7 +42,7 @@ class ColorTheme {
],
// https://lospec.com/palette-list/arjibi8
4: [
'arjibi8': [
0x8bc7bf,
0x5796a1,
0x524bb3,
......@@ -71,9 +71,9 @@ class ColorTheme {
static int defaultItemColor = 0x808080;
static int getColorsCount(final int skin) {
if (itemColors.containsKey(skin) && null != itemColors[skin]) {
List<int> skinColors = itemColors[skin] ?? [];
static int getColorsCount(String colorsTheme) {
if (itemColors.containsKey(colorsTheme) && null != itemColors[colorsTheme]) {
List<int> skinColors = itemColors[colorsTheme] ?? [];
return skinColors.length;
}
......@@ -81,16 +81,18 @@ class ColorTheme {
return 0;
}
static int getColorCode(int? value, final int skin) {
if (value != null && itemColors.containsKey(skin) && null != itemColors[skin]) {
List<int> skinColors = itemColors[skin] ?? [];
return (skinColors[value % getColorsCount(skin)]) | 0xFF000000;
static int getColorCode(int? value, String colorsTheme) {
if (value != null &&
itemColors.containsKey(colorsTheme) &&
null != itemColors[colorsTheme]) {
List<int> skinColors = itemColors[colorsTheme] ?? [];
return (skinColors[value % getColorsCount(colorsTheme)]) | 0xFF000000;
}
return defaultItemColor | 0xFF000000;
}
static Color getColor(int? value, final int skin) {
return Color(getColorCode(value, skin));
static Color getColor(int? value, String colorsTheme) {
return Color(getColorCode(value, colorsTheme));
}
static Color getBorderColor() {
......
import 'package:jeweled/utils/tools.dart';
class DefaultGameSettings {
// available game parameters codes
static const String parameterCodeBoardSize = 'boardSize';
static const String parameterCodeColorsCount = 'colorsCount';
static const List<String> availableParameters = [
'boardSize',
'colorsCount',
parameterCodeBoardSize,
parameterCodeColorsCount,
];
static const int boardSizeValueSmall = 6;
static const int boardSizeValueMedium = 10;
static const int boardSizeValueLarge = 14;
static const int boardSizeValueExtraLarge = 18;
static const int defaultBoardSizeValue = boardSizeValueMedium;
static const List<int> allowedBoardSizeValues = [
// board size: available values
static const String boardSizeValueSmall = '6';
static const String boardSizeValueMedium = '10';
static const String boardSizeValueLarge = '14';
static const String boardSizeValueExtraLarge = '18';
static const List<String> allowedBoardSizeValues = [
boardSizeValueSmall,
boardSizeValueMedium,
boardSizeValueLarge,
boardSizeValueExtraLarge,
];
static const int colorsCountValueLow = 5;
static const int colorsCountValueMedium = 6;
static const int colorsCountValueHigh = 7;
static const int colorsCountValueVeryHigh = 8;
static const int defaultColorsCountValue = colorsCountValueMedium;
static const List<int> allowedColorsCountValues = [
// board size: default value
static const String defaultBoardSizeValue = boardSizeValueMedium;
// colors count: available values
static const String colorsCountValueLow = '5';
static const String colorsCountValueMedium = '6';
static const String colorsCountValueHigh = '7';
static const String colorsCountValueVeryHigh = '8';
static const List<String> allowedColorsCountValues = [
colorsCountValueLow,
colorsCountValueMedium,
colorsCountValueHigh,
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) {
case 'boardSize':
case parameterCodeBoardSize:
return DefaultGameSettings.allowedBoardSizeValues;
case 'colorsCount':
case parameterCodeColorsCount:
return DefaultGameSettings.allowedColorsCountValues;
}
......@@ -44,5 +50,10 @@ class DefaultGameSettings {
return [];
}
// parameters displayed with assets (instead of painter)
static List<String> displayedWithAssets = [
//
];
static int blockMinimumCellsCount = 3;
}
import 'package:jeweled/utils/tools.dart';
class DefaultGlobalSettings {
// available global parameters codes
static const String parameterCodeColorsTheme = 'colorsTheme';
static const String parameterCodeGraphicsTheme = 'graphicTheme';
static const List<String> availableParameters = [
'colorsTheme',
'graphicTheme',
parameterCodeColorsTheme,
parameterCodeGraphicsTheme,
];
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 const String colorThemeGothicBit = 'gothic-bit';
static const String colorThemeSweethope = 'sweethope';
static const String colorThemeNostalgicDreams = 'nostalgic-dreams';
static const String colorThemeArjibi8 = 'arjibi8';
static const String defaultColorsThemeValue = colorThemeSweethope;
static const List<String> allowedColorsThemeValues = [
colorThemeGothicBit,
colorThemeSweethope,
colorThemeNostalgicDreams,
colorThemeArjibi8,
];
static const int graphicThemeSolidBackground = 0;
static const int graphicThemeGradientAndBorder = 1;
static const int graphicThemeEmojis = 2;
static const int graphicThemePatterns = 3;
static const int defaultGraphicThemeValue = graphicThemeSolidBackground;
static const List<int> allowedGraphicThemeValues = [
static const String graphicThemeSolidBackground = 'SolidBackground';
static const String graphicThemeGradientAndBorder = 'GradientAndBorder';
static const String graphicThemeEmojis = 'Emojis';
static const String graphicThemePatterns = 'Patterns';
static const List<String> allowedGraphicThemeValues = [
graphicThemeSolidBackground,
graphicThemeGradientAndBorder,
graphicThemeEmojis,
graphicThemePatterns,
];
static const String defaultGraphicThemeValue = graphicThemeSolidBackground;
static const List<String> graphicThemeContentEmojiStrings = [
'🍏',
'🤍',
......@@ -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) {
case 'colorsTheme':
case parameterCodeColorsTheme:
return DefaultGlobalSettings.allowedColorsThemeValues;
case 'graphicTheme':
case parameterCodeGraphicsTheme:
return DefaultGlobalSettings.allowedGraphicThemeValues;
}
printlog('Did not find any available value for global parameter "$parameterCode".');
return [];
}
// parameters displayed with assets (instead of painter)
static List<String> displayedWithAssets = [
//
];
}
import 'package:flutter/material.dart';
import 'package:unicons/unicons.dart';
import 'package:jeweled/ui/screens/about_page.dart';
import 'package:jeweled/ui/screens/game_page.dart';
import 'package:jeweled/ui/screens/settings_page.dart';
import 'package:jeweled/ui/screens/page_game.dart';
import 'package:jeweled/ui/screens/page_settings.dart';
import 'package:jeweled/ui/screens/page_about.dart';
class MenuItem {
final String code;
final Icon icon;
final Widget page;
const MenuItem({
required this.code,
required this.icon,
required this.page,
});
......@@ -20,23 +18,20 @@ class MenuItem {
class Menu {
static const indexGame = 0;
static const menuItemGame = MenuItem(
code: 'bottom_nav_game',
icon: Icon(UniconsLine.home),
page: GamePage(),
page: PageGame(),
);
static const indexSettings = 1;
static const menuItemSettings = MenuItem(
code: 'bottom_nav_settings',
icon: Icon(UniconsLine.setting),
page: SettingsPage(),
page: PageSettings(),
);
static const indexAbout = 2;
static const menuItemAbout = MenuItem(
code: 'bottom_nav_about',
icon: Icon(UniconsLine.info_circle),
page: AboutPage(),
page: PageAbout(),
);
static Map<int, MenuItem> items = {
......
......@@ -39,11 +39,9 @@ final ColorScheme lightColorScheme = ColorScheme.light(
secondary: primarySwatch.shade500,
onSecondary: Colors.white,
error: errorColor,
background: textSwatch.shade200,
onBackground: textSwatch.shade500,
onSurface: textSwatch.shade500,
surface: textSwatch.shade50,
surfaceVariant: Colors.white,
surfaceContainerHighest: Colors.white,
shadow: textSwatch.shade900.withOpacity(.1),
);
......@@ -52,11 +50,9 @@ final ColorScheme darkColorScheme = ColorScheme.dark(
secondary: primarySwatch.shade500,
onSecondary: Colors.white,
error: errorColor,
background: const Color(0xFF171724),
onBackground: textSwatch.shade400,
onSurface: textSwatch.shade300,
surface: const Color(0xFF262630),
surfaceVariant: const Color(0xFF282832),
surfaceContainerHighest: const Color(0xFF282832),
shadow: textSwatch.shade900.withOpacity(.2),
);
......@@ -192,5 +188,3 @@ final ThemeData darkTheme = lightTheme.copyWith(
),
),
);
final ThemeData appTheme = darkTheme;
......@@ -3,10 +3,10 @@ import 'package:flutter/material.dart';
import 'package:hydrated_bloc/hydrated_bloc.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/settings_game.dart';
import 'package:jeweled/models/settings_global.dart';
import 'package:jeweled/models/game/cell_location.dart';
import 'package:jeweled/models/game/game.dart';
import 'package:jeweled/models/settings/settings_game.dart';
import 'package:jeweled/models/settings/settings_global.dart';
import 'package:jeweled/utils/tools.dart';
part 'game_state.dart';
......@@ -14,7 +14,7 @@ part 'game_state.dart';
class GameCubit extends HydratedCubit<GameState> {
GameCubit()
: super(GameState(
currentGame: Game.createNull(),
currentGame: Game.createEmpty(),
));
void updateState(Game game) {
......@@ -25,23 +25,55 @@ class GameCubit extends HydratedCubit<GameState> {
void refresh() {
final Game game = Game(
board: state.currentGame.board,
// Settings
gameSettings: state.currentGame.gameSettings,
globalSettings: state.currentGame.globalSettings,
shuffledColors: state.currentGame.shuffledColors,
// State
isRunning: state.currentGame.isRunning,
isStarted: state.currentGame.isStarted,
isFinished: state.currentGame.isFinished,
animationInProgress: state.currentGame.animationInProgress,
// Base data
board: state.currentGame.board,
// Game data
shuffledColors: state.currentGame.shuffledColors,
availableBlocksCount: state.currentGame.availableBlocksCount,
movesCount: state.currentGame.movesCount,
score: state.currentGame.score,
movesCount: state.currentGame.movesCount,
);
// game.dump();
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() {
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();
}
......@@ -51,6 +83,7 @@ class GameCubit extends HydratedCubit<GameState> {
}
void increaseMovesCount() {
state.currentGame.isStarted = true;
state.currentGame.increaseMovesCount();
refresh();
}
......@@ -66,19 +99,19 @@ class GameCubit extends HydratedCubit<GameState> {
}
void updateGameIsFinished(bool gameIsFinished) {
state.currentGame.updateGameIsFinished(gameIsFinished);
state.currentGame.isFinished = gameIsFinished;
refresh();
}
void shuffleColors(final int colorsTheme) {
void shuffleColors(final String colorsTheme) {
state.currentGame.shuffleColorsAgain(colorsTheme);
}
moveCellsDown() {
final Game currentGame = state.currentGame;
final int boardSizeHorizontal = currentGame.gameSettings.boardSize;
final int boardSizeVertical = currentGame.gameSettings.boardSize;
final int boardSizeHorizontal = currentGame.gameSettings.boardSizeValue;
final int boardSizeVertical = currentGame.gameSettings.boardSizeValue;
for (int row = 0; row < boardSizeVertical; row++) {
for (int col = 0; col < boardSizeHorizontal; col++) {
......@@ -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
GameState? fromJson(Map<String, dynamic> json) {
Game currentGame = json['currentGame'] as Game;
final Game currentGame = json['currentGame'] as Game;
return GameState(
currentGame: currentGame,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment