implement setPlacement in Score Dao & add placement game type to match tile
This commit is contained in:
@@ -353,4 +353,19 @@ class ScoreEntryDao extends DatabaseAccessor<AppDatabase>
|
||||
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<void> setPlacements({
|
||||
required String matchId,
|
||||
required List<Player> 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),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -199,7 +199,7 @@ class _MatchResultViewState extends State<MatchResultView> {
|
||||
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<MatchResultView> {
|
||||
child: Text(
|
||||
' #${i + 1} ',
|
||||
style: const TextStyle(
|
||||
color: CustomTheme.primaryColor,
|
||||
color: CustomTheme.textColor,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 16,
|
||||
),
|
||||
@@ -383,18 +383,11 @@ class _MatchResultViewState extends State<MatchResultView> {
|
||||
|
||||
/// Handles saving the placement for each player in the database.
|
||||
Future<void> _handlePlacement() async {
|
||||
for (int i = 0; i < allPlayers.length; i++) {
|
||||
await db.scoreEntryDao.addScore(
|
||||
await db.scoreEntryDao.setPlacements(
|
||||
matchId: widget.match.id,
|
||||
playerId: allPlayers[i].id,
|
||||
entry: ScoreEntry(
|
||||
roundNumber: 0,
|
||||
score: allPlayers.length - i,
|
||||
change: 0,
|
||||
),
|
||||
players: allPlayers,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String getTitleForRuleset(AppLocalizations loc) {
|
||||
switch (ruleset) {
|
||||
|
||||
@@ -303,8 +303,9 @@ class _MatchTileState extends State<MatchTile> {
|
||||
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.';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user