oakmac / chessboard2

chessboard.js v2
ISC License
81 stars 7 forks source link

question about analysis arrows #40

Closed oakmac closed 1 year ago

oakmac commented 1 year ago

I received this email with questions about chessboard2. I wanted to reply publicly for the benefit of others who might have similar questions.


Hi Chris,

I’m looking into using chessboard2 in an app I’m working on and analysis arrows are really important for its functionality.

When I browsed through the docs I did not see them documented and even the references to their methods from https://chessboardjs.com/v2/examples#3008-analysis-arrows did not lead anywhere.

A few questions if I may:

  1. How stable is the current version?
  2. Any idea when a release version will be available?
  3. How are the arrows and circles stored internally as i would like to save them along with the game?
  4. Any recommended approach to drawing them using the mouse rather than programatically? onDrag…() seem to work on pieces so I assume I need to handle the mouse events separately from chessbord’s APIs.

I hope you provide some insight on the above.

Thank you so much,

oakmac commented 1 year ago

When I browsed through the docs I did not see them documented and even the references to their methods from https://chessboardjs.com/v2/examples#3008-analysis-arrows did not lead anywhere.

I have not written the documentation for the analysis arrow methods yet, but you can see their usage in that example.

How stable is the current version?

Pretty stable. I do not have plans to change any existing methods that are currently implemented. I would like to add some new methods before releasing to v2.0.0.

Any idea when a release version will be available?

If I were starting a new project today that needed a chessboard, I would use chessboard2 over chessboard.js. v0.3.0 is pretty functional for most use cases. I would like to release v2.0.0 before the end of the year.

How are the arrows and circles stored internally as i would like to save them along with the game?

Arrows and circles are stored internally inside a ClojureScript atom, but I consider this an implementation detail of chessboard2. You can use the .getArrows() method from example 3008 and the .getCircles() method from example 3009 to retrieve the current state of these on the board in multiple formats (Array, Object, Map).

Any recommended approach to drawing them using the mouse rather than programatically? onDrag…() seem to work on pieces so I assume I need to handle the mouse events separately from chessboard’s APIs.

Yes - I think capturing the mouse event to determine which square was clicked is what you would need to do in order to accomplish this today. It might be good for chessboard2 to offer an .onClickSquare() event that you could hook into in order to do this; I will give this a think.

djeetee commented 1 year ago

on the last point, either a .onClickSquare() or a mouse coordinates (from the click event)-to-square method would be also good.

oakmac commented 1 year ago

@djeetee the master branch now has two examples of dynamically adding arrows to the board using mouse events (PR #41)

oakmac commented 1 year ago

This is supported by v0.4.0

djeetee commented 1 year ago

Hey Chris, I hope all is well.

I finally sunk my teeth into chessboard2. I have the board set up, i can feed positions, moves, navigate, etc… So far so good.

My question/comment is this: it would be great if one could enable/disable play for one of the two players. In other words, being able to stop one color from moving their pieces.

Say I’m playing white and waiting for black to move, I shouldn’t be able to move my own piece (unless of course I want to enable pre-moves which another use-case on its own) but at least I’m not changing the state of the board during the other player’s turn.

Is there a clean way to do that with the current functionality or do I have to code the logic?

Thank you,

-George On Apr 10, 2023 at 11:00 AM -0400, Chris Oakman @.***>, wrote:

This is supported by v0.4.0

https://chessboardjs.com/v2/examples#4015-mouse-enter-leave-squareshttps://chessboardjs.com/v2/examples#4016-mouse-down-up-squareshttps://chessboardjs.com/v2/examples#5006-click-to-create-arrowshttps://chessboardjs.com/v2/examples#5007-click-to-create-arrows-preview

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>

oakmac commented 1 year ago

it would be great if one could enable/disable play for one of the two players. In other words, being able to stop one color from moving their pieces.

I think Example 4002 demonstrates the behavior you want.