-
-
Notifications
You must be signed in to change notification settings - Fork 225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
1043 add castling method option v2 #1347
base: main
Are you sure you want to change the base?
1043 add castling method option v2 #1347
Conversation
Just for my understanding, why the v1 was closed? thanks :) |
Sure, I had attempted an implementation that modified dartchess and chessground which maybe was not the correct approach. I didn't have a great deal of time to look at it at that point so I just closed the PRs for hygeine. See here for reference lichess-org/dartchess#44 This change is limited to only the mobile app with no changes elsewhere. Not sure if this is the right approach still, happy to be told if you think there is an alternative way to come at it |
c97a375
to
b2a2c28
Compare
b2a2c28
to
c8348c0
Compare
I think this is ready to be looked at @veloce. Not sure what's going on with the tests but maybe an issue unrelated to this PR? |
A fix was pushed on the main branch. The tests need to be rerun manually. |
@Jimima can you rebase your branch on top of main so the tests pass? thank. |
@veloce done! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this. This is looking good but there are a couple of issues to address on top of the comments I've made:
- for now this settings applies only to online games, but it should also apply to puzzles, analysis, study, etc.
- the logic you added to game_controller.dart must be refactored so it can work everywhere.
- this is the time for a refactoring: we need a global
board
wrapper so we can apply settings to the whole app - a good starting point for this refactoring imo, is the private _BoardWidget which should be extracted to a public widget in another file. It should be modified to take only
BoardPrefs
andBoardSettingsOverride
(and not directly theChessboardSettings
from chessground which should be constructed inside the widget from the prefs and the optional override). - the new castling logic should be tested
|
||
// TODO: l10n | ||
String get label => switch (this) { | ||
CastlingMethod.kingOverRook => 'Move king over rook', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
translation keys already exist: look at app_en.arb: preferencesCastleByMovingOntoTheRook
.
enum CastlingMethod { | ||
kingOverRook, | ||
kingTwoSquares, | ||
either; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not support either
because it is not supported on website.
The default is kingOverRook
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Default is now either
since we'll support all three castling methods which is correctly set on line 159.
@@ -369,3 +429,11 @@ String pieceShiftMethodl10n(BuildContext context, PieceShiftMethod pieceShiftMet | |||
PieceShiftMethod.drag => context.l10n.preferencesDragPiece, | |||
PieceShiftMethod.tapTwoSquares => 'Tap two squares', | |||
}; | |||
|
|||
String castlingMethodl10n(BuildContext context, CastlingMethod castlingMethod) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duplicated l10n logic; must be defined directly in the enum to be consistent with rest of code.
Thanks for the feedback, that all makes sense. I also wonder if we are worried about premoves respecting the preference as right now they do not. I think the main site does not either but I would need to check this. |
@veloce I would appreciate another review if possible, I have made a few changes: Created a new BoardWidget component and use this in place of Chessboard where possible Some questions: I wonder if we can support either castling method in the app as it seems like an improvement over the web site. I have left it in for now but can easily remove it if you prefer. Right now I kept the refactoring light and boardPrefs is passed in as a parameter. Should the board widget be fetching the boardPrefs directly from the shared state rather than taking it as a parameter? Is there further refactoring to be done? You mentioned taking only BoardPrefs and BoardSettingsOverride but I was a bit unsure about how to make this work. Any further guidance would be gratefully received 🙂 |
Oh yes, also I will add some tests in the meantime |
…ethod-option-v2' into 1043-add-castling-method-option-v2
Will review asap.
No here I think we should stick to what the website does. It would be less error prone and easier to maintain. |
@veloce The website only gives two castling options, but the second castling option (move king onto rook) still allows you to move the king two spaces to castle. So in reality the two options on the website are
If we're going to stick to what the website does, we should make sure to do it this way or include all three options since the website options aren't explicit enough. Lichess.Website.-.Move.king.onto.rook.mov |
I wish the website would have more explicit options indeed. |
Sorry @Jimima for the delay I was focused on fixing the new theme. Could you fix the conflicts and I look at this asap. Thanks! |
Oh, by the way if we have to support the "either" as the website I'd rather have an "either" choice in the settings as you did initially and asked you to remove... sorry about that. |
Navigator.of(context).push(CastlingMethodSettingsScreen.buildRoute(context)); | ||
// pushPlatformRoute( | ||
// context, | ||
// title: context.l10n.preferencesCastleByMovingTheKingTwoSquaresOrOntoTheRook, | ||
// builder: (context) => const CastlingMethodSettingsScreen(), | ||
// ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quick question, should this be commented out or deleted?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will remove
enum CastlingMethod { | ||
kingOverRook, | ||
kingTwoSquares, | ||
either; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Default is now either
since we'll support all three castling methods which is correctly set on line 159.
switch (castlingMethod) { | ||
CastlingMethod.kingOverRook => context.l10n.preferencesCastleByMovingOntoTheRook, | ||
CastlingMethod.kingTwoSquares => context.l10n.preferencesCastleByMovingTwoSquares, | ||
CastlingMethod.either => context.l10n.preferencesBothClicksAndDrag, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we be using preferencesBothClicksAndDrag
here? If the string gets changed in the future from "Either" to "Either click or drag", then we wouldn't want the castling method string to change to that as well. I'm unsure when new strings should be created or if maybe we should rename preferencesBothClicksAndDrag
to something like preferencesEither
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah good point, not sure how to correctly handle this as there is no string currently for this. Maybe I just hard code an english string and add a comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah just hardcode it for now and leave a // TODO translate
@@ -88,6 +90,7 @@ class AnalysisBoardState extends ConsumerState<AnalysisBoard> { | |||
.onUserMove(move, shouldReplace: widget.shouldReplaceChildOnUserMove), | |||
onPromotionSelection: (role) => ref.read(ctrlProvider.notifier).onPromotionSelection(role), | |||
), | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: extra line I think?
@@ -354,6 +355,7 @@ class _BroadcastBoardState extends ConsumerState<_BroadcastBoard> { | |||
newShapeColor: boardPrefs.shapeColor.color, | |||
), | |||
), | |||
boardPrefs: boardPrefs, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: maybe we add this new line right under the size argument to keep argument order the same
lib/src/view/study/study_screen.dart
Outdated
@@ -568,6 +569,7 @@ class _StudyBoardState extends ConsumerState<_StudyBoard> { | |||
}, | |||
) | |||
: null, | |||
boardPrefs: boardPrefs, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: same here, maybe we add this new line right under the size argument to keep argument order the same
…a/lichess-mobile into 1043-add-castling-method-option-v2
@veloce thanks, and no problem at all. I am still not sure of the correct approach here, as I said, happy to take a steer from you if you think there is more to do with refactoring or whatever. I might need some guidance, however :-) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job, I think it's taking the right direction. Made a couple of small comments.
Now, this touches crucial part of the app (board for games and analysis) so this change should be tested.
It should be a widget test for the new BoardWidget
that test at least the correct behaviour of castling according to all possible settings.
You can look at existing puzzle_screen_test.dart
, game_screen_test.dart
or flutter-chessground
tests for inspiration.
switch (castlingMethod) { | ||
CastlingMethod.kingOverRook => context.l10n.preferencesCastleByMovingOntoTheRook, | ||
CastlingMethod.kingTwoSquares => context.l10n.preferencesCastleByMovingTwoSquares, | ||
CastlingMethod.either => context.l10n.preferencesBothClicksAndDrag, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah just hardcode it for now and leave a // TODO translate
static Route<dynamic> buildRoute(BuildContext context) { | ||
return buildScreenRoute( | ||
context, | ||
screen: const BoardClockPositionScreen(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong screen here.
return buildScreenRoute( | ||
context, | ||
screen: const BoardClockPositionScreen(), | ||
title: 'Clock position', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong title.
|
||
return CupertinoPageScaffold( | ||
navigationBar: const CupertinoNavigationBar(), | ||
child: SafeArea( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to have a SafeArea around ListView
.
lib/src/widgets/board.dart
Outdated
|
||
@override | ||
Widget build(BuildContext context) { | ||
final Map<Square, Square> castlingMap = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be a static const.
lib/src/widgets/board.dart
Outdated
import 'package:flutter/material.dart'; | ||
import 'package:lichess_mobile/src/model/settings/board_preferences.dart'; | ||
|
||
class BoardWidget extends StatelessWidget { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A doc comment indicating the purpose of this widget would be welcome.
lib/src/widgets/board.dart
Outdated
final BoardPrefs boardPrefs; | ||
final String fen; | ||
final Side orientation; | ||
final GameData? gameData; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here I don't think GameData
should be nullable. This board widget purpose is to wrap interactive boards only.
Perhaps renaming it to InteractiveBoardWidget
would make it even clearer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a holdover from boardTable where this was refactored out from. boardTable can take a null value which is then passed in here. I can change this but I'm not totally clear on how to handle the case where boardTable does not have gameData. Happy to take a steer here as I can see a few solutions but not sure which is best.
lib/src/widgets/board.dart
Outdated
child: Container( | ||
decoration: BoxDecoration( | ||
color: | ||
Theme.of(context).platform == TargetPlatform.iOS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the new theme we can remove these distinctions between iOS and android. So use colorScheme.surface
on both platforms.
I should have changed it in the new theme PR, but let's do it here.
Thanks for the comments I'll get to work on this |
Adds an option to change castling method. Still needs some work to tidy up but the approach is implemented. Note that it only really works for Standard variants as chess960 always uses king over rook. I think this is okay but maybe the UI could make this clearer.