Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions lib/src/model/game/archived_game.dart
Original file line number Diff line number Diff line change
Expand Up @@ -259,16 +259,34 @@ ClockData _clockDataFromPick(RequiredPick pick) {
}

Player _playerFromUserGamePick(RequiredPick pick) {
final originalName = pick('name').asStringOrNull();
return Player(
user: pick('user').asLightUserOrNull(),
name: pick('name').asStringOrNull(),
rating: pick('rating').asIntOrNull(),
name: _removeRatingFromName(originalName),
rating:
pick('rating').asIntOrNull() ?? _extractRatingFromName(originalName),
ratingDiff: pick('ratingDiff').asIntOrNull(),
aiLevel: pick('aiLevel').asIntOrNull(),
analysis: pick('analysis').letOrNull(_playerAnalysisFromPick),
);
}

int? _extractRatingFromName(String? name) {
if (name == null) return null;
final regex = RegExp(r'\((\d+)\)');
final match = regex.firstMatch(name);
if (match != null) {
return int.tryParse(match.group(1)!);
}
return null;
}

String? _removeRatingFromName(String? name) {
if (name == null) return null;
final regex = RegExp(r'\s*\(\d+\)\s*');
return name.replaceAll(regex, '');
}

PlayerAnalysis _playerAnalysisFromPick(RequiredPick pick) {
return PlayerAnalysis(
inaccuracies: pick('inaccuracy').asIntOrThrow(),
Expand Down
2 changes: 2 additions & 0 deletions lib/src/model/game/game.dart
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,12 @@ abstract mixin class BaseGame {
'Site': lichessUri('/$id').toString(),
'Date': _dateFormat.format(meta.createdAt),
'White': white.user?.name ??
white.name ??
(white.aiLevel != null
? 'Stockfish level ${white.aiLevel}'
: 'Anonymous'),
'Black': black.user?.name ??
black.name ??
(black.aiLevel != null
? 'Stockfish level ${black.aiLevel}'
: 'Anonymous'),
Expand Down
12 changes: 7 additions & 5 deletions lib/src/view/game/game_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,13 @@ class GamePlayer extends StatelessWidget {
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Icon(
player.onGame == true ? Icons.cloud : Icons.cloud_off,
color: player.onGame == true ? LichessColors.green : null,
size: 14,
),
if (player.user != null) ...[
Icon(
player.onGame == true ? Icons.cloud : Icons.cloud_off,
color: player.onGame == true ? LichessColors.green : null,
size: 14,
),
],
const SizedBox(width: 5),
if (player.user?.isPatron == true) ...[
Icon(
Expand Down