-
-
Notifications
You must be signed in to change notification settings - Fork 189
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
feat: add board editor #865
Conversation
Okay, so after playing around a bit already, it looks to me like most of the board editor logic needs to be added directly to flutter-chessground. Not sure about the "piece-menu" for adding pieces (see above). But if we want to support adding pieces by dragging them from the menu to the board, we probably have to implement this in chessground as well...? |
Quick feedback: if we have to modify chessground to support this, the changes should be the simplest and the lightest possible. Like we should only add "generic" (optional) handlers. Something like: class BoardEditorOptions {
/// Enable board editor mode
final bool enable;
/// Callback to add or remove a piece on this square id.
final void Function(SquareId squareId)? onTogglePiece;
final void Function(SquareId squareId)? onRemovePiece;
...
} This is already a significant change because we have to implement the "board editor" logic in the pointer event listener handlers. Don't know if we can handle drag to board feature like that, but I'd say it is not mandatory to support this so we can figure it out later. Anyway, changes in chessground shouldn't be more than that. |
Thanks for the quick reply! However, after playing around with the code a bit yesterday, I'm not a 100% sure if it's really the best idea to modify the
So maybe adding a separate |
@veloce I added a quick proof of concept implementing a basic board editor (minus adding new pieces) by adding a new |
Yeah totally, a separate Now there is still the question of the chessground API. I haven't had much time to think about it, but I still think the The reason behind this is that we don't want to maintain a full-fledged editor in an external package. Because there is no limit in terms of what a board editor can be in terms of feature, the majority of the UI should be implemented in the app and chessground should just take care of what is going on inside the board. |
Thanks for taking a look, I really appreciate the quick feedback! Yeah I agree with that, the I'd suggest that I add the missing API described above and clean up and document the code a bit more (maybe reduce some more duplication). Then when I mark it as "Ready To Review", you can take a closer look and we can continue the discussion over at |
@tom-anders I think you can start working on this using a local chessground plugin based on current I'll publish the 4.0.0 version later when I had the chance to test this. |
Sure! |
@veloce There are a lot of API breaks to be fixed when updating to the main branch, so I'll think for now I'll stick with a commit before those breaks. Let me know when the API breaks are fixed in the |
Okay, so here's what I got so far. The code is not cleaned up yet, but I think it has all the basic feature we need. Right now, I'm mainly looking for design feedback:
board_editor.webm |
I'm ok if you fix the API breaks in this PR. These are only name changes so it should be straightforward to fix. |
Thanks for your work @tom-anders , it looks great already! Here's my feedback:
|
Thanks for the feedback, ready for code review now!
Yeah I'm using plain
Yep, wrong icon, fixed now
Done, I scaled down the icons a bit so that they match the piece size.
It uses the "menu" icon now and has been moved to the bottom bar. |
That is not the material color palette I meant, sorry for the confusion. What you want to use is the ColorScheme. |
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.
I don't understand all these changes in analysis_controller
. The board editor isn't supposed to make a difference in analysis screen.
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.
Huh, not sure what went wrong here. There are some changes expected due to the chessground API breaks, but maybe I messed up during the rebase. I'll take a look
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.
Definitely some kind of merge mistake, the changes are only part of the first commit that fixes the chessground API breaks. Sorry about that! Will fix later this evening.
In the meantime, the second commit (feat: add board editor) seems fine, so I think you can already review that one
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.
Fixed, sorry again for the confusion!
I just published chessground 4.0.0 to pub.dev @tom-anders . I think you want to update your PR with that version. There are other breaking changes, sorry for that, but it should not be too hard to fix them.
|
39b5e74
to
9a4670d
Compare
9a4670d
to
d300dee
Compare
Nice work! Uses chessground 4.0.0 now, fixing all API breaks. Also rebased against |
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.
Outstanding work, thank you very much.
@override | ||
Widget build(BuildContext context, WidgetRef ref) { | ||
final pgn = ref.watch(boardEditorControllerProvider).pgn; | ||
final orientation = ref.read(boardEditorControllerProvider).orientation; |
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 be ref.watch
|
||
String get fen => _setup.fen; | ||
|
||
String? get pgn { |
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.
It should be made clear in a doc comment that only valid position PGN is returned, and it returns null
if not valid.
@@ -37,7 +37,7 @@ class UciCharPair with _$UciCharPair { | |||
String.fromCharCode(35 + f), | |||
String.fromCharCode( | |||
p != null | |||
? 35 + 64 + 8 * _promotionRoles.indexOf(p) + squareFile(t) | |||
? 35 + 64 + 8 * _promotionRoles.indexOf(p) + t.file.value |
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 File
extension type implements int
, unwrapping .value
is not necessary.
), | ||
pointerMode: ref.watch(boardEditorControllerProvider).editorPointerMode, | ||
onDiscardedPiece: | ||
ref.read(boardEditorControllerProvider.notifier).discardPiece, |
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.
One should not use ref.read
in build()
methods. Also it is better to put it at the beginning of build()
so that we know the provider dependencies of a widget.
} | ||
|
||
Future<BoardEditorController> setupBoardEditor(WidgetTester tester) async { | ||
final boardEditorController = BoardEditorController(); |
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.
It is not ideal to construct directly a notifier instance. Testing providers should be done according to Riverpod's doc:
https://riverpod.dev/docs/essentials/testing
Creating/reading providers should always go through a Container
.
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.
Done here: 86dd3fb
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, will keep that in mind for the next time
Thanks again for the quick and valuable feedback! Implementing this was really fun |
Hey @tom-anders great work on this again.
|
Yeah, what's still missing is a "Load Position" menu, where you can set the board to a specific opening or endgame position. We could also have a "Clear Board" entry in that list (I think the old app does as well).
Yeah sounds useful, shouldn't be too hard to implement. I'll open Github issues for both of these features, I think these are "Good first issue" candidates |
Closes #458
Opening an early draft PR to let people know I'm working on this.
Functionality that should definitely be part of this PR IMO:
Functionality that we could add later:
@veloce Feedback would be welcome, if you find the time :)