Impementing toJson() and fromJson() Method in GameSession and Round class

This commit is contained in:
Felix Kirchner
2025-04-30 14:34:14 +02:00
parent 9f315a5db8
commit 6b6e824860
2 changed files with 41 additions and 0 deletions

View File

@@ -1,3 +1,5 @@
import 'package:cabo_counter/data/game_session.dart';
/// This class represents a single round in the game.
/// It is stored within the [GameSession] class.
/// [roundNum] is the number of the round its reppresenting.
@@ -16,4 +18,19 @@ class Round {
required this.scores,
required this.scoreUpdates,
this.kamikazePlayerIndex});
/// Converts the Round object to a JSON map.
Map<String, dynamic> toJson() => {
'roundNum': roundNum,
'scores': scores,
'scoreUpdates': scoreUpdates,
'kamikazePlayerIndex': kamikazePlayerIndex,
};
/// Creates a Round object from a JSON map.
Round.fromJson(Map<String, dynamic> json)
: roundNum = json['roundNum'],
scores = List<int>.from(json['scores']),
scoreUpdates = List<int>.from(json['scoreUpdates']),
kamikazePlayerIndex = json['kamikazePlayerIndex'];
}