lichess-org / chessground

Mobile/Web chess UI for lichess.org
https://lichess.org
GNU General Public License v3.0
1.04k stars 261 forks source link

Not possible to set custom premove squares #271

Closed melgrove closed 1 year ago

melgrove commented 1 year ago

Problem

state.movable.dests takes the Dests map, and it's possible to set custom piece movement rules by passing a custom map with .set(). However, state.premovable.dests takes Key[] and just stores the possible premove squares for a particular selected square. These values are calculated here https://github.com/lichess-org/chessground/blob/239763228a3fd88540c796d1e9f2a99a140a342f/src/board.ts#L206 and are hardcoded to use the rules of chess (premove.ts). It's not possible to set custom premove squares like state.movable.dests using .set() or mutating cg.state directly because the rules of chess are automatically used in line 206 on every selection.

Solution

Make a new optional property state.premovable.customDests which uses the Dests format like state.movable.dests. When this property is present, it is used to set state.premovable.dests instead of calling premove() and using the rules of chess. To use custom premoves you can use .set() to set premovable.customDests.