Updated score saving in match
This commit is contained in:
@@ -15,7 +15,7 @@ class Match {
|
||||
final Group? group;
|
||||
final List<Player> players;
|
||||
final String notes;
|
||||
List<Score> scores;
|
||||
Map<String, List<Score>> scores;
|
||||
Player? winner;
|
||||
|
||||
Match({
|
||||
@@ -27,10 +27,11 @@ class Match {
|
||||
this.group,
|
||||
this.players = const [],
|
||||
this.notes = '',
|
||||
this.scores = const [],
|
||||
Map<String, List<Score>>? scores,
|
||||
this.winner,
|
||||
}) : id = id ?? const Uuid().v4(),
|
||||
createdAt = createdAt ?? clock.now();
|
||||
createdAt = createdAt ?? clock.now(),
|
||||
scores = scores ?? {for (var player in players) player.id: []};
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
@@ -67,7 +68,7 @@ class Match {
|
||||
'gameId': game.id,
|
||||
'groupId': group?.id,
|
||||
'playerIds': players.map((player) => player.id).toList(),
|
||||
'scores': scores.map((score) => score.toJson()).toList(),
|
||||
'scores': scores,
|
||||
'notes': notes,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,24 +1,16 @@
|
||||
class Score {
|
||||
final String playerId;
|
||||
final int roundNumber;
|
||||
int score = 0;
|
||||
int change = 0;
|
||||
|
||||
Score({
|
||||
required this.playerId,
|
||||
required this.roundNumber,
|
||||
required this.score,
|
||||
required this.change,
|
||||
});
|
||||
Score({required this.roundNumber, required this.score, required this.change});
|
||||
|
||||
Score.fromJson(Map<String, dynamic> json)
|
||||
: playerId = json['playerId'],
|
||||
roundNumber = json['roundNumber'],
|
||||
: roundNumber = json['roundNumber'],
|
||||
score = json['score'],
|
||||
change = json['change'];
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'playerId': playerId,
|
||||
'roundNumber': roundNumber,
|
||||
'score': score,
|
||||
'change': change,
|
||||
|
||||
Reference in New Issue
Block a user