color is now a required game parameter

This commit is contained in:
gelbeinhalb
2026-01-23 11:08:11 +01:00
parent 6006c6d3f7
commit 55f5aac4e2
11 changed files with 51 additions and 61 deletions

View File

@@ -20,7 +20,7 @@ class GameDao extends DatabaseAccessor<AppDatabase> with _$GameDaoMixin {
name: row.name,
ruleset: row.ruleset,
description: row.description,
color: row.color != null ? int.tryParse(row.color!) : null,
color: row.color,
icon: row.icon,
createdAt: row.createdAt,
),
@@ -37,7 +37,7 @@ class GameDao extends DatabaseAccessor<AppDatabase> with _$GameDaoMixin {
name: result.name,
ruleset: result.ruleset,
description: result.description,
color: result.color != null ? int.tryParse(result.color!) : null,
color: result.color,
icon: result.icon,
createdAt: result.createdAt,
);
@@ -54,7 +54,7 @@ class GameDao extends DatabaseAccessor<AppDatabase> with _$GameDaoMixin {
name: game.name,
ruleset: game.ruleset ?? '',
description: Value(game.description),
color: Value(game.color?.toString()),
color: game.color,
icon: Value(game.icon),
createdAt: game.createdAt,
),
@@ -80,7 +80,7 @@ class GameDao extends DatabaseAccessor<AppDatabase> with _$GameDaoMixin {
name: game.name,
ruleset: game.ruleset ?? '',
description: Value(game.description),
color: Value(game.color?.toString()),
color: game.color,
icon: Value(game.icon),
createdAt: game.createdAt,
),
@@ -142,10 +142,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 int? newColor,
required String newColor,
}) async {
await (update(gameTable)..where((g) => g.id.equals(gameId))).write(
GameTableCompanion(color: Value(newColor?.toString())),
GameTableCompanion(color: Value(newColor)),
);
}

View File

@@ -129,7 +129,7 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
name: game.name,
ruleset: game.ruleset ?? '',
description: Value(game.description),
color: Value(game.color?.toString()),
color: game.color,
icon: Value(game.icon),
createdAt: game.createdAt,
),

View File

