Changed the overall return type for gamemodes
This commit is contained in:
@@ -4,6 +4,7 @@ import 'package:cabo_counter/data/game_session.dart';
|
||||
import 'package:cabo_counter/l10n/generated/app_localizations.dart';
|
||||
import 'package:cabo_counter/presentation/views/create_game_view.dart';
|
||||
import 'package:cabo_counter/presentation/views/graph_view.dart';
|
||||
import 'package:cabo_counter/presentation/views/mode_selection_view.dart';
|
||||
import 'package:cabo_counter/presentation/views/points_view.dart';
|
||||
import 'package:cabo_counter/presentation/views/round_view.dart';
|
||||
import 'package:cabo_counter/services/local_storage_service.dart';
|
||||
@@ -205,9 +206,11 @@ class _ActiveGameViewState extends State<ActiveGameView> {
|
||||
CupertinoPageRoute(
|
||||
builder: (_) => CreateGameView(
|
||||
gameTitle: gameSession.gameTitle,
|
||||
isPointsLimitEnabled: widget
|
||||
.gameSession
|
||||
.isPointsLimitEnabled,
|
||||
gameMode: widget.gameSession
|
||||
.isPointsLimitEnabled ==
|
||||
true
|
||||
? GameMode.pointLimit
|
||||
: GameMode.unlimited,
|
||||
players: gameSession.players,
|
||||
)));
|
||||
},
|
||||
|
||||
@@ -16,15 +16,15 @@ enum CreateStatus {
|
||||
}
|
||||
|
||||
class CreateGameView extends StatefulWidget {
|
||||
final GameMode gameMode;
|
||||
final String? gameTitle;
|
||||
final bool? isPointsLimitEnabled;
|
||||
final List<String>? players;
|
||||
|
||||
const CreateGameView({
|
||||
super.key,
|
||||
this.gameTitle,
|
||||
this.isPointsLimitEnabled,
|
||||
this.players,
|
||||
required this.gameMode,
|
||||
});
|
||||
|
||||
@override
|
||||
@@ -42,19 +42,15 @@ class _CreateGameViewState extends State<CreateGameView> {
|
||||
/// Maximum number of players allowed in the game.
|
||||
final int maxPlayers = 5;
|
||||
|
||||
/// Variable to store whether the points limit feature is enabled.
|
||||
bool? _isPointsLimitEnabled;
|
||||
/// Variable to hold the selected game mode.
|
||||
late GameMode gameMode;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
if (widget.isPointsLimitEnabled == null) {
|
||||
_isPointsLimitEnabled =
|
||||
ConfigService.gameMode == -1 ? null : ConfigService.gameMode == 1;
|
||||
} else {
|
||||
_isPointsLimitEnabled = widget.isPointsLimitEnabled;
|
||||
}
|
||||
gameMode = widget.gameMode;
|
||||
print('Game mode: $gameMode');
|
||||
|
||||
_gameTitleTextController.text = widget.gameTitle ?? '';
|
||||
|
||||
@@ -106,10 +102,10 @@ class _CreateGameViewState extends State<CreateGameView> {
|
||||
suffix: Row(
|
||||
children: [
|
||||
Text(
|
||||
_isPointsLimitEnabled == null
|
||||
? AppLocalizations.of(context).select_mode
|
||||
: (_isPointsLimitEnabled!
|
||||
? '${ConfigService.pointLimit} ${AppLocalizations.of(context).points}'
|
||||
gameMode == GameMode.none
|
||||
? AppLocalizations.of(context).no_mode_selected
|
||||
: (gameMode == GameMode.pointLimit
|
||||
? '${ConfigService.getPointLimit()} ${AppLocalizations.of(context).points}'
|
||||
: AppLocalizations.of(context).unlimited),
|
||||
),
|
||||
const SizedBox(width: 3),
|
||||
@@ -121,29 +117,15 @@ class _CreateGameViewState extends State<CreateGameView> {
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => ModeSelectionMenu(
|
||||
pointLimit: ConfigService.pointLimit,
|
||||
pointLimit: ConfigService.getPointLimit(),
|
||||
showDeselection: false,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
switch (selectedMode) {
|
||||
case GameMode.pointLimit:
|
||||
setState(() {
|
||||
_isPointsLimitEnabled = true;
|
||||
});
|
||||
break;
|
||||
case GameMode.unlimited:
|
||||
setState(() {
|
||||
_isPointsLimitEnabled = false;
|
||||
});
|
||||
break;
|
||||
case GameMode.none:
|
||||
default:
|
||||
setState(() {
|
||||
_isPointsLimitEnabled = null;
|
||||
});
|
||||
}
|
||||
setState(() {
|
||||
gameMode = selectedMode ?? gameMode;
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
@@ -249,7 +231,7 @@ class _CreateGameViewState extends State<CreateGameView> {
|
||||
showFeedbackDialog(CreateStatus.noGameTitle);
|
||||
return;
|
||||
}
|
||||
if (_isPointsLimitEnabled == null) {
|
||||
if (gameMode == GameMode.none) {
|
||||
showFeedbackDialog(CreateStatus.noModeSelected);
|
||||
return;
|
||||
}
|
||||
@@ -266,13 +248,16 @@ class _CreateGameViewState extends State<CreateGameView> {
|
||||
for (var controller in _playerNameTextControllers) {
|
||||
players.add(controller.text);
|
||||
}
|
||||
|
||||
bool isPointsLimitEnabled = gameMode == GameMode.pointLimit;
|
||||
|
||||
GameSession gameSession = GameSession(
|
||||
createdAt: DateTime.now(),
|
||||
gameTitle: _gameTitleTextController.text,
|
||||
players: players,
|
||||
pointLimit: ConfigService.pointLimit,
|
||||
caboPenalty: ConfigService.caboPenalty,
|
||||
isPointsLimitEnabled: _isPointsLimitEnabled!,
|
||||
pointLimit: ConfigService.getPointLimit(),
|
||||
caboPenalty: ConfigService.getCaboPenalty(),
|
||||
isPointsLimitEnabled: isPointsLimitEnabled,
|
||||
);
|
||||
final index = await gameManager.addGameSession(gameSession);
|
||||
final session = gameManager.gameList[index];
|
||||
|
||||
@@ -77,7 +77,8 @@ class _MainMenuViewState extends State<MainMenuView> {
|
||||
onPressed: () => Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => const CreateGameView(),
|
||||
builder: (context) => CreateGameView(
|
||||
gameMode: ConfigService.getGameMode()),
|
||||
),
|
||||
),
|
||||
icon: const Icon(CupertinoIcons.add)),
|
||||
@@ -96,8 +97,8 @@ class _MainMenuViewState extends State<MainMenuView> {
|
||||
onTap: () => Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) =>
|
||||
const CreateGameView(),
|
||||
builder: (context) => CreateGameView(
|
||||
gameMode: ConfigService.getGameMode()),
|
||||
),
|
||||
),
|
||||
child: Icon(
|
||||
@@ -216,9 +217,9 @@ class _MainMenuViewState extends State<MainMenuView> {
|
||||
|
||||
/// Translates the game mode boolean into the corresponding String.
|
||||
/// If [pointLimit] is true, it returns '101 Punkte', otherwise it returns 'Unbegrenzt'.
|
||||
String _translateGameMode(bool pointLimit) {
|
||||
if (pointLimit) {
|
||||
return '${ConfigService.pointLimit} ${AppLocalizations.of(context).points}';
|
||||
String _translateGameMode(bool isPointLimitEnabled) {
|
||||
if (isPointLimitEnabled) {
|
||||
return '${ConfigService.getPointLimit()} ${AppLocalizations.of(context).points}';
|
||||
}
|
||||
return AppLocalizations.of(context).unlimited;
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ class SettingsView extends StatefulWidget {
|
||||
class _SettingsViewState extends State<SettingsView> {
|
||||
UniqueKey _stepperKey1 = UniqueKey();
|
||||
UniqueKey _stepperKey2 = UniqueKey();
|
||||
int defaultMode = ConfigService.gameMode;
|
||||
GameMode defaultMode = ConfigService.getGameMode();
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -57,7 +57,7 @@ class _SettingsViewState extends State<SettingsView> {
|
||||
prefixIcon: CupertinoIcons.bolt_fill,
|
||||
suffixWidget: CustomStepper(
|
||||
key: _stepperKey1,
|
||||
initialValue: ConfigService.caboPenalty,
|
||||
initialValue: ConfigService.getCaboPenalty(),
|
||||
minValue: 0,
|
||||
maxValue: 50,
|
||||
step: 1,
|
||||
@@ -73,7 +73,7 @@ class _SettingsViewState extends State<SettingsView> {
|
||||
prefixIcon: FontAwesomeIcons.bullseye,
|
||||
suffixWidget: CustomStepper(
|
||||
key: _stepperKey2,
|
||||
initialValue: ConfigService.pointLimit,
|
||||
initialValue: ConfigService.getPointLimit(),
|
||||
minValue: 30,
|
||||
maxValue: 1000,
|
||||
step: 10,
|
||||
@@ -91,11 +91,10 @@ class _SettingsViewState extends State<SettingsView> {
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
Text(
|
||||
defaultMode == -1
|
||||
? AppLocalizations.of(context)
|
||||
.no_mode_selected
|
||||
: (defaultMode == 1
|
||||
? '${ConfigService.pointLimit} ${AppLocalizations.of(context).points}'
|
||||
defaultMode == GameMode.none
|
||||
? AppLocalizations.of(context).no_default_mode
|
||||
: (defaultMode == GameMode.pointLimit
|
||||
? '${ConfigService.getPointLimit()} ${AppLocalizations.of(context).points}'
|
||||
: AppLocalizations.of(context).unlimited),
|
||||
),
|
||||
const SizedBox(width: 5),
|
||||
@@ -107,29 +106,15 @@ class _SettingsViewState extends State<SettingsView> {
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => ModeSelectionMenu(
|
||||
pointLimit: ConfigService.pointLimit,
|
||||
pointLimit: ConfigService.getPointLimit(),
|
||||
showDeselection: true,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
switch (selectedMode) {
|
||||
case GameMode.pointLimit:
|
||||
setState(() {
|
||||
defaultMode = 1;
|
||||
});
|
||||
break;
|
||||
case GameMode.unlimited:
|
||||
setState(() {
|
||||
defaultMode = 0;
|
||||
});
|
||||
break;
|
||||
case GameMode.none:
|
||||
default:
|
||||
setState(() {
|
||||
defaultMode = -1;
|
||||
});
|
||||
}
|
||||
setState(() {
|
||||
defaultMode = selectedMode ?? GameMode.none;
|
||||
});
|
||||
ConfigService.setGameMode(defaultMode);
|
||||
},
|
||||
),
|
||||
@@ -142,7 +127,7 @@ class _SettingsViewState extends State<SettingsView> {
|
||||
setState(() {
|
||||
_stepperKey1 = UniqueKey();
|
||||
_stepperKey2 = UniqueKey();
|
||||
defaultMode = ConfigService.gameMode;
|
||||
defaultMode = ConfigService.getGameMode();
|
||||
});
|
||||
},
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user