Select Git revision
nav_cubit.dart
-
Benoît Harrault authoredBenoît Harrault authored
game_settings.dart 1.66 KiB
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) {
if (DefaultGameSettings.allowedBoardSizeValues.contains(size)) {
return size;
}
return DefaultGameSettings.defaultBoardSizeValue;
}
static int getColorsCountValueFromUnsafe(int colorsCount) {
if (DefaultGameSettings.allowedColorsCountValues.contains(colorsCount)) {
return colorsCount;
}
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,
);
}
void dump() {
print('Settings: ');
print(' boardSize: ' + boardSize.toString());
print(' colorsCount: ' + colorsCount.toString());
print(' colorsTheme: ' + colorsTheme.toString());
}
String toString() {
return 'GameSettings(' + this.toJson().toString() + ')';
}
Map<String, dynamic>? toJson() {
return <String, dynamic>{
'boardSize': this.boardSize,
'colorsCount': this.colorsCount,
'colorsTheme': this.colorsTheme,
};
}
}