Skip to content

Commit

Permalink
Move code to widget folder
Browse files Browse the repository at this point in the history
  • Loading branch information
veloce committed Oct 21, 2024
1 parent 85a756e commit 719e860
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 75 deletions.
2 changes: 1 addition & 1 deletion lib/src/model/analysis/analysis_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import 'package:lichess_mobile/src/model/engine/work.dart';
import 'package:lichess_mobile/src/model/game/player.dart';
import 'package:lichess_mobile/src/utils/rate_limit.dart';
import 'package:lichess_mobile/src/view/engine/engine_gauge.dart';
import 'package:lichess_mobile/src/view/pgn/pgn_tree_view.dart';
import 'package:lichess_mobile/src/widgets/pgn.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';

part 'analysis_controller.freezed.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/src/view/analysis/analysis_board.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import 'package:lichess_mobile/src/model/common/chess.dart';
import 'package:lichess_mobile/src/model/common/eval.dart';
import 'package:lichess_mobile/src/model/engine/evaluation_service.dart';
import 'package:lichess_mobile/src/model/settings/board_preferences.dart';
import 'package:lichess_mobile/src/view/pgn/annotations.dart';
import 'package:lichess_mobile/src/widgets/pgn.dart';

class AnalysisBoard extends ConsumerStatefulWidget {
const AnalysisBoard(
Expand Down
2 changes: 1 addition & 1 deletion lib/src/view/analysis/tree_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:lichess_mobile/src/model/analysis/analysis_controller.dart';
import 'package:lichess_mobile/src/model/analysis/opening_service.dart';
import 'package:lichess_mobile/src/model/common/chess.dart';
import 'package:lichess_mobile/src/utils/l10n_context.dart';
import 'package:lichess_mobile/src/view/pgn/pgn_tree_view.dart';
import 'package:lichess_mobile/src/widgets/pgn.dart';

const kOpeningHeaderHeight = 32.0;

Expand Down
2 changes: 1 addition & 1 deletion lib/src/view/game/game_result_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import 'package:lichess_mobile/src/model/game/playable_game.dart';
import 'package:lichess_mobile/src/utils/l10n_context.dart';
import 'package:lichess_mobile/src/utils/navigation.dart';
import 'package:lichess_mobile/src/view/analysis/analysis_screen.dart';
import 'package:lichess_mobile/src/view/pgn/annotations.dart';
import 'package:lichess_mobile/src/widgets/buttons.dart';
import 'package:lichess_mobile/src/widgets/feedback.dart';
import 'package:lichess_mobile/src/widgets/pgn.dart';

import 'status_l10n.dart';

Expand Down
69 changes: 0 additions & 69 deletions lib/src/view/pgn/annotations.dart

This file was deleted.

68 changes: 67 additions & 1 deletion lib/src/view/pgn/pgn_tree_view.dart → lib/src/widgets/pgn.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:chessground/chessground.dart';
import 'package:collection/collection.dart';
import 'package:dartchess/dartchess.dart';
import 'package:fast_immutable_collections/fast_immutable_collections.dart';
Expand All @@ -8,14 +9,79 @@ import 'package:lichess_mobile/src/model/account/account_preferences.dart';
import 'package:lichess_mobile/src/model/analysis/analysis_preferences.dart';
import 'package:lichess_mobile/src/model/common/node.dart';
import 'package:lichess_mobile/src/model/common/uci.dart';
import 'package:lichess_mobile/src/styles/lichess_colors.dart';
import 'package:lichess_mobile/src/utils/duration.dart';
import 'package:lichess_mobile/src/utils/l10n_context.dart';
import 'package:lichess_mobile/src/utils/rate_limit.dart';
import 'package:lichess_mobile/src/widgets/adaptive_bottom_sheet.dart';
import 'package:lichess_mobile/src/widgets/buttons.dart';
import 'package:lichess_mobile/src/widgets/list.dart';

import 'annotations.dart';
const innacuracyColor = LichessColors.cyan;
const mistakeColor = Color(0xFFe69f00);
const blunderColor = Color(0xFFdf5353);

Color? nagColor(int nag) {
return switch (nag) {
1 => Colors.lightGreen,
2 => mistakeColor,
3 => Colors.teal,
4 => blunderColor,
5 => LichessColors.purple,
6 => LichessColors.cyan,
int() => null,
};
}

String moveAnnotationChar(Iterable<int> nags) {
return nags
.map(
(nag) => switch (nag) {
1 => '!',
2 => '?',
3 => '!!',
4 => '??',
5 => '!?',
6 => '?!',
int() => '',
},
)
.join('');
}

Annotation? makeAnnotation(Iterable<int>? nags) {
final nag = nags?.firstOrNull;
if (nag == null) {
return null;
}
return switch (nag) {
1 => const Annotation(
symbol: '!',
color: Colors.lightGreen,
),
3 => const Annotation(
symbol: '!!',
color: Colors.teal,
),
5 => const Annotation(
symbol: '!?',
color: Colors.purple,
),
6 => const Annotation(
symbol: '?!',
color: LichessColors.cyan,
),
2 => const Annotation(
symbol: '?',
color: mistakeColor,
),
4 => const Annotation(
symbol: '??',
color: blunderColor,
),
int() => null,
};
}

// fast replay debounce delay, same as piece animation duration, to avoid piece
// animation jank at the end of the replay
Expand Down
2 changes: 1 addition & 1 deletion test/view/analysis/analysis_screen_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import 'package:lichess_mobile/src/model/game/player.dart';
import 'package:lichess_mobile/src/model/settings/preferences_storage.dart';
import 'package:lichess_mobile/src/model/user/user.dart';
import 'package:lichess_mobile/src/view/analysis/analysis_screen.dart';
import 'package:lichess_mobile/src/view/pgn/pgn_tree_view.dart';
import 'package:lichess_mobile/src/widgets/bottom_bar_button.dart';
import 'package:lichess_mobile/src/widgets/pgn.dart';

import '../../test_provider_scope.dart';

Expand Down

0 comments on commit 719e860

Please sign in to comment.