@@ -682,9 +682,9 @@ class $GameTableTable extends GameTable
late final GeneratedColumn<String> color = GeneratedColumn<String>(
'color',
aliasedName,
true,
false,
type: DriftSqlType.string,
requiredDuringInsert: false,
requiredDuringInsert: true,
);
static const VerificationMeta _iconMeta = const VerificationMeta('icon');
@override
@@ -763,6 +763,8 @@ class $GameTableTable extends GameTable
_colorMeta,
color.isAcceptableOrUnknown(data['color']!, _colorMeta),
);
} else if (isInserting) {
context.missing(_colorMeta);
}
if (data.containsKey('icon')) {
context.handle(
@@ -806,7 +808,7 @@ class $GameTableTable extends GameTable
color: attachedDatabase.typeMapping.read(
DriftSqlType.string,
data['${effectivePrefix}color'],
),
)!,
icon: attachedDatabase.typeMapping.read(
DriftSqlType.string,
data['${effectivePrefix}icon'],
@@ -829,7 +831,7 @@ class GameTableData extends DataClass implements Insertable<GameTableData> {
final String name;
final String ruleset;
final String? description;
final String? color;
final String color;
final String? icon;
final DateTime createdAt;
const GameTableData({
@@ -837,7 +839,7 @@ class GameTableData extends DataClass implements Insertable<GameTableData> {
required this.name,
required this.ruleset,
this.description,
this.color,
required this.color,
this.icon,
required this.createdAt,
});
@@ -850,9 +852,7 @@ class GameTableData extends DataClass implements Insertable<GameTableData> {
if (!nullToAbsent || description != null) {
map['description'] = Variable<String>(description);
}
if (!nullToAbsent || color != null) {
map['color'] = Variable<String>(color);
}
map['color'] = Variable<String>(color);
if (!nullToAbsent || icon != null) {
map['icon'] = Variable<String>(icon);
}
@@ -868,9 +868,7 @@ class GameTableData extends DataClass implements Insertable<GameTableData> {
description: description == null && nullToAbsent
? const Value.absent()
: Value(description),
color: color == null && nullToAbsent
? const Value.absent()
: Value(color),
color: Value(color),
icon: icon == null && nullToAbsent ? const Value.absent() : Value(icon),
createdAt: Value(createdAt),
);
@@ -886,7 +884,7 @@ class GameTableData extends DataClass implements Insertable<GameTableData> {
name: serializer.fromJson<String>(json['name']),
ruleset: serializer.fromJson<String>(json['ruleset']),
description: serializer.fromJson<String?>(json['description']),
color: serializer.fromJson<String?>(json['color']),
color: serializer.fromJson<String>(json['color']),
icon: serializer.fromJson<String?>(json['icon']),
createdAt: serializer.fromJson<DateTime>(json['createdAt']),
);
@@ -899,7 +897,7 @@ class GameTableData extends DataClass implements Insertable<GameTableData> {
'name': serializer.toJson<String>(name),
'ruleset': serializer.toJson<String>(ruleset),
'description': serializer.toJson<String?>(description),
'color': serializer.toJson<String?>(color),
'color': serializer.toJson<String>(color),
'icon': serializer.toJson<String?>(icon),
'createdAt': serializer.toJson<DateTime>(createdAt),
};
@@ -910,7 +908,7 @@ class GameTableData extends DataClass implements Insertable<GameTableData> {
String? name,
String? ruleset,
Value<String?> description = const Value.absent(),
Value<String?> color = const Value.absent(),
String? color,
Value<String?> icon = const Value.absent(),
DateTime? createdAt,
}) => GameTableData(
@@ -918,7 +916,7 @@ class GameTableData extends DataClass implements Insertable<GameTableData> {
name: name ?? this.name,
ruleset: ruleset ?? this.ruleset,
description: description.present ? description.value : this.description,
color: color.present ? color.value : this.color,
color: color ?? this.color,
icon: icon.present ? icon.value : this.icon,
createdAt: createdAt ?? this.createdAt,
);
@@ -971,7 +969,7 @@ class GameTableCompanion extends UpdateCompanion<GameTableData> {
final Value<String> name;
final Value<String> ruleset;
final Value<String?> description;
final Value<String?> color;
final Value<String> color;
final Value<String?> icon;
final Value<DateTime> createdAt;
final Value<int> rowid;
@@ -990,13 +988,14 @@ class GameTableCompanion extends UpdateCompanion<GameTableData> {
required String name,
required String ruleset,
this.description = const Value.absent(),
this.color = const Value.absent(),
required String color,
this.icon = const Value.absent(),
required DateTime createdAt,
this.rowid = const Value.absent(),
}) : id = Value(id),
name = Value(name),
ruleset = Value(ruleset),
color = Value(color),
createdAt = Value(createdAt);
static Insertable<GameTableData> custom({
Expression<String>? id,
@@ -1025,7 +1024,7 @@ class GameTableCompanion extends UpdateCompanion<GameTableData> {
Value<String>? name,
Value<String>? ruleset,
Value<String?>? description,
Value<String?>? color,
Value<String>? color,
Value<String?>? icon,
Value<DateTime>? createdAt,
Value<int>? rowid,
@@ -3665,7 +3664,7 @@ typedef $$GameTableTableCreateCompanionBuilder =
required String name,
required String ruleset,
Value<String?> description,
Value<String?> color,
required String color,
Value<String?> icon,
required DateTime createdAt,
Value<int> rowid,
@@ -3676,7 +3675,7 @@ typedef $$GameTableTableUpdateCompanionBuilder =
Value<String> name,
Value<String> ruleset,
Value<String?> description,
Value<String?> color,
Value<String> color,
Value<String?> icon,
Value<DateTime> createdAt,
Value<int> rowid,
@@ -3910,7 +3909,7 @@ class $$GameTableTableTableManager
Value<String> name = const Value.absent(),
Value<String> ruleset = const Value.absent(),
Value<String?> description = const Value.absent(),
Value<String?> color = const Value.absent(),
Value<String> color = const Value.absent(),
Value<String?> icon = const Value.absent(),
Value<DateTime> createdAt = const Value.absent(),
Value<int> rowid = const Value.absent(),
@@ -3930,7 +3929,7 @@ class $$GameTableTableTableManager
required String name,
required String ruleset,
Value<String?> description = const Value.absent(),
Value<String?> color = const Value.absent(),
required String color,
Value<String?> icon = const Value.absent(),
required DateTime createdAt,
Value<int> rowid = const Value.absent(),

View File

@@ -5,7 +5,7 @@ class GameTable extends Table {
TextColumn get name => text()();
TextColumn get ruleset => text()();
TextColumn get description => text().nullable()();
TextColumn get color => text().nullable()();
TextColumn get color => text()();
TextColumn get icon => text().nullable()();
DateTimeColumn get createdAt => dateTime()();

View File

@@ -7,7 +7,7 @@ class Game {
final String name;
final String? ruleset;
final String? description;
final int? color;
final String color;
final String? icon;
Game({
@@ -16,7 +16,7 @@ class Game {
required this.name,
this.ruleset,
this.description,
this.color,
required this.color,
this.icon,
}) : id = id ?? const Uuid().v4(),
createdAt = createdAt ?? clock.now();

View File

@@ -202,6 +202,7 @@ class _CreateMatchViewState extends State<CreateMatchView> {
name: selectedGame.$1,
description: selectedGame.$2,
ruleset: selectedGame.$3.name,
color: '0xFF000000',
);
} else {
// Use the selected game from the list
@@ -210,6 +211,7 @@ class _CreateMatchViewState extends State<CreateMatchView> {
name: selectedGame.$1,
description: selectedGame.$2,
ruleset: selectedGame.$3.name,
color: '0xFF000000',
);
}
// Add the game to the database if it doesn't exist

View File

@@ -26,7 +26,7 @@ void main() {
name: 'Chess',
ruleset: 'winner.single',
description: 'A classic strategy game',
color: 0xFF0000FF,
color: '0xFF0000FF',
icon: 'chess_icon',
);
testGame2 = Game(
@@ -34,13 +34,14 @@ void main() {
name: 'Poker',
ruleset: 'Texas Hold\'em rules',
description: 'winner.multiple',
color: 0xFFFF0000,
color: '0xFFFF0000',
icon: 'poker_icon',
);
testGame3 = Game(
id: 'game3',
name: 'Monopoly',
description: 'A board game about real estate',
color: '0xFF000000',
);
});
});
@@ -130,7 +131,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');
final gameWithNulls = Game(name: 'Simple Game', color: '0xFF000000');
final result = await database.gameDao.addGame(game: gameWithNulls);
expect(result, true);
@@ -139,7 +140,7 @@ void main() {
);
expect(fetchedGame.name, 'Simple Game');
expect(fetchedGame.description, isNull);
expect(fetchedGame.color, isNull);
expect(fetchedGame.color, '0xFF000000');
expect(fetchedGame.icon, isNull);
});
@@ -336,35 +337,20 @@ void main() {
await database.gameDao.updateGameColor(
gameId: testGame1.id,
newColor: 0xFF00FF00,
newColor: '0xFF00FF00',
);
final updatedGame = await database.gameDao.getGameById(
gameId: testGame1.id,
);
expect(updatedGame.color, 0xFF00FF00);
});
// Verifies that updateGameColor can set the color to null.
test('updateGameColor can set color to null', () async {
await database.gameDao.addGame(game: testGame1);
await database.gameDao.updateGameColor(
gameId: testGame1.id,
newColor: null,
);
final updatedGame = await database.gameDao.getGameById(
gameId: testGame1.id,
);
expect(updatedGame.color, isNull);
expect(updatedGame.color, '0xFF00FF00');
});
// 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: '0xFF00FF00',
);
final allGames = await database.gameDao.getAllGames();
@@ -470,6 +456,7 @@ void main() {
final specialGame = Game(
name: 'Game\'s & "Special" <Name>',
description: 'Description with émojis 🎮🎲',
color: '0xFF000000',
);
await database.gameDao.addGame(game: specialGame);
@@ -487,6 +474,7 @@ void main() {
ruleset: '',
description: '',
icon: '',
color: '0xFF000000',
);
await database.gameDao.addGame(game: emptyGame);
@@ -506,6 +494,7 @@ void main() {
name: longString,
description: longString,
ruleset: longString,
color: '0xFF000000',
);
await database.gameDao.addGame(game: longGame);
@@ -527,7 +516,7 @@ void main() {
);
await database.gameDao.updateGameColor(
gameId: testGame1.id,
newColor: 0xFF123456,
newColor: '0xFF123456',
);
await database.gameDao.updateGameDescription(
gameId: testGame1.id,
@@ -538,7 +527,7 @@ void main() {
gameId: testGame1.id,
);
expect(updatedGame.name, 'Updated Name');
expect(updatedGame.color, 0xFF123456);
expect(updatedGame.color, '0xFF123456');
expect(updatedGame.description, 'Updated Description');
expect(updatedGame.ruleset, testGame1.ruleset);
expect(updatedGame.icon, testGame1.icon);

View File

@@ -48,7 +48,7 @@ void main() {
name: 'Test Group 2',
members: [testPlayer4, testPlayer5],
);
testGame = Game(name: 'Test Game');
testGame = Game(name: 'Test Game', color: '0xFF000000');
testMatch1 = Match(
name: 'First Test Match',
game: testGame,

View File

@@ -46,7 +46,7 @@ void main() {
name: 'Test Group',
members: [testPlayer1, testPlayer2, testPlayer3],
);
testGame = Game(name: 'Test Game');
testGame = Game(name: 'Test Game', color: '0xFF000000');
testMatchOnlyGroup = Match(
name: 'Test Match with Group',
game: testGame,

View File

@@ -31,7 +31,7 @@ void main() {
testPlayer1 = Player(name: 'Alice');
testPlayer2 = Player(name: 'Bob');
testPlayer3 = Player(name: 'Charlie');
testGame = Game(name: 'Test Game');
testGame = Game(name: 'Test Game', color: '0xFF000000');
testMatch1 = Match(
name: 'Test Match 1',
game: testGame,

View File

@@ -48,8 +48,8 @@ void main() {
name: 'Team Gamma',
members: [testPlayer1, testPlayer3],
);
testGame1 = Game(name: 'Game 1');
testGame2 = Game(name: 'Game 2');
testGame1 = Game(name: 'Game 1', color: '0xFF000000');
testGame2 = Game(name: 'Game 2', color: '0xFF000000');
});
await database.playerDao.addPlayersAsList(