Compare commits
4 Commits
feb5fa0615
...
82b344a145
| Author | SHA1 | Date | |
|---|---|---|---|
| 82b344a145 | |||
| 338f4294dc | |||
| cfed05595c | |||
| fa841e328e |
@@ -88,13 +88,12 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"winner": {
|
"winner": {
|
||||||
"type": ["string","null"]
|
"type": ["object","null"]
|
||||||
},
|
},
|
||||||
"required": [
|
"required": [
|
||||||
"id",
|
"id",
|
||||||
"createdAt",
|
"createdAt",
|
||||||
"name",
|
"name"
|
||||||
"winner"
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -20,13 +20,16 @@ class GameDao extends DatabaseAccessor<AppDatabase> with _$GameDaoMixin {
|
|||||||
result.map((row) async {
|
result.map((row) async {
|
||||||
final group = await db.groupGameDao.getGroupOfGame(gameId: row.id);
|
final group = await db.groupGameDao.getGroupOfGame(gameId: row.id);
|
||||||
final players = await db.playerGameDao.getPlayersOfGame(gameId: row.id);
|
final players = await db.playerGameDao.getPlayersOfGame(gameId: row.id);
|
||||||
|
final winner = row.winnerId != null
|
||||||
|
? await db.playerDao.getPlayerById(playerId: row.winnerId!)
|
||||||
|
: null;
|
||||||
return Game(
|
return Game(
|
||||||
id: row.id,
|
id: row.id,
|
||||||
name: row.name,
|
name: row.name,
|
||||||
group: group,
|
group: group,
|
||||||
players: players,
|
players: players,
|
||||||
createdAt: row.createdAt,
|
createdAt: row.createdAt,
|
||||||
winner: row.winnerId,
|
winner: winner,
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
@@ -45,13 +48,17 @@ class GameDao extends DatabaseAccessor<AppDatabase> with _$GameDaoMixin {
|
|||||||
if (await db.groupGameDao.gameHasGroup(gameId: gameId)) {
|
if (await db.groupGameDao.gameHasGroup(gameId: gameId)) {
|
||||||
group = await db.groupGameDao.getGroupOfGame(gameId: gameId);
|
group = await db.groupGameDao.getGroupOfGame(gameId: gameId);
|
||||||
}
|
}
|
||||||
|
Player? winner;
|
||||||
|
if (result.winnerId != null) {
|
||||||
|
winner = await db.playerDao.getPlayerById(playerId: result.winnerId!);
|
||||||
|
}
|
||||||
|
|
||||||
return Game(
|
return Game(
|
||||||
id: result.id,
|
id: result.id,
|
||||||
name: result.name,
|
name: result.name,
|
||||||
players: players,
|
players: players,
|
||||||
group: group,
|
group: group,
|
||||||
winner: result.winnerId,
|
winner: winner,
|
||||||
createdAt: result.createdAt,
|
createdAt: result.createdAt,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -64,7 +71,7 @@ class GameDao extends DatabaseAccessor<AppDatabase> with _$GameDaoMixin {
|
|||||||
GameTableCompanion.insert(
|
GameTableCompanion.insert(
|
||||||
id: game.id,
|
id: game.id,
|
||||||
name: game.name,
|
name: game.name,
|
||||||
winnerId: Value(game.winner),
|
winnerId: Value(game.winner?.id),
|
||||||
createdAt: game.createdAt,
|
createdAt: game.createdAt,
|
||||||
),
|
),
|
||||||
mode: InsertMode.insertOrReplace,
|
mode: InsertMode.insertOrReplace,
|
||||||
@@ -100,7 +107,7 @@ class GameDao extends DatabaseAccessor<AppDatabase> with _$GameDaoMixin {
|
|||||||
id: game.id,
|
id: game.id,
|
||||||
name: game.name,
|
name: game.name,
|
||||||
createdAt: game.createdAt,
|
createdAt: game.createdAt,
|
||||||
winnerId: Value(game.winner),
|
winnerId: Value(game.winner?.id),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.toList(),
|
.toList(),
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ class Game {
|
|||||||
final String name;
|
final String name;
|
||||||
final List<Player>? players;
|
final List<Player>? players;
|
||||||
final Group? group;
|
final Group? group;
|
||||||
final String? winner;
|
final Player? winner;
|
||||||
|
|
||||||
Game({
|
Game({
|
||||||
String? id,
|
String? id,
|
||||||
@@ -17,7 +17,7 @@ class Game {
|
|||||||
required this.name,
|
required this.name,
|
||||||
this.players,
|
this.players,
|
||||||
this.group,
|
this.group,
|
||||||
this.winner = '',
|
this.winner,
|
||||||
}) : id = id ?? const Uuid().v4(),
|
}) : id = id ?? const Uuid().v4(),
|
||||||
createdAt = createdAt ?? clock.now();
|
createdAt = createdAt ?? clock.now();
|
||||||
|
|
||||||
@@ -37,7 +37,7 @@ class Game {
|
|||||||
.toList()
|
.toList()
|
||||||
: null,
|
: null,
|
||||||
group = json['group'] != null ? Group.fromJson(json['group']) : null,
|
group = json['group'] != null ? Group.fromJson(json['group']) : null,
|
||||||
winner = json['winner'] ?? '';
|
winner = json['winner'] != null ? Player.fromJson(json['winner']) : null;
|
||||||
|
|
||||||
/// Converts the Game instance to a JSON object.
|
/// Converts the Game instance to a JSON object.
|
||||||
Map<String, dynamic> toJson() => {
|
Map<String, dynamic> toJson() => {
|
||||||
@@ -46,6 +46,6 @@ class Game {
|
|||||||
'name': name,
|
'name': name,
|
||||||
'players': players?.map((player) => player.toJson()).toList(),
|
'players': players?.map((player) => player.toJson()).toList(),
|
||||||
'group': group?.toJson(),
|
'group': group?.toJson(),
|
||||||
'winner': winner,
|
'winner': winner?.toJson(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -127,13 +127,13 @@ class _StatisticsViewState extends State<StatisticsView> {
|
|||||||
// Getting the winners
|
// Getting the winners
|
||||||
for (var game in games) {
|
for (var game in games) {
|
||||||
final winner = game.winner;
|
final winner = game.winner;
|
||||||
if (winner != null && winner.isNotEmpty) {
|
if (winner != null) {
|
||||||
final index = winCounts.indexWhere((entry) => entry.$1 == winner);
|
final index = winCounts.indexWhere((entry) => entry.$1 == winner.id);
|
||||||
if (index != -1) {
|
if (index != -1) {
|
||||||
final current = winCounts[index].$2;
|
final current = winCounts[index].$2;
|
||||||
winCounts[index] = (winner, current + 1);
|
winCounts[index] = (winner.id, current + 1);
|
||||||
} else {
|
} else {
|
||||||
winCounts.add((winner, 1));
|
winCounts.add((winner.id, 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user