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);
|
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,
|
height: 60,
|
||||||
child: Container(
|
child: Container(
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: CustomTheme.boxColor,
|
color: CustomTheme.primaryColor,
|
||||||
border: Border.all(
|
border: Border.all(
|
||||||
color: CustomTheme.primaryColor,
|
color: CustomTheme.primaryColor,
|
||||||
),
|
),
|
||||||
@@ -212,7 +212,7 @@ class _MatchResultViewState extends State<MatchResultView> {
|
|||||||
child: Text(
|
child: Text(
|
||||||
' #${i + 1} ',
|
' #${i + 1} ',
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
color: CustomTheme.primaryColor,
|
color: CustomTheme.textColor,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
fontSize: 16,
|
fontSize: 16,
|
||||||
),
|
),
|
||||||
@@ -383,17 +383,10 @@ class _MatchResultViewState extends State<MatchResultView> {
|
|||||||
|
|
||||||
/// Handles saving the placement for each player in the database.
|
/// Handles saving the placement for each player in the database.
|
||||||
Future<void> _handlePlacement() async {
|
Future<void> _handlePlacement() async {
|
||||||
for (int i = 0; i < allPlayers.length; i++) {
|
await db.scoreEntryDao.setPlacements(
|
||||||
await db.scoreEntryDao.addScore(
|
matchId: widget.match.id,
|
||||||
matchId: widget.match.id,
|
players: allPlayers,
|
||||||
playerId: allPlayers[i].id,
|
);
|
||||||
entry: ScoreEntry(
|
|
||||||
roundNumber: 0,
|
|
||||||
score: allPlayers.length - i,
|
|
||||||
change: 0,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String getTitleForRuleset(AppLocalizations loc) {
|
String getTitleForRuleset(AppLocalizations loc) {
|
||||||
|
|||||||
@@ -303,8 +303,9 @@ class _MatchTileState extends State<MatchTile> {
|
|||||||
final mvp = widget.match.mvp;
|
final mvp = widget.match.mvp;
|
||||||
final mvpScore = widget.match.scores[mvp.first.id]?.score ?? 0;
|
final mvpScore = widget.match.scores[mvp.first.id]?.score ?? 0;
|
||||||
final mvpNames = mvp.map((player) => player.name).join(', ');
|
final mvpNames = mvp.map((player) => player.name).join(', ');
|
||||||
|
|
||||||
return '${loc.winner}: $mvpNames (${getPointLabel(loc, mvpScore)})';
|
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.';
|
return '${loc.winner}: n.A.';
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user