From ec9ec27c05f0e5905dcecde0161b3661fe32fd6f Mon Sep 17 00:00:00 2001 From: Nikolas Rimikis Date: Sat, 30 Oct 2021 18:22:24 +0200 Subject: [PATCH] Clean up dead code (#363) * Clean up dead code We had a lot of old code-behind comments. I've removed them for better readability of the code and easier maintenance. (when searching stiff in the code, it sometimes brings you to dead code ...) Also, the methods on the gamePage observing the routes does only log "/" as we don't use namedRoutes. * Update position.dart Co-authored-by: Calcitem --- src/ui/flutter_app/lib/mill/position.dart | 15 +- .../lib/screens/game_page/game_page.dart | 196 ------------------ .../point_style_modal.dart | 9 - .../lib/shared/painters/board_painter.dart | 4 +- .../lib/shared/painters/pieces_painter.dart | 45 +--- 5 files changed, 12 insertions(+), 257 deletions(-) diff --git a/src/ui/flutter_app/lib/mill/position.dart b/src/ui/flutter_app/lib/mill/position.dart index 5ef5dfd6..4c7b7314 100644 --- a/src/ui/flutter_app/lib/mill/position.dart +++ b/src/ui/flutter_app/lib/mill/position.dart @@ -161,8 +161,7 @@ class Position { recorder = GameRecorder(lastPositionWithRemove: fen()); } - /// fen() returns a FEN representation of the position. - + /// Return a FEN representation of the position. String fen() { final buffer = StringBuffer(); @@ -1074,11 +1073,6 @@ class Position { Future gotoHistory(HistoryMove move, [int? index]) async { final int moveIndex = _gotoHistoryIndex(move, index); - //if (recorder == null) { - // debugPrint("[goto] recorder is null."); - // return "null"; - //} - if (recorder.cur == moveIndex) { debugPrint("[goto] cur is equal to moveIndex."); return "equal"; @@ -1169,10 +1163,7 @@ class Position { final buffer = StringBuffer(); int posAfterLastRemove = 0; - //debugPrint("recorder.movesCount = ${recorder.movesCount}"); - for (i = recorder.movesCount - 1; i >= 0; i--) { - //if (recorder.moveAt(i).type == MoveType.remove) break; if (recorder.moveAt(i).move[0] == '-') break; } @@ -1180,18 +1171,14 @@ class Position { posAfterLastRemove = i + 1; } - //debugPrint("[movesSinceLastRemove] posAfterLastRemove = $posAfterLastRemove"); - for (int i = posAfterLastRemove; i < recorder.movesCount; i++) { buffer.write(" ${recorder.moveAt(i).move}"); } final String moves = buffer.toString(); - //debugPrint("moves = $moves"); final idx = moves.indexOf('-('); if (idx != -1) { - //debugPrint("moves[$idx] is -("); assert(false); } diff --git a/src/ui/flutter_app/lib/screens/game_page/game_page.dart b/src/ui/flutter_app/lib/screens/game_page/game_page.dart index 313bba11..5d9fa19f 100644 --- a/src/ui/flutter_app/lib/screens/game_page/game_page.dart +++ b/src/ui/flutter_app/lib/screens/game_page/game_page.dart @@ -16,8 +16,6 @@ along with this program. If not, see . */ -//import 'dart:typed_data'; - import 'dart:async'; import 'package:fluentui_system_icons/fluentui_system_icons.dart'; @@ -39,7 +37,6 @@ import 'package:sanmill/shared/dialog.dart'; import 'package:sanmill/shared/picker.dart'; import 'package:sanmill/shared/snackbar.dart'; import 'package:sanmill/shared/theme/app_theme.dart'; -//import 'package:screen_recorder/screen_recorder.dart'; import 'package:stack_trace/stack_trace.dart'; part 'package:sanmill/screens/game_page/board.dart'; @@ -71,12 +68,6 @@ class _GamePageState extends State bool isReady = false; bool isGoingToHistory = false; late Timer timer; - /* - ScreenRecorderController screenRecorderController = ScreenRecorderController( - pixelRatio: 1.0, - skipFramesBetweenCaptures: 0, - ); - */ late AnimationController _animationController; late Animation animation; bool disposed = false; @@ -487,12 +478,6 @@ class _GamePageState extends State position.recorder.prune(); position.recorder.moveIn(m, position); - /* - if (LocalDatabaseService.preferences.screenReaderSupport && m.notation != null) { - showSnackBar(context, S.of(context).human + ": " + m.notation!); - } - */ - setState(() {}); if (position.winner == PieceColor.nobody) { @@ -696,88 +681,6 @@ class _GamePageState extends State }); } - /* - onStartRecordingButtonPressed() async { - Navigator.pop(context); - showDialog( - context: context, - barrierDismissible: true, - builder: (context) => AlertDialog( - title: Text( - S.of(context).appName, - style: TextStyle( - color: AppTheme.dialogTitleColor, - fontSize: LocalDatabaseService.display.fontSize + 4, - ), - ), - content: Column( - mainAxisSize: MainAxisSize.min, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - S.of(context).experimental, - style: TextStyle( - fontSize: LocalDatabaseService.display.fontSize, - ), - ), - ], - ), - actions: [ - TextButton( - child: Text( - S.of(context).ok, - style: TextStyle( - fontSize: LocalDatabaseService.display.fontSize, - ), - ), - onPressed: () => Navigator.pop(context), - ), - ], - ), - ); - - screenRecorderController.start(); - showSnackBar( - S.of(context).recording, - duration: Duration(seconds: 1 << 31), - ); - } - - onStopRecordingButtonPressed() async { - Navigator.pop(context); - screenRecorderController.stop(); - showSnackBar( - S.of(context).stopRecording, - duration: Duration(seconds: 2), - ); - } - - onShowRecordingButtonPressed() async { - Navigator.pop(context); - showSnackBar( - S.of(context).pleaseWait, - duration: Duration(seconds: 1 << 31), - ); - var gif = await screenRecorderController.export(); - ScaffoldMessenger.of(context).hideCurrentSnackBar(); - if (gif == null) { - showSnackBar(S.of(context).noRecording); - return; - } - - var image = Image.memory( - Uint8List.fromList(gif), - ); - - showDialog( - context: context, - builder: (context) { - return AlertDialog(backgroundColor: Colors.black, content: image); - }, - ); - } - */ - Future onAutoReplayButtonPressed() async { Navigator.pop(context); @@ -831,56 +734,6 @@ class _GamePageState extends State ), onPressed: () => Navigator.pop(context), ), - /* - SizedBox(height: AppTheme.sizedBoxHeight), - LocalDatabaseService.experimentsEnabled - ? SimpleDialogOption( - child: Text( - S.of(context).startRecording, - style: AppTheme.simpleDialogOptionTextStyle, - textAlign: TextAlign.center, - ), - onPressed: onStartRecordingButtonPressed, - ) - : SizedBox(height: 1), - LocalDatabaseService.experimentsEnabled - ? SizedBox(height: AppTheme.sizedBoxHeight) - : SizedBox(height: 1), - LocalDatabaseService.experimentsEnabled - ? SimpleDialogOption( - child: Text( - S.of(context).stopRecording, - style: AppTheme.simpleDialogOptionTextStyle, - textAlign: TextAlign.center, - ), - onPressed: onStopRecordingButtonPressed, - ) - : SizedBox(height: 1), - LocalDatabaseService.experimentsEnabled - ? SizedBox(height: AppTheme.sizedBoxHeight) - : SizedBox(height: 1), - LocalDatabaseService.experimentsEnabled - ? SimpleDialogOption( - child: Text( - S.of(context).showRecording, - style: AppTheme.simpleDialogOptionTextStyle, - textAlign: TextAlign.center, - ), - onPressed: onShowRecordingButtonPressed, - ) - : SizedBox(height: 1), - */ - /* - SizedBox(height: AppTheme.sizedBoxHeight), - SimpleDialogOption( - child: Text( - S.of(context).autoReplay, - style: AppTheme.simpleDialogOptionTextStyle, - textAlign: TextAlign.center, - ), - onPressed: onAutoReplayButtonPressed, - ), - */ ], ), ), @@ -1017,17 +870,6 @@ class _GamePageState extends State if (mounted) { final pos = gameInstance.position; - /* - String us = ""; - String them = ""; - if (pos.side == PieceColor.white) { - us = S.of(context).player1; - them = S.of(context).player2; - } else if (pos.side == PieceColor.black) { - us = S.of(context).player2; - them = S.of(context).player1; - } - */ late final String text; final lastEffectiveMove = pos.recorder.lastEffectiveMove; @@ -1195,8 +1037,6 @@ class _GamePageState extends State } String getGameOverReasonString(GameOverReason? reason, String? winner) { - //String winnerStr = - // winner == Color.white ? S.of(context).white : S.of(context).black; final String loserStr = winner == PieceColor.white ? S.of(context).black : S.of(context).white; @@ -1829,18 +1669,6 @@ class _GamePageState extends State ], ), ), - /* - body: Column(children: [ - header, - ScreenRecorder( - width: MediaQuery.of(context).size.width, - height: MediaQuery.of(context).size.width, - controller: screenRecorderController, - child: board, - ), - toolbar - ]), - */ ); } @@ -1854,28 +1682,4 @@ class _GamePageState extends State LocalDatabaseService.listenPreferences.removeListener(_refeshEngine); super.dispose(); } - - @override - void didPush() { - final route = ModalRoute.of(context)!.settings.name; - debugPrint('$_tag Game Page didPush route: $route'); - } - - @override - void didPopNext() { - final route = ModalRoute.of(context)!.settings.name; - debugPrint('$_tag Game Page didPopNext route: $route'); - } - - @override - void didPushNext() { - final route = ModalRoute.of(context)!.settings.name; - debugPrint('$_tag Game Page didPushNext route: $route'); - } - - @override - void didPop() { - final route = ModalRoute.of(context)!.settings.name; - debugPrint('$_tag Game Page didPop route: $route'); - } } diff --git a/src/ui/flutter_app/lib/screens/personalization_settings/point_style_modal.dart b/src/ui/flutter_app/lib/screens/personalization_settings/point_style_modal.dart index eb34fc91..417a96aa 100644 --- a/src/ui/flutter_app/lib/screens/personalization_settings/point_style_modal.dart +++ b/src/ui/flutter_app/lib/screens/personalization_settings/point_style_modal.dart @@ -49,15 +49,6 @@ class _PointStyleModal extends StatelessWidget { value: 1, onChanged: onChanged, ), - /* - RadioListTile( - activeColor: AppTheme.switchListTileActiveColor, - title: const Text(S.of(context).hollow), - groupValue: LocalDatabaseService.display.pointStyle, - value: 2, - onChanged: callback, - ), - */ ], ), ); diff --git a/src/ui/flutter_app/lib/shared/painters/board_painter.dart b/src/ui/flutter_app/lib/shared/painters/board_painter.dart index 30a3811a..75ff574b 100644 --- a/src/ui/flutter_app/lib/shared/painters/board_painter.dart +++ b/src/ui/flutter_app/lib/shared/painters/board_painter.dart @@ -137,7 +137,7 @@ class BoardPainter extends PiecesBasePainter { final offset = (boardWidth - squareWidth * 6) / 4; - /* Show notations "a b c d e f" on board */ + // Show notations "a b c d e f" on board if (LocalDatabaseService.preferences.developerMode) { notationPainterV.paint( @@ -157,7 +157,7 @@ class BoardPainter extends PiecesBasePainter { ), ); - /* Show notations "1 2 3 4 5 6 7" on board */ + // Show notations "1 2 3 4 5 6 7" on board notationPainterH.paint( canvas, diff --git a/src/ui/flutter_app/lib/shared/painters/pieces_painter.dart b/src/ui/flutter_app/lib/shared/painters/pieces_painter.dart index 9f32740f..f7c67fb6 100644 --- a/src/ui/flutter_app/lib/shared/painters/pieces_painter.dart +++ b/src/ui/flutter_app/lib/shared/painters/pieces_painter.dart @@ -93,7 +93,6 @@ class PiecesPainter extends PiecesBasePainter { int focusIndex = invalidIndex, int blurIndex = invalidIndex, }) { - // final left = offsetX; final top = offsetY; @@ -111,8 +110,7 @@ class PiecesPainter extends PiecesBasePainter { if (piece == Piece.noPiece) continue; - final pos = - Offset(left+ squareWidth* col, top+ squareWidth * row); + final pos = Offset(left + squareWidth * col, top + squareWidth * row); final animated = focusIndex == index; piecesToDraw @@ -129,19 +127,11 @@ class PiecesPainter extends PiecesBasePainter { paint.style = PaintingStyle.fill; - /* - final textStyle = TextStyle( - color: ColorConst.PieceTextColor, - fontSize: pieceSide * 0.8, - height: 1.0, - ); - */ - for (final pps in piecesToDraw) { - final pieceRadius = pieceWidth/ 2; + final pieceRadius = pieceWidth / 2; final pieceInnerRadius = pieceRadius * 0.99; - final animatedPieceRadius = animatedPieceWidth/ 2; + final animatedPieceRadius = animatedPieceWidth / 2; final animatedPieceInnerRadius = animatedPieceRadius * 0.99; // Draw Border of Piece @@ -189,27 +179,10 @@ class PiecesPainter extends PiecesBasePainter { // draw focus and blur position - final int row = focusIndex~/ 7; + final int row = focusIndex ~/ 7; final int column = focusIndex % 7; if (focusIndex != invalidIndex) { - /* - focusPositionColor = Color.fromARGB( - (LocalDatabaseService.colorSettings.whitePieceColor).alpha + - LocalDatabaseService.colorSettings.blackPieceColor).alpha) ~/ - 2, - (LocalDatabaseService.colorSettings.whitePieceColor).red + - LocalDatabaseService.colorSettings.blackPieceColor).red) ~/ - 2, - (LocalDatabaseService.colorSettings.whitePieceColor).green + - LocalDatabaseService.colorSettings.blackPieceColor).green) ~/ - 2, - (LocalDatabaseService.colorSettings.whitePieceColor).blue + - LocalDatabaseService.colorSettings.blackPieceColor).blue) ~/ - 2) - .withOpacity(0.5); - */ - focusPositionColor = LocalDatabaseService.colorSettings.pieceHighlightColor; @@ -218,22 +191,22 @@ class PiecesPainter extends PiecesBasePainter { paint.strokeWidth = 2; canvas.drawCircle( - Offset(left+ column * squareWidth, top+ row * squareWidth), - animatedPieceWidth/ 2, + Offset(left + column * squareWidth, top + row * squareWidth), + animatedPieceWidth / 2, paint, ); } if (blurIndex != invalidIndex) { - final row = blurIndex~/ 7; + final row = blurIndex ~/ 7; final column = blurIndex % 7; paint.color = blurPositionColor; paint.style = PaintingStyle.fill; canvas.drawCircle( - Offset(left+ column * squareWidth, top+ row * squareWidth), - animatedPieceWidth/ 2 * 0.8, + Offset(left + column * squareWidth, top + row * squareWidth), + animatedPieceWidth / 2 * 0.8, paint, ); }