Neue Datenbank Struktur #156
@@ -37,6 +37,17 @@ enum ExportResult { success, canceled, unknownException }
|
||||
/// - [Ruleset.multipleWinners]: Multiple players can be winners.
|
||||
enum Ruleset { highestScore, lowestScore, singleWinner, singleLoser, multipleWinners }
|
||||
|
||||
/// Different colors available for games
|
||||
/// - [GameColor.red]: Red color
|
||||
/// - [GameColor.blue]: Blue color
|
||||
/// - [GameColor.green]: Green color
|
||||
/// - [GameColor.yellow]: Yellow color
|
||||
/// - [GameColor.purple]: Purple color
|
||||
/// - [GameColor.orange]: Orange color
|
||||
/// - [GameColor.pink]: Pink color
|
||||
/// - [GameColor.teal]: Teal color
|
||||
enum GameColor { red, blue, green, yellow, purple, orange, pink, teal }
|
||||
|
||||
/// Translates a [Ruleset] enum value to its corresponding localized string.
|
||||
String translateRulesetToString(Ruleset ruleset, BuildContext context) {
|
||||
final loc = AppLocalizations.of(context);
|
||||
|
||||
@@ -21,7 +21,7 @@ class GameDao extends DatabaseAccessor<AppDatabase> with _$GameDaoMixin {
|
||||
name: row.name,
|
||||
ruleset: Ruleset.values.firstWhere((e) => e.name == row.ruleset),
|
||||
description: row.description,
|
||||
color: row.color,
|
||||
color: GameColor.values.firstWhere((e) => e.name == row.color),
|
||||
icon: row.icon,
|
||||
createdAt: row.createdAt,
|
||||
),
|
||||
@@ -38,7 +38,7 @@ class GameDao extends DatabaseAccessor<AppDatabase> with _$GameDaoMixin {
|
||||
name: result.name,
|
||||
ruleset: Ruleset.values.firstWhere((e) => e.name == result.ruleset),
|
||||
|
flixcoo marked this conversation as resolved
|
||||
description: result.description,
|
||||
color: result.color,
|
||||
color: GameColor.values.firstWhere((e) => e.name == result.color),
|
||||
icon: result.icon,
|
||||
createdAt: result.createdAt,
|
||||
);
|
||||
@@ -55,7 +55,7 @@ class GameDao extends DatabaseAccessor<AppDatabase> with _$GameDaoMixin {
|
||||
name: game.name,
|
||||
ruleset: game.ruleset.name,
|
||||
description: game.description,
|
||||
color: game.color,
|
||||
color: game.color.name,
|
||||
icon: game.icon,
|
||||
createdAt: game.createdAt,
|
||||
),
|
||||
@@ -81,7 +81,7 @@ class GameDao extends DatabaseAccessor<AppDatabase> with _$GameDaoMixin {
|
||||
name: game.name,
|
||||
ruleset: game.ruleset.name,
|
||||
description: game.description,
|
||||
color: game.color,
|
||||
color: game.color.name,
|
||||
icon: game.icon,
|
||||
createdAt: game.createdAt,
|
||||
),
|
||||
@@ -135,10 +135,10 @@ class GameDao extends DatabaseAccessor<AppDatabase> with _$GameDaoMixin {
|
||||
}
|
||||
|
||||
/// Updates the color of the game with the given [gameId].
|
||||
Future<void> updateGameColor({required String gameId, required String newColor}) async {
|
||||
Future<void> updateGameColor({required String gameId, required GameColor newColor}) async {
|
||||
await (update(
|
||||
gameTable,
|
||||
)..where((g) => g.id.equals(gameId))).write(GameTableCompanion(color: Value(newColor)));
|
||||
)..where((g) => g.id.equals(gameId))).write(GameTableCompanion(color: Value(newColor.name)));
|
||||
}
|
||||
|
||||
/// Updates the icon of the game with the given [gameId].
|
||||
|
||||
@@ -126,7 +126,7 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
|
||||
name: game.name,
|
||||
ruleset: game.ruleset.name,
|
||||
description: game.description,
|
||||
color: game.color,
|
||||
color: game.color.name,
|
||||
icon: game.icon,
|
||||
createdAt: game.createdAt,
|
||||
),
|
||||
|
||||
@@ -8,7 +8,7 @@ class Game {
|
||||
final String name;
|
||||
|
gelbeinhalb marked this conversation as resolved
flixcoo
commented
Ruleset sollte nicht optional, weil das immer gebraucht wird Ruleset sollte nicht optional, weil das immer gebraucht wird
Ruleset als enum
|
||||
final Ruleset ruleset;
|
||||
|
gelbeinhalb marked this conversation as resolved
Outdated
flixcoo
commented
Description als leeren string setzen, wenn nicht übergeben Description als leeren string setzen, wenn nicht übergeben
sneeex
commented
warum findest du leeren string besser als nullable? warum findest du leeren string besser als nullable?
flixcoo
commented
Finde null sollte man nur dann verwenden, wenns halt nicht anders geht, wie z.B. bei objekten Finde null sollte man nur dann verwenden, wenns halt nicht anders geht, wie z.B. bei objekten
|
||||
final String description;
|
||||
|
gelbeinhalb marked this conversation as resolved
Outdated
flixcoo
commented
Hier lieber enum, gerne auch mit einem Hier lieber enum, gerne auch mit einem `Color.none`
sneeex
commented
warum aber nicht hex codes? warum aber nicht hex codes?
sneeex
commented
oder willst du die farben vorgeben? oder willst du die farben vorgeben?
flixcoo
commented
Ja man könnte auch hexcodes machen. Würde die Farben so oder so vorgeben unabhängig davon wie man sie speichert Ja man könnte auch hexcodes machen. Würde die Farben so oder so vorgeben unabhängig davon wie man sie speichert
gelbeinhalb
commented
würde enums maybe machen, weil man sonst im export einfach den hex code ändern könnte. Also idk ob das juckt aber 🤷♂️ würde enums maybe machen, weil man sonst im export einfach den hex code ändern könnte. Also idk ob das juckt aber 🤷♂️
|
||||
final String color;
|
||||
final GameColor color;
|
||||
|
gelbeinhalb marked this conversation as resolved
Outdated
flixcoo
commented
Hier auch mit enum arbeiten? Hier auch mit enum arbeiten?
|
||||
final String icon;
|
||||
|
||||
Game({
|
||||
@@ -34,7 +34,7 @@ class Game {
|
||||
name = json['name'],
|
||||
ruleset = Ruleset.values.firstWhere((e) => e.name == json['ruleset']),
|
||||
description = json['description'],
|
||||
color = json['color'],
|
||||
color = GameColor.values.firstWhere((e) => e.name == json['color']),
|
||||
icon = json['icon'];
|
||||
|
||||
/// Converts the Game instance to a JSON object.
|
||||
@@ -44,7 +44,7 @@ class Game {
|
||||
'name': name,
|
||||
'ruleset': ruleset.name,
|
||||
'description': description,
|
||||
'color': color,
|
||||
'color': color.name,
|
||||
'icon': icon,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ class Match {
|
||||
createdAt = DateTime.parse(json['createdAt']),
|
||||
endedAt = json['endedAt'] != null ? DateTime.parse(json['endedAt']) : null,
|
||||
name = json['name'],
|
||||
game = Game(name: '', ruleset: Ruleset.singleWinner, description: '', color: '', icon: ''), // Populated during import via DataTransferService
|
||||
game = Game(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
|
||||
notes = json['notes'] ?? '';
|
||||
|
||||
@@ -42,7 +42,7 @@ class _HomeViewState extends State<HomeView> {
|
||||
2,
|
||||
Match(
|
||||
name: 'Skeleton Match',
|
||||
game: Game(name: '', ruleset: Ruleset.singleWinner, description: '', color: '', icon: ''),
|
||||
game: Game(name: '', ruleset: Ruleset.singleWinner, description: '', color: GameColor.blue, icon: ''),
|
||||
group: Group(
|
||||
name: 'Skeleton Group',
|
||||
description: '',
|
||||
|
||||
@@ -202,7 +202,7 @@ class _CreateMatchViewState extends State<CreateMatchView> {
|
||||
name: selectedGame.$1,
|
||||
description: selectedGame.$2,
|
||||
ruleset: selectedGame.$3,
|
||||
color: '0xFF000000',
|
||||
color: GameColor.blue,
|
||||
icon: '',
|
||||
);
|
||||
} else {
|
||||
@@ -212,7 +212,7 @@ class _CreateMatchViewState extends State<CreateMatchView> {
|
||||
name: selectedGame.$1,
|
||||
description: selectedGame.$2,
|
||||
ruleset: selectedGame.$3,
|
||||
color: '0xFF000000',
|
||||
color: GameColor.blue,
|
||||
icon: '',
|
||||
);
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ class _MatchViewState extends State<MatchView> {
|
||||
4,
|
||||
Match(
|
||||
name: 'Skeleton match name',
|
||||
game: Game(name: '', ruleset: Ruleset.singleWinner, description: '', color: '', icon: ''),
|
||||
game: Game(name: '', ruleset: Ruleset.singleWinner, description: '', color: GameColor.blue, icon: ''),
|
||||
group: Group(
|
||||
name: 'Group name',
|
||||
description: '',
|
||||
|
||||
@@ -208,7 +208,7 @@ class DataTransferService {
|
||||
return Match(
|
||||
id: map['id'] as String,
|
||||
name: map['name'] as String,
|
||||
game: game ?? Game(name: 'Unknown', ruleset: Ruleset.singleWinner, description: '', color: '', icon: ''),
|
||||
game: game ?? Game(name: 'Unknown', ruleset: Ruleset.singleWinner, description: '', color: GameColor.blue, icon: ''),
|
||||
group: group,
|
||||
players: players.isNotEmpty ? players : null,
|
||||
createdAt: DateTime.parse(map['createdAt'] as String),
|
||||
|
||||
@@ -27,7 +27,7 @@ void main() {
|
||||
name: 'Chess',
|
||||
ruleset: Ruleset.singleWinner,
|
||||
description: 'A classic strategy game',
|
||||
color: '0xFF0000FF',
|
||||
color: GameColor.blue,
|
||||
icon: 'chess_icon',
|
||||
);
|
||||
testGame2 = Game(
|
||||
@@ -35,7 +35,7 @@ void main() {
|
||||
name: 'Poker',
|
||||
ruleset: Ruleset.multipleWinners,
|
||||
description: 'Card game with multiple winners',
|
||||
color: '0xFFFF0000',
|
||||
color: GameColor.red,
|
||||
icon: 'poker_icon',
|
||||
);
|
||||
testGame3 = Game(
|
||||
@@ -43,7 +43,7 @@ void main() {
|
||||
name: 'Monopoly',
|
||||
ruleset: Ruleset.highestScore,
|
||||
description: 'A board game about real estate',
|
||||
color: '0xFF000000',
|
||||
color: GameColor.orange,
|
||||
icon: '',
|
||||
);
|
||||
});
|
||||
@@ -134,7 +134,7 @@ void main() {
|
||||
|
||||
// Verifies that a game with null optional fields can be added and retrieved.
|
||||
test('addGame handles game with null optional fields', () async {
|
||||
final gameWithNulls = Game(name: 'Simple Game', ruleset: Ruleset.lowestScore, description: 'A simple game', color: '0xFF000000', icon: '');
|
||||
final gameWithNulls = Game(name: 'Simple Game', ruleset: Ruleset.lowestScore, description: 'A simple game', color: GameColor.green, icon: '');
|
||||
final result = await database.gameDao.addGame(game: gameWithNulls);
|
||||
expect(result, true);
|
||||
|
||||
@@ -143,7 +143,7 @@ void main() {
|
||||
);
|
||||
expect(fetchedGame.name, 'Simple Game');
|
||||
expect(fetchedGame.description, 'A simple game');
|
||||
expect(fetchedGame.color, '0xFF000000');
|
||||
expect(fetchedGame.color, GameColor.green);
|
||||
expect(fetchedGame.icon, isNull);
|
||||
});
|
||||
|
||||
@@ -340,20 +340,20 @@ void main() {
|
||||
|
||||
await database.gameDao.updateGameColor(
|
||||
gameId: testGame1.id,
|
||||
newColor: '0xFF00FF00',
|
||||
newColor: GameColor.green,
|
||||
);
|
||||
|
||||
final updatedGame = await database.gameDao.getGameById(
|
||||
gameId: testGame1.id,
|
||||
);
|
||||
expect(updatedGame.color, '0xFF00FF00');
|
||||
expect(updatedGame.color, GameColor.green);
|
||||
});
|
||||
|
||||
// Verifies that updateGameColor does nothing when game doesn't exist.
|
||||
test('updateGameColor does nothing for non-existent game', () async {
|
||||
await database.gameDao.updateGameColor(
|
||||
gameId: 'non-existent-id',
|
||||
newColor: '0xFF00FF00',
|
||||
newColor: GameColor.green,
|
||||
);
|
||||
|
||||
final allGames = await database.gameDao.getAllGames();
|
||||
@@ -460,7 +460,7 @@ void main() {
|
||||
name: 'Game\'s & "Special" <Name>',
|
||||
ruleset: Ruleset.multipleWinners,
|
||||
description: 'Description with émojis 🎮🎲',
|
||||
color: '0xFF000000',
|
||||
color: GameColor.purple,
|
||||
icon: '',
|
||||
);
|
||||
await database.gameDao.addGame(game: specialGame);
|
||||
@@ -479,7 +479,7 @@ void main() {
|
||||
ruleset: Ruleset.singleWinner,
|
||||
description: '',
|
||||
icon: '',
|
||||
color: '0xFF000000',
|
||||
color: GameColor.red,
|
||||
);
|
||||
await database.gameDao.addGame(game: emptyGame);
|
||||
|
||||
@@ -499,7 +499,7 @@ void main() {
|
||||
name: longString,
|
||||
description: longString,
|
||||
ruleset: Ruleset.multipleWinners,
|
||||
color: '0xFF000000',
|
||||
color: GameColor.yellow,
|
||||
icon: '',
|
||||
);
|
||||
await database.gameDao.addGame(game: longGame);
|
||||
@@ -522,7 +522,7 @@ void main() {
|
||||
);
|
||||
await database.gameDao.updateGameColor(
|
||||
gameId: testGame1.id,
|
||||
newColor: '0xFF123456',
|
||||
newColor: GameColor.teal,
|
||||
);
|
||||
await database.gameDao.updateGameDescription(
|
||||
gameId: testGame1.id,
|
||||
@@ -533,7 +533,7 @@ void main() {
|
||||
gameId: testGame1.id,
|
||||
);
|
||||
expect(updatedGame.name, 'Updated Name');
|
||||
expect(updatedGame.color, '0xFF123456');
|
||||
expect(updatedGame.color, GameColor.teal);
|
||||
expect(updatedGame.description, 'Updated Description');
|
||||
expect(updatedGame.ruleset, testGame1.ruleset);
|
||||
expect(updatedGame.icon, testGame1.icon);
|
||||
|
||||
@@ -51,7 +51,7 @@ void main() {
|
||||
description: '',
|
||||
members: [testPlayer4, testPlayer5],
|
||||
);
|
||||
testGame = Game(name: 'Test Game', ruleset: Ruleset.singleWinner, description: 'A test game', color: '0xFF000000', icon: '');
|
||||
testGame = Game(name: 'Test Game', ruleset: Ruleset.singleWinner, description: 'A test game', color: GameColor.blue, icon: '');
|
||||
testMatch1 = Match(
|
||||
name: 'First Test Match',
|
||||
game: testGame,
|
||||
|
||||
@@ -48,7 +48,7 @@ void main() {
|
||||
description: '',
|
||||
members: [testPlayer1, testPlayer2, testPlayer3],
|
||||
);
|
||||
testGame = Game(name: 'Test Game', ruleset: Ruleset.singleWinner, description: 'A test game', color: '0xFF000000', icon: '');
|
||||
testGame = Game(name: 'Test Game', ruleset: Ruleset.singleWinner, description: 'A test game', color: GameColor.blue, icon: '');
|
||||
testMatchOnlyGroup = Match(
|
||||
name: 'Test Match with Group',
|
||||
game: testGame,
|
||||
|
||||
@@ -32,7 +32,7 @@ void main() {
|
||||
testPlayer1 = Player(name: 'Alice', description: '');
|
||||
testPlayer2 = Player(name: 'Bob', description: '');
|
||||
testPlayer3 = Player(name: 'Charlie', description: '');
|
||||
testGame = Game(name: 'Test Game', ruleset: Ruleset.singleWinner, description: 'A test game', color: '0xFF000000', icon: '');
|
||||
testGame = Game(name: 'Test Game', ruleset: Ruleset.singleWinner, description: 'A test game', color: GameColor.blue, icon: '');
|
||||
testMatch1 = Match(
|
||||
name: 'Test Match 1',
|
||||
game: testGame,
|
||||
|
||||
@@ -49,8 +49,8 @@ void main() {
|
||||
name: 'Team Gamma',
|
||||
members: [testPlayer1, testPlayer3],
|
||||
);
|
||||
testGame1 = Game(name: 'Game 1', ruleset: Ruleset.singleWinner, description: 'Test game 1', color: '0xFF000000', icon: '');
|
||||
testGame2 = Game(name: 'Game 2', ruleset: Ruleset.highestScore, description: 'Test game 2', color: '0xFF000000', icon: '');
|
||||
testGame1 = Game(name: 'Game 1', ruleset: Ruleset.singleWinner, description: 'Test game 1', color: GameColor.blue, icon: '');
|
||||
testGame2 = Game(name: 'Game 2', ruleset: Ruleset.highestScore, description: 'Test game 2', color: GameColor.red, icon: '');
|
||||
});
|
||||
|
||||
await database.playerDao.addPlayersAsList(
|
||||
|
||||
Reference in New Issue
Block a user
Funktioniert das tatsächlich? Ist das getestet, dass dann auch ein ruleset (color) gefunden wird wenn du den enum speicherst?
Ja glaube das hat funktioniert