Added scores to match class
This commit is contained in:
@@ -3,6 +3,7 @@ import 'package:tallee/core/enums.dart';
|
|||||||
import 'package:tallee/data/dto/game.dart';
|
import 'package:tallee/data/dto/game.dart';
|
||||||
import 'package:tallee/data/dto/group.dart';
|
import 'package:tallee/data/dto/group.dart';
|
||||||
import 'package:tallee/data/dto/player.dart';
|
import 'package:tallee/data/dto/player.dart';
|
||||||
|
import 'package:tallee/data/dto/score_entry.dart';
|
||||||
import 'package:uuid/uuid.dart';
|
import 'package:uuid/uuid.dart';
|
||||||
|
|
||||||
class Match {
|
class Match {
|
||||||
@@ -14,6 +15,7 @@ class Match {
|
|||||||
final Group? group;
|
final Group? group;
|
||||||
final List<Player> players;
|
final List<Player> players;
|
||||||
final String notes;
|
final String notes;
|
||||||
|
List<ScoreEntry> scores;
|
||||||
Player? winner;
|
Player? winner;
|
||||||
|
|
||||||
Match({
|
Match({
|
||||||
@@ -24,28 +26,42 @@ class Match {
|
|||||||
required this.game,
|
required this.game,
|
||||||
this.group,
|
this.group,
|
||||||
this.players = const [],
|
this.players = const [],
|
||||||
String? notes,
|
this.notes = '',
|
||||||
|
this.scores = const [],
|
||||||
this.winner,
|
this.winner,
|
||||||
}) : id = id ?? const Uuid().v4(),
|
}) : id = id ?? const Uuid().v4(),
|
||||||
createdAt = createdAt ?? clock.now(),
|
createdAt = createdAt ?? clock.now();
|
||||||
notes = notes ?? '';
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'Match{id: $id, name: $name, game: $game, group: $group, players: $players, notes: $notes, endedAt: $endedAt}';
|
return 'Match{id: $id, createdAt: $createdAt, endedAt: $endedAt, '
|
||||||
|
'name: $name, game: $game, group: $group, players: $players, '
|
||||||
|
'notes: $notes, scores: $scores, winner: $winner}';
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a Match instance from a JSON object (ID references format).
|
/// Creates a Match instance from a JSON object (ID references format).
|
||||||
/// Related objects are reconstructed from IDs by the DataTransferService.
|
/// Related objects are reconstructed from IDs by the DataTransferService.
|
||||||
Match.fromJson(Map<String, dynamic> json)
|
Match.fromJson(Map<String, dynamic> json)
|
||||||
: id = json['id'],
|
: id = json['id'],
|
||||||
createdAt = DateTime.parse(json['createdAt']),
|
createdAt = DateTime.parse(json['createdAt']),
|
||||||
endedAt = json['endedAt'] != null ? DateTime.parse(json['endedAt']) : null,
|
endedAt = json['endedAt'] != null
|
||||||
name = json['name'],
|
? DateTime.parse(json['endedAt'])
|
||||||
game = Game(name: '', ruleset: Ruleset.singleWinner, description: '', color: GameColor.blue, icon: ''), // Populated during import via DataTransferService
|
: null,
|
||||||
group = null, // Populated during import via DataTransferService
|
name = json['name'],
|
||||||
players = [], // Populated during import via DataTransferService
|
game = Game(
|
||||||
notes = json['notes'] ?? '';
|
name: '',
|
||||||
|
ruleset: Ruleset.singleWinner,
|
||||||
|
description: '',
|
||||||
|
color: GameColor.blue,
|
||||||
|
icon: '',
|
||||||
|
),
|
||||||
|
// Populated during import via DataTransferService
|
||||||
|
group = null,
|
||||||
|
// Populated during import via DataTransferService
|
||||||
|
players = [],
|
||||||
|
// Populated during import via DataTransferService
|
||||||
|
scores = json['scores'],
|
||||||
|
notes = json['notes'] ?? '';
|
||||||
|
|
||||||
/// Converts the Match instance to a JSON object using normalized format (ID references only).
|
/// Converts the Match instance to a JSON object using normalized format (ID references only).
|
||||||
Map<String, dynamic> toJson() => {
|
Map<String, dynamic> toJson() => {
|
||||||
@@ -56,6 +72,7 @@ class Match {
|
|||||||
'gameId': game.id,
|
'gameId': game.id,
|
||||||
'groupId': group?.id,
|
'groupId': group?.id,
|
||||||
'playerIds': players.map((player) => player.id).toList(),
|
'playerIds': players.map((player) => player.id).toList(),
|
||||||
|
'scores': scores.map((score) => score.toJson()).toList(),
|
||||||
'notes': notes,
|
'notes': notes,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
30
lib/data/dto/score_entry.dart
Normal file
30
lib/data/dto/score_entry.dart
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
class ScoreEntry {
|
||||||
|
final String playerId;
|
||||||
|
final String matchId;
|
||||||
|
final int roundNumber;
|
||||||
|
int score = 0;
|
||||||
|
int change = 0;
|
||||||
|
|
||||||
|
ScoreEntry({
|
||||||
|
required this.playerId,
|
||||||
|
required this.matchId,
|
||||||
|
required this.roundNumber,
|
||||||
|
required this.score,
|
||||||
|
required this.change,
|
||||||
|
});
|
||||||
|
|
||||||
|
ScoreEntry.fromJson(Map<String, dynamic> json)
|
||||||
|
: playerId = json['playerId'],
|
||||||
|
matchId = json['matchId'],
|
||||||
|
roundNumber = json['roundNumber'],
|
||||||
|
score = json['score'],
|
||||||
|
change = json['change'];
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() => {
|
||||||
|
'playerId': playerId,
|
||||||
|
'matchId': matchId,
|
||||||
|
'roundNumber': roundNumber,
|
||||||
|
'score': score,
|
||||||
|
'change': change,
|
||||||
|
};
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user