First version of retrieving a gamesession from the db
This commit is contained in:
@@ -20,21 +20,25 @@ class GameSession extends ChangeNotifier {
|
||||
final int pointLimit;
|
||||
final int caboPenalty;
|
||||
final bool isPointsLimitEnabled;
|
||||
bool isGameFinished = false;
|
||||
String winner = '';
|
||||
int roundNumber = 1;
|
||||
late List<int> playerScores;
|
||||
List<Round> roundList = [];
|
||||
bool isGameFinished;
|
||||
String winner;
|
||||
int roundNumber;
|
||||
List<int> playerScores;
|
||||
List<Round> roundList;
|
||||
|
||||
GameSession({
|
||||
required this.id,
|
||||
required this.createdAt,
|
||||
required this.gameTitle,
|
||||
required this.players,
|
||||
required this.pointLimit,
|
||||
required this.caboPenalty,
|
||||
required this.isPointsLimitEnabled,
|
||||
}) {
|
||||
GameSession(
|
||||
{required this.id,
|
||||
required this.createdAt,
|
||||
required this.gameTitle,
|
||||
required this.players,
|
||||
required this.pointLimit,
|
||||
required this.caboPenalty,
|
||||
required this.isPointsLimitEnabled,
|
||||
this.isGameFinished = false,
|
||||
this.winner = '',
|
||||
this.roundNumber = 1,
|
||||
this.playerScores = const [],
|
||||
this.roundList = const []}) {
|
||||
playerScores = List.filled(players.length, 0);
|
||||
}
|
||||
|
||||
@@ -207,6 +211,8 @@ class GameSession extends ChangeNotifier {
|
||||
int? kamikazePlayerIndex,
|
||||
]) {
|
||||
Round newRound = Round(
|
||||
roundId: const Uuid().v1(),
|
||||
gameId: id,
|
||||
roundNum: roundNum,
|
||||
caboPlayerIndex: caboPlayerIndex,
|
||||
kamikazePlayerIndex: kamikazePlayerIndex,
|
||||
|
||||
34
lib/data/dto/player.dart
Normal file
34
lib/data/dto/player.dart
Normal file
@@ -0,0 +1,34 @@
|
||||
class Player {
|
||||
final String playerId;
|
||||
final String gameId;
|
||||
final String name;
|
||||
final int position;
|
||||
int totalScore;
|
||||
|
||||
Player(
|
||||
{required this.playerId,
|
||||
required this.gameId,
|
||||
required this.name,
|
||||
required this.position,
|
||||
this.totalScore = 0});
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return '(playerId: $playerId, gameId: $gameId, name: $name, position: $position)';
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'playerId': playerId,
|
||||
'gameId': gameId,
|
||||
'name': name,
|
||||
'position': position,
|
||||
'totalScore': totalScore
|
||||
};
|
||||
|
||||
Player.fromJson(Map<String, dynamic> json)
|
||||
: playerId = json['playerId'],
|
||||
gameId = json['gameId'],
|
||||
name = json['name'],
|
||||
position = json['position'],
|
||||
totalScore = json['totalScore'];
|
||||
}
|
||||
@@ -6,6 +6,8 @@
|
||||
/// [kamikazePlayerIndex] is the index of the player who got kamikaze. If no one got
|
||||
/// kamikaze, this value is null.
|
||||
class Round {
|
||||
final String roundId;
|
||||
final String gameId;
|
||||
final int roundNum;
|
||||
final int caboPlayerIndex;
|
||||
final int? kamikazePlayerIndex;
|
||||
@@ -13,6 +15,8 @@ class Round {
|
||||
final List<int> scoreUpdates;
|
||||
|
||||
Round({
|
||||
required this.roundId,
|
||||
required this.gameId,
|
||||
required this.roundNum,
|
||||
required this.caboPlayerIndex,
|
||||
this.kamikazePlayerIndex,
|
||||
@@ -29,6 +33,8 @@ class Round {
|
||||
|
||||
/// Converts the Round object to a JSON map.
|
||||
Map<String, dynamic> toJson() => {
|
||||
'roundId': roundId,
|
||||
'gameId': gameId,
|
||||
'roundNum': roundNum,
|
||||
'caboPlayerIndex': caboPlayerIndex,
|
||||
'kamikazePlayerIndex': kamikazePlayerIndex,
|
||||
@@ -38,7 +44,9 @@ class Round {
|
||||
|
||||
/// Creates a Round object from a JSON map.
|
||||
Round.fromJson(Map<String, dynamic> json)
|
||||
: roundNum = json['roundNum'],
|
||||
: roundId = json['roundId'],
|
||||
gameId = json['gameId'],
|
||||
roundNum = json['roundNum'],
|
||||
caboPlayerIndex = json['caboPlayerIndex'],
|
||||
kamikazePlayerIndex = json['kamikazePlayerIndex'],
|
||||
scores = List<int>.from(json['scores']),
|
||||
|
||||
12
lib/data/dto/round_score.dart
Normal file
12
lib/data/dto/round_score.dart
Normal file
@@ -0,0 +1,12 @@
|
||||
class RoundScore {
|
||||
final String roundId;
|
||||
final String playerId;
|
||||
final int score;
|
||||
final int scoreUpdate;
|
||||
|
||||
RoundScore(
|
||||
{required this.roundId,
|
||||
required this.playerId,
|
||||
required this.score,
|
||||
required this.scoreUpdate});
|
||||
}
|
||||
Reference in New Issue
Block a user