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

How to implement piece drag and drop feature like https://lichess.org/editor? #281

Closed invisionweb closed 1 year ago

invisionweb commented 1 year ago

I'm finding it difficult to create a piece drag and drop feature like https://lichess.org/editor. The extra new pieces will be outside the board. How the event afterNewPiece() can be triggered?

movable?: {
    events?: {
      after?: (orig: cg.Key, dest: cg.Key, metadata: cg.MoveMetadata) => void; // called after the move has been played
      afterNewPiece?: (role: cg.Role, key: cg.Key, metadata: cg.MoveMetadata) => void; // called after a new piece is dropped on the board
    };
  };
uribalb commented 1 year ago

I'm finding it difficult to create a piece drag and drop feature like https://lichess.org/editor. The extra new pieces will be outside the board. How the event afterNewPiece() can be triggered?

movable?: {
    events?: {
      after?: (orig: cg.Key, dest: cg.Key, metadata: cg.MoveMetadata) => void; // called after the move has been played
      afterNewPiece?: (role: cg.Role, key: cg.Key, metadata: cg.MoveMetadata) => void; // called after a new piece is dropped on the board
    };
  };

Look into Lichess' source code

ornicar commented 1 year ago

Please, this is not an issue.