From 79ce3efd0ab8d87bf7eac64f9c86862e65fa3a30 Mon Sep 17 00:00:00 2001 From: Mathis Kirchner Date: Sat, 9 May 2026 18:19:30 +0200 Subject: [PATCH] implement setPlacement in Score Dao & add placement game type to match tile --- lib/data/dao/score_entry_dao.dart | 15 +++++++++++++++ .../match_view/match_result_view.dart | 19 ++++++------------- .../widgets/tiles/match_tile.dart | 3 ++- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/lib/data/dao/score_entry_dao.dart b/lib/data/dao/score_entry_dao.dart index 9c4e01d..cf6a449 100644 --- a/lib/data/dao/score_entry_dao.dart +++ b/lib/data/dao/score_entry_dao.dart @@ -353,4 +353,19 @@ class ScoreEntryDao extends DatabaseAccessor return await deleteAllScoresForMatch(matchId: matchId); } } + + /// Sets the placement for each player in a match. + /// The highest score is assigned to the first player, the second highest to the second player, and so on. + Future setPlacements({ + required String matchId, + required List players, + }) async { + for (int i = 0; i < players.length; i++) { + await db.scoreEntryDao.addScore( + matchId: matchId, + playerId: players[i].id, + entry: ScoreEntry(roundNumber: 0, score: players.length - i, change: 0), + ); + } + } } diff --git a/lib/presentation/views/main_menu/match_view/match_result_view.dart b/lib/presentation/views/main_menu/match_view/match_result_view.dart index f0c6fb4..839d109 100644 --- a/lib/presentation/views/main_menu/match_view/match_result_view.dart +++ b/lib/presentation/views/main_menu/match_view/match_result_view.dart @@ -199,7 +199,7 @@ class _MatchResultViewState extends State { height: 60, child: Container( decoration: BoxDecoration( - color: CustomTheme.boxColor, + color: CustomTheme.primaryColor, border: Border.all( color: CustomTheme.primaryColor, ), @@ -212,7 +212,7 @@ class _MatchResultViewState extends State { child: Text( ' #${i + 1} ', style: const TextStyle( - color: CustomTheme.primaryColor, + color: CustomTheme.textColor, fontWeight: FontWeight.bold, fontSize: 16, ), @@ -383,17 +383,10 @@ class _MatchResultViewState extends State { /// Handles saving the placement for each player in the database. Future _handlePlacement() async { - for (int i = 0; i < allPlayers.length; i++) { - await db.scoreEntryDao.addScore( - matchId: widget.match.id, - playerId: allPlayers[i].id, - entry: ScoreEntry( - roundNumber: 0, - score: allPlayers.length - i, - change: 0, - ), - ); - } + await db.scoreEntryDao.setPlacements( + matchId: widget.match.id, + players: allPlayers, + ); } String getTitleForRuleset(AppLocalizations loc) { diff --git a/lib/presentation/widgets/tiles/match_tile.dart b/lib/presentation/widgets/tiles/match_tile.dart index f7585d6..1149a67 100644 --- a/lib/presentation/widgets/tiles/match_tile.dart +++ b/lib/presentation/widgets/tiles/match_tile.dart @@ -303,8 +303,9 @@ class _MatchTileState extends State { final mvp = widget.match.mvp; final mvpScore = widget.match.scores[mvp.first.id]?.score ?? 0; final mvpNames = mvp.map((player) => player.name).join(', '); - return '${loc.winner}: $mvpNames (${getPointLabel(loc, mvpScore)})'; + } else if (ruleset == Ruleset.placement) { + return '${loc.winner}: ${widget.match.mvp.first.name}'; } return '${loc.winner}: n.A.'; }