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

Merge branch '21-add-colors-theme-selector' into 'master'

Resolve "Add colors theme selector"

Closes #21

See merge request !22
parents 36641f0a f12f4200
No related branches found
No related tags found
1 merge request!22Resolve "Add colors theme selector"
Pipeline #4973 passed
org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
app.versionName=0.0.19
app.versionCode=19
app.versionName=0.0.20
app.versionCode=20
Add colors theme selector in parameters.
Ajout de la sélection du thème de couleurs.
......@@ -2,6 +2,7 @@ class DefaultGameSettings {
static const List<String> availableParameters = [
'boardSize',
'colorsCount',
'colorsTheme',
];
static const int boardSizeValueSmall = 6;
......@@ -30,12 +31,28 @@ 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 [];
......
......@@ -67,8 +67,8 @@ class GameCubit extends HydratedCubit<GameState> {
refresh();
}
void shuffleColors() {
this.state.currentGame.shuffleColorsAgain();
void shuffleColors(final int colorsTheme) {
this.state.currentGame.shuffleColorsAgain(colorsTheme);
}
moveCellsDown() {
......
......@@ -12,12 +12,14 @@ class SettingsCubit extends HydratedCubit<SettingsState> {
void setValues({
int? boardSize,
int? colorsCount,
int? colorsTheme,
}) {
emit(
SettingsState(
settings: GameSettings(
boardSize: boardSize ?? state.settings.boardSize,
colorsCount: colorsCount ?? state.settings.colorsCount,
colorsTheme: colorsTheme ?? state.settings.colorsTheme,
),
),
);
......@@ -29,6 +31,8 @@ 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;
}
......@@ -39,10 +43,12 @@ class SettingsCubit extends HydratedCubit<SettingsState> {
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,
);
}
......@@ -50,11 +56,13 @@ class SettingsCubit extends HydratedCubit<SettingsState> {
SettingsState? 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(
settings: GameSettings(
boardSize: boardSize,
colorsCount: colorsCount,
colorsTheme: colorsTheme,
),
);
}
......@@ -64,6 +72,7 @@ class SettingsCubit extends HydratedCubit<SettingsState> {
return <String, dynamic>{
'boardSize': state.settings.boardSize,
'colorsCount': state.settings.colorsCount,
'colorsTheme': state.settings.colorsTheme,
};
}
}
import 'dart:math';
import 'package:jeweled/config/default_game_settings.dart';
import 'package:jeweled/models/game_board.dart';
import 'package:jeweled/models/game_cell.dart';
import 'package:jeweled/models/cell_location.dart';
......@@ -31,7 +32,7 @@ class Game {
return Game(
board: GameBoard.createNull(),
settings: GameSettings.createDefault(),
shuffledColors: shuffleColors(),
shuffledColors: shuffleColors(DefaultGameSettings.defaultColorsThemeValue),
);
}
......@@ -41,20 +42,21 @@ class Game {
return Game(
board: GameBoard.createRandom(settings),
settings: settings,
shuffledColors: shuffleColors(),
shuffledColors: shuffleColors(settings.colorsTheme),
isRunning: true,
);
}
static List<int> shuffleColors() {
List<int> values = new List<int>.generate(ColorTheme.getColorsCount(), (i) => i + 1);
static List<int> shuffleColors(final int colorsTheme) {
List<int> values =
new List<int>.generate(ColorTheme.getColorsCount(colorsTheme), (i) => i + 1);
values.shuffle();
return values;
}
void shuffleColorsAgain() {
this.shuffledColors = shuffleColors();
void shuffleColorsAgain(final int colorsTheme) {
this.shuffledColors = shuffleColors(colorsTheme);
}
GameCell getCell(CellLocation cellLocation) {
......
......@@ -3,10 +3,12 @@ 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) {
......@@ -25,10 +27,19 @@ 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,
);
}
......@@ -36,6 +47,7 @@ class GameSettings {
print('Settings: ');
print(' boardSize: ' + boardSize.toString());
print(' colorsCount: ' + colorsCount.toString());
print(' colorsTheme: ' + colorsTheme.toString());
}
String toString() {
......@@ -46,6 +58,7 @@ class GameSettings {
return <String, dynamic>{
'boardSize': this.boardSize,
'colorsCount': this.colorsCount,
'colorsTheme': this.colorsTheme,
};
}
}
......@@ -33,7 +33,7 @@ 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);
final int colorCode = ColorTheme.getColorCode(cellValue, game.settings.colorsTheme);
final Animation<double>? translation = this.animations[row][col];
final double y = yOrigin + (translation?.value ?? 0) * cellSize;
......
......@@ -3,6 +3,7 @@ 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/utils/color_extensions.dart';
import 'package:jeweled/utils/color_theme.dart';
......@@ -11,11 +12,13 @@ class ParameterPainter extends CustomPainter {
required this.code,
required this.value,
required this.isSelected,
required this.gameSettings,
});
final String code;
final int value;
final bool isSelected;
final GameSettings gameSettings;
@override
void paint(Canvas canvas, Size size) {
......@@ -41,6 +44,9 @@ class ParameterPainter extends CustomPainter {
case 'boardSize':
paintBoardSizeParameterItem(value, canvas, canvasSize);
break;
case 'colorsTheme':
paintColorsThemeParameterItem(value, canvas, canvasSize);
break;
default:
print('Unknown parameter: ' + code + '/' + value.toString());
paintUnknownParameterItem(value, canvas, canvasSize);
......@@ -121,7 +127,8 @@ class ParameterPainter extends CustomPainter {
final Offset topLeft = Offset(origin + col * cellSize, origin + row * cellSize);
final Offset bottomRight = topLeft + Offset(cellSize, cellSize);
final squareColor = Color(ColorTheme.getColorCode(col + row * gridWidth));
final squareColor =
Color(ColorTheme.getColorCode(col + row * gridWidth, gameSettings.colorsTheme));
paint.color = squareColor;
paint.style = PaintingStyle.fill;
......@@ -187,7 +194,7 @@ class ParameterPainter extends CustomPainter {
final Offset bottomRight = topLeft + Offset(width, width);
final squareColor = Color(ColorTheme.getColorCode(colorIndex));
final squareColor = Color(ColorTheme.getColorCode(colorIndex, gameSettings.colorsTheme));
paint.color = squareColor;
paint.style = PaintingStyle.fill;
canvas.drawRect(Rect.fromPoints(topLeft, bottomRight), paint);
......@@ -220,4 +227,41 @@ class ParameterPainter extends CustomPainter {
),
);
}
void paintColorsThemeParameterItem(final int value, final Canvas canvas, final double size) {
Color backgroundColor = Colors.grey;
const int gridWidth = 4;
final paint = Paint();
paint.strokeJoin = StrokeJoin.round;
paint.strokeWidth = 3 / 100 * size;
// Colored background
paint.color = backgroundColor;
paint.style = PaintingStyle.fill;
canvas.drawRect(Rect.fromPoints(Offset(0, 0), Offset(size, size)), paint);
// Mini grid
final borderColor = Colors.grey.shade800;
final double cellSize = size / gridWidth;
final double origin = (size - gridWidth * cellSize) / 2;
for (int row = 0; row < gridWidth; row++) {
for (int col = 0; col < gridWidth; col++) {
final Offset topLeft = Offset(origin + col * cellSize, origin + row * cellSize);
final Offset bottomRight = topLeft + Offset(cellSize, cellSize);
final squareColor = Color(ColorTheme.getColorCode(col + row * gridWidth, value));
paint.color = squareColor;
paint.style = PaintingStyle.fill;
canvas.drawRect(Rect.fromPoints(topLeft, bottomRight), paint);
paint.color = borderColor;
paint.style = PaintingStyle.stroke;
canvas.drawRect(Rect.fromPoints(topLeft, bottomRight), paint);
}
}
}
}
......@@ -60,7 +60,7 @@ class GameTopIndicatorWidget extends StatelessWidget {
child: Icon(UniconsSolid.refresh),
onPressed: () {
final GameCubit gameCubit = BlocProvider.of<GameCubit>(context);
gameCubit.shuffleColors();
gameCubit.shuffleColors(currentGame.settings.colorsTheme);
},
)
],
......
......@@ -49,6 +49,7 @@ class Parameters extends StatelessWidget {
code: code,
value: value,
isSelected: isActive,
gameSettings: settingsState.settings,
),
isComplex: true,
),
......
import 'package:flutter/material.dart';
class ColorTheme {
static Map<String, List<int>> itemColors = {
'default': [
0x000000,
0x9D9D9D,
0xFFFFFF,
0xBE2633,
0xE06F8B,
0x493C2B,
0xA46422,
0xEB8931,
0xF7E26B,
0x2F484E,
0x44891A,
0xA3CE27,
0x1B2632,
0x005784,
0x31A2F2,
0xB2DCEF,
static Map<int, 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: [
0x0e0e12,
0x1a1a24,
0x333346,
0x535373,
0x8080a4,
0xa6a6bf,
0xc1c1d2,
0xe6e6ec,
],
// https://lospec.com/palette-list/sweethope
2: [
0x615e85,
0x9c8dc2,
0xd9a3cd,
0xebc3a7,
0xe0e0dc,
0xa3d1af,
0x90b4de,
0x717fb0,
],
// https://lospec.com/palette-list/nostalgic-dreams
3: [
0xd9af80,
0xb07972,
0x524352,
0x686887,
0x7f9bb0,
0xbfd4b0,
0x90b870,
0x628c70,
],
// https://lospec.com/palette-list/arjibi8
4: [
0x8bc7bf,
0x5796a1,
0x524bb3,
0x471b6e,
0x702782,
0xb0455a,
0xde8b6f,
0xebd694,
],
// https://lospec.com/palette-list/kotomasho-8
// 5:[0x40263e,0x5979a6,0x84c2a3,0xefe8c3,0xefefef,0xcbc7d6,0xd06060,0x773971,],
// https://lospec.com/palette-list/desatur8
// 6:[0xf0f0eb,0xffff8f,0x7be098,0x849ad8,0xe8b382,0xd8828e,0xa776c1,0x545155,],
// https://lospec.com/palette-list/purplemorning8
// 7:[0x211d38,0x2e2a4f,0x3b405e,0x60556e,0x9a6278,0xc7786f,0xcfa98a,0xcdd4a5,],
// https://lospec.com/palette-list/cold-war-8
// 8:[0x332422,0xc95b40,0xff9b5e,0xfcdf76,0x4c2f7f,0x3a66ad,0x39cec2,0xfafff9,],
// https://lospec.com/palette-list/low-8
// 9:[0x111323,0x374566,0x50785d,0x8497b3,0xe8dcd8,0xcfb463,0xb35447,0x692e4b,],
};
static int defaultItemColor = 0x808080;
static int getColorsCount() {
const skin = 'default';
static int defaultItemColor = 0x808080;
static int getColorsCount(final int skin) {
if (itemColors.containsKey(skin) && null != itemColors[skin]) {
List<int> skinColors = itemColors[skin] ?? [];
......@@ -35,12 +81,10 @@ class ColorTheme {
return 0;
}
static int getColorCode(int? value) {
const skin = 'default';
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()]) | 0xFF000000;
return (skinColors[value % getColorsCount(skin)]) | 0xFF000000;
}
return defaultItemColor | 0xFF000000;
}
......
......@@ -3,7 +3,7 @@ description: Jeweled Game
publish_to: 'none'
version: 0.0.19+19
version: 0.0.20+20
environment:
sdk: '^3.0.0'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment