First version of inserting into db
This commit is contained in:
@@ -62,7 +62,7 @@ class _ActiveGameViewState extends State<ActiveGameView> {
|
||||
builder: (context, _) {
|
||||
sortedPlayerIndices = _getSortedPlayerIndices();
|
||||
denseRanks = _calculateDenseRank(
|
||||
gameSession.playerScores, sortedPlayerIndices);
|
||||
gameSession.getPlayerScoresAsList(), sortedPlayerIndices);
|
||||
return CupertinoPageScaffold(
|
||||
navigationBar: CupertinoNavigationBar(
|
||||
previousPageTitle: AppLocalizations.of(context).games,
|
||||
@@ -117,7 +117,7 @@ class _ActiveGameViewState extends State<ActiveGameView> {
|
||||
_getPlacementTextWidget(index),
|
||||
const SizedBox(width: 5),
|
||||
Text(
|
||||
gameSession.players[playerIndex],
|
||||
gameSession.players[playerIndex].name,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.bold),
|
||||
),
|
||||
@@ -127,7 +127,7 @@ class _ActiveGameViewState extends State<ActiveGameView> {
|
||||
children: [
|
||||
const SizedBox(width: 5),
|
||||
Text(
|
||||
'${gameSession.playerScores[playerIndex]} '
|
||||
'${gameSession.getPlayerScoresAsList()[playerIndex]} '
|
||||
'${AppLocalizations.of(context).points}')
|
||||
],
|
||||
),
|
||||
@@ -258,15 +258,14 @@ class _ActiveGameViewState extends State<ActiveGameView> {
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (_) => CreateGameView(
|
||||
gameTitle:
|
||||
gameSession.gameTitle,
|
||||
gameMode: widget.gameSession
|
||||
.isPointsLimitEnabled ==
|
||||
true
|
||||
? GameMode.pointLimit
|
||||
: GameMode.unlimited,
|
||||
players: gameSession.players,
|
||||
)));
|
||||
gameTitle: gameSession.gameTitle,
|
||||
gameMode: widget.gameSession
|
||||
.isPointsLimitEnabled ==
|
||||
true
|
||||
? GameMode.pointLimit
|
||||
: GameMode.unlimited,
|
||||
players: gameSession
|
||||
.getPlayerNamesAsList())));
|
||||
},
|
||||
),
|
||||
CupertinoListTile(
|
||||
@@ -374,8 +373,8 @@ class _ActiveGameViewState extends State<ActiveGameView> {
|
||||
List<int>.generate(gameSession.players.length, (index) => index);
|
||||
// Sort the indices based on the summed points
|
||||
playerIndices.sort((a, b) {
|
||||
int scoreA = gameSession.playerScores[a];
|
||||
int scoreB = gameSession.playerScores[b];
|
||||
int scoreA = gameSession.getPlayerScoresAsList()[a];
|
||||
int scoreB = gameSession.getPlayerScoresAsList()[b];
|
||||
if (scoreA != scoreB) {
|
||||
return scoreA.compareTo(scoreB);
|
||||
}
|
||||
@@ -515,7 +514,8 @@ class _ActiveGameViewState extends State<ActiveGameView> {
|
||||
/// Plays the confetti animation and shows a dialog with the winner's information.
|
||||
Future<void> _playFinishAnimation(BuildContext context) async {
|
||||
String winner = widget.gameSession.winner;
|
||||
int winnerPoints = widget.gameSession.playerScores.min;
|
||||
|
||||
int winnerPoints = widget.gameSession.getPlayerScoresAsList().min;
|
||||
int winnerAmount = winner.contains('&') ? 2 : 1;
|
||||
|
||||
confettiController.play();
|
||||
|
||||
@@ -94,7 +94,7 @@ class _GraphViewState extends State<GraphView> {
|
||||
List<LineSeries<(int, num), int>> getCumulativeScores() {
|
||||
final rounds = widget.gameSession.roundList;
|
||||
final playerCount = widget.gameSession.players.length;
|
||||
final playerNames = widget.gameSession.players;
|
||||
final playerNames = widget.gameSession.getPlayerNamesAsList();
|
||||
|
||||
List<List<int>> cumulativeScores = List.generate(playerCount, (_) => []);
|
||||
List<int> runningTotals = List.filled(playerCount, 0);
|
||||
|
||||
@@ -68,7 +68,7 @@ class _PointsViewState extends State<PointsView> {
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 8),
|
||||
child: Text(
|
||||
player,
|
||||
player.name,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.bold),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
@@ -120,7 +120,7 @@ class _PointsViewState extends State<PointsView> {
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 8),
|
||||
child: Text(
|
||||
player,
|
||||
player.name,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.bold),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
@@ -236,18 +236,20 @@ class _PointsViewState extends State<PointsView> {
|
||||
fontWeight: FontWeight.bold),
|
||||
),
|
||||
)),
|
||||
...widget.gameSession.playerScores.map(
|
||||
(score) => DataCell(
|
||||
Center(
|
||||
child: Text(
|
||||
'$score',
|
||||
style: const TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold),
|
||||
...widget.gameSession
|
||||
.getPlayerScoresAsList()
|
||||
.map(
|
||||
(score) => DataCell(
|
||||
Center(
|
||||
child: Text(
|
||||
'$score',
|
||||
style: const TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
|
||||
@@ -146,7 +146,7 @@ class _RoundViewState extends State<RoundView> {
|
||||
.entries
|
||||
.map((entry) {
|
||||
final index = entry.key;
|
||||
final name = entry.value;
|
||||
final player = entry.value;
|
||||
return MapEntry(
|
||||
index,
|
||||
Padding(
|
||||
@@ -157,7 +157,7 @@ class _RoundViewState extends State<RoundView> {
|
||||
child: FittedBox(
|
||||
fit: BoxFit.scaleDown,
|
||||
child: Text(
|
||||
name,
|
||||
player.name,
|
||||
textAlign: TextAlign.center,
|
||||
maxLines: 1,
|
||||
style: const TextStyle(
|
||||
@@ -210,7 +210,7 @@ class _RoundViewState extends State<RoundView> {
|
||||
]))
|
||||
]),
|
||||
subtitle: Text(
|
||||
'${widget.gameSession.playerScores[originalIndex]}'
|
||||
'${widget.gameSession.getPlayerScoresAsList()[originalIndex]}'
|
||||
' ${AppLocalizations.of(context).points}'),
|
||||
trailing: SizedBox(
|
||||
width: 100,
|
||||
@@ -329,10 +329,11 @@ class _RoundViewState extends State<RoundView> {
|
||||
/// Rotates the players list based on the previous round's winner.
|
||||
List<String> _getRotatedPlayers() {
|
||||
final winnerIndex = _getPreviousRoundWinnerIndex();
|
||||
final playerList = widget.gameSession.getPlayerNamesAsList();
|
||||
return [
|
||||
widget.gameSession.players[winnerIndex],
|
||||
...widget.gameSession.players.sublist(winnerIndex + 1),
|
||||
...widget.gameSession.players.sublist(0, winnerIndex)
|
||||
playerList[winnerIndex],
|
||||
...playerList.sublist(winnerIndex + 1),
|
||||
...playerList.sublist(0, winnerIndex)
|
||||
];
|
||||
}
|
||||
|
||||
@@ -358,14 +359,14 @@ class _RoundViewState extends State<RoundView> {
|
||||
message: Text(AppLocalizations.of(context).who_has_kamikaze),
|
||||
actions: widget.gameSession.players.asMap().entries.map((entry) {
|
||||
final index = entry.key;
|
||||
final name = entry.value;
|
||||
final player = entry.value;
|
||||
return CupertinoActionSheetAction(
|
||||
onPressed: () {
|
||||
_kamikazePlayerIndex = index;
|
||||
Navigator.pop(context, true);
|
||||
},
|
||||
child: Text(
|
||||
name,
|
||||
player.name,
|
||||
style: TextStyle(color: CustomTheme.kamikazeColor),
|
||||
),
|
||||
);
|
||||
@@ -494,7 +495,7 @@ class _RoundViewState extends State<RoundView> {
|
||||
String _getBonusPopupMessageString(
|
||||
int pointLimit, int bonusPoints, List<int> bonusPlayers) {
|
||||
List<String> nameList =
|
||||
bonusPlayers.map((i) => widget.gameSession.players[i]).toList();
|
||||
bonusPlayers.map((i) => widget.gameSession.players[i].name).toList();
|
||||
String resultText = '';
|
||||
if (nameList.length == 1) {
|
||||
resultText = AppLocalizations.of(context).bonus_points_message(
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'package:cabo_counter/core/constants.dart';
|
||||
import 'package:cabo_counter/core/custom_theme.dart';
|
||||
import 'package:cabo_counter/data/dto/game_manager.dart';
|
||||
import 'package:cabo_counter/data/dto/game_session.dart';
|
||||
import 'package:cabo_counter/data/dto/player.dart';
|
||||
import 'package:cabo_counter/l10n/generated/app_localizations.dart';
|
||||
import 'package:cabo_counter/presentation/views/home/active_game/active_game_view.dart';
|
||||
import 'package:cabo_counter/presentation/views/home/active_game/mode_selection_view.dart';
|
||||
@@ -448,26 +449,38 @@ class _CreateGameViewState extends State<CreateGameView> {
|
||||
/// It then adds the game session to the game manager and navigates to the active game view.
|
||||
void _createGame() {
|
||||
var uuid = const Uuid();
|
||||
final String id = uuid.v1();
|
||||
final String gameId = uuid.v1();
|
||||
|
||||
List<String> players = [];
|
||||
// Collect player names from the text controllers.
|
||||
List<String> playerNames = [];
|
||||
for (var controller in _playerNameTextControllers) {
|
||||
players.add(controller.text);
|
||||
playerNames.add(controller.text);
|
||||
}
|
||||
|
||||
// Create a list of Player objects with unique IDs and the corresponding attributes
|
||||
List<Player> playerList = [];
|
||||
for (int i = 0; i < playerNames.length; i++) {
|
||||
playerList.add(Player(
|
||||
playerId: uuid.v1(),
|
||||
gameId: gameId,
|
||||
name: playerNames[i],
|
||||
position: i,
|
||||
));
|
||||
}
|
||||
|
||||
bool isPointsLimitEnabled = gameMode == GameMode.pointLimit;
|
||||
|
||||
GameSession gameSession = GameSession(
|
||||
id: id,
|
||||
id: gameId,
|
||||
createdAt: DateTime.now(),
|
||||
gameTitle: _gameTitleTextController.text,
|
||||
players: players,
|
||||
players: playerList,
|
||||
pointLimit: ConfigService.getPointLimit(),
|
||||
caboPenalty: ConfigService.getCaboPenalty(),
|
||||
isPointsLimitEnabled: isPointsLimitEnabled,
|
||||
isGameFinished: false);
|
||||
gameManager.addGameSession(gameSession);
|
||||
final session = gameManager.getGameSessionById(id) ?? gameSession;
|
||||
final session = gameManager.getGameSessionById(gameId) ?? gameSession;
|
||||
|
||||
Navigator.pushAndRemoveUntil(
|
||||
context,
|
||||
|
||||
Reference in New Issue
Block a user