WIP: Score implementation ergänzen #196
@@ -32,7 +32,7 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
|
|||||||
final winner = await getWinner(matchId: row.id);
|
final winner = await getWinner(matchId: row.id);
|
||||||
return Match(
|
return Match(
|
||||||
id: row.id,
|
id: row.id,
|
||||||
name: row.name ?? '',
|
name: row.name,
|
||||||
game: game,
|
game: game,
|
||||||
group: group,
|
group: group,
|
||||||
players: players,
|
players: players,
|
||||||
@@ -64,7 +64,7 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
|
|||||||
|
|
||||||
return Match(
|
return Match(
|
||||||
id: result.id,
|
id: result.id,
|
||||||
name: result.name ?? '',
|
name: result.name,
|
||||||
game: game,
|
game: game,
|
||||||
group: group,
|
group: group,
|
||||||
players: players,
|
players: players,
|
||||||
@@ -85,7 +85,7 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
|
|||||||
id: match.id,
|
id: match.id,
|
||||||
gameId: match.game.id,
|
gameId: match.game.id,
|
||||||
groupId: Value(match.group?.id),
|
groupId: Value(match.group?.id),
|
||||||
name: Value(match.name),
|
name: match.name,
|
||||||
notes: Value(match.notes),
|
notes: Value(match.notes),
|
||||||
createdAt: match.createdAt,
|
createdAt: match.createdAt,
|
||||||
endedAt: Value(match.endedAt),
|
endedAt: Value(match.endedAt),
|
||||||
@@ -170,7 +170,7 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
|
|||||||
id: match.id,
|
id: match.id,
|
||||||
gameId: match.game.id,
|
gameId: match.game.id,
|
||||||
groupId: Value(match.group?.id),
|
groupId: Value(match.group?.id),
|
||||||
name: Value(match.name),
|
name: match.name,
|
||||||
notes: Value(match.notes),
|
notes: Value(match.notes),
|
||||||
createdAt: match.createdAt,
|
createdAt: match.createdAt,
|
||||||
endedAt: Value(match.endedAt),
|
endedAt: Value(match.endedAt),
|
||||||
@@ -223,7 +223,6 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
|
|||||||
PlayerMatchTableCompanion.insert(
|
PlayerMatchTableCompanion.insert(
|
||||||
matchId: match.id,
|
matchId: match.id,
|
||||||
playerId: p.id,
|
playerId: p.id,
|
||||||
score: 0,
|
|
||||||
),
|
),
|
||||||
mode: InsertMode.insertOrIgnore,
|
mode: InsertMode.insertOrIgnore,
|
||||||
);
|
);
|
||||||
@@ -283,7 +282,7 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
|
|||||||
final winner = await db.matchDao.getWinner(matchId: row.id);
|
final winner = await db.matchDao.getWinner(matchId: row.id);
|
||||||
return Match(
|
return Match(
|
||||||
id: row.id,
|
id: row.id,
|
||||||
name: row.name ?? '',
|
name: row.name,
|
||||||
game: game,
|
game: game,
|
||||||
group: group,
|
group: group,
|
||||||
players: players,
|
players: players,
|
||||||
@@ -490,20 +489,22 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
|
|||||||
await db.playerMatchDao.getPlayersOfMatch(matchId: matchId) ?? [];
|
await db.playerMatchDao.getPlayersOfMatch(matchId: matchId) ?? [];
|
||||||
|
|
||||||
// Set all players' scores to 0
|
// Set all players' scores to 0
|
||||||
for (final player in players) {
|
// TODO: Implement
|
||||||
|
/*for (final player in players) {
|
||||||
await db.playerMatchDao.updatePlayerScore(
|
await db.playerMatchDao.updatePlayerScore(
|
||||||
matchId: matchId,
|
matchId: matchId,
|
||||||
playerId: player.id,
|
playerId: player.id,
|
||||||
newScore: 0,
|
newScore: 0,
|
||||||
);
|
);
|
||||||
}
|
}*/
|
||||||
|
|
||||||
// Set the winner's score to 1
|
// Set the winner's score to 1
|
||||||
await db.playerMatchDao.updatePlayerScore(
|
// TODO: Implement
|
||||||
|
/*await db.playerMatchDao.updatePlayerScore(
|
||||||
matchId: matchId,
|
matchId: matchId,
|
||||||
playerId: winnerId,
|
playerId: winnerId,
|
||||||
newScore: 1,
|
newScore: 1,
|
||||||
);
|
);*/
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -517,11 +518,11 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
final success = await db.playerMatchDao.updatePlayerScore(
|
/*final success = await db.playerMatchDao.updatePlayerScore(
|
||||||
matchId: matchId,
|
matchId: matchId,
|
||||||
playerId: winner.id,
|
playerId: winner.id,
|
||||||
newScore: 0,
|
newScore: 0,
|
||||||
);
|
);*/
|
||||||
return success;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ class PlayerMatchDao extends DatabaseAccessor<AppDatabase>
|
|||||||
playerId: playerId,
|
playerId: playerId,
|
||||||
matchId: matchId,
|
matchId: matchId,
|
||||||
teamId: Value(teamId),
|
teamId: Value(teamId),
|
||||||
score: score,
|
|
||||||
),
|
),
|
||||||
mode: InsertMode.insertOrIgnore,
|
mode: InsertMode.insertOrIgnore,
|
||||||
);
|
);
|
||||||
@@ -48,6 +47,7 @@ class PlayerMatchDao extends DatabaseAccessor<AppDatabase>
|
|||||||
|
|
||||||
/// Retrieves a player's score for a specific match.
|
/// Retrieves a player's score for a specific match.
|
||||||
/// Returns null if the player is not in the match.
|
/// Returns null if the player is not in the match.
|
||||||
|
/// TODO: Implement
|
||||||
Future<int?> getPlayerScore({
|
Future<int?> getPlayerScore({
|
||||||
required String matchId,
|
required String matchId,
|
||||||
required String playerId,
|
required String playerId,
|
||||||
@@ -57,7 +57,7 @@ class PlayerMatchDao extends DatabaseAccessor<AppDatabase>
|
|||||||
(p) => p.matchId.equals(matchId) & p.playerId.equals(playerId),
|
(p) => p.matchId.equals(matchId) & p.playerId.equals(playerId),
|
||||||
))
|
))
|
||||||
.getSingleOrNull();
|
.getSingleOrNull();
|
||||||
return result?.score;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Updates the score for a player in a match.
|
/// Updates the score for a player in a match.
|
||||||
@@ -67,12 +67,13 @@ class PlayerMatchDao extends DatabaseAccessor<AppDatabase>
|
|||||||
required String playerId,
|
required String playerId,
|
||||||
required int newScore,
|
required int newScore,
|
||||||
}) async {
|
}) async {
|
||||||
final rowsAffected =
|
/* final rowsAffected =
|
||||||
await (update(playerMatchTable)..where(
|
await (update(playerMatchTable)..where(
|
||||||
(p) => p.matchId.equals(matchId) & p.playerId.equals(playerId),
|
(p) => p.matchId.equals(matchId) & p.playerId.equals(playerId),
|
||||||
))
|
))
|
||||||
.write(PlayerMatchTableCompanion(score: Value(newScore)));
|
.write(PlayerMatchTableCompanion(score: Value(newScore)));
|
||||||
return rowsAffected > 0;
|
return rowsAffected > 0;*/
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Updates the team for a player in a match.
|
/// Updates the team for a player in a match.
|
||||||
@@ -166,7 +167,6 @@ class PlayerMatchDao extends DatabaseAccessor<AppDatabase>
|
|||||||
(id) => PlayerMatchTableCompanion.insert(
|
(id) => PlayerMatchTableCompanion.insert(
|
||||||
playerId: id,
|
playerId: id,
|
||||||
matchId: matchId,
|
matchId: matchId,
|
||||||
score: 0,
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.toList();
|
.toList();
|
||||||
|
|||||||
Reference in New Issue
Block a user