oakmac / chessboardjs

JavaScript chessboard
https://chessboardjs.com
MIT License
2.01k stars 408 forks source link

Not working Clicked and drop? #175

Closed KGPARMAR closed 4 years ago

KGPARMAR commented 5 years ago

I have play this example but here only working drag and drop but not working, see example: https://play.google.com/store/apps/details?id=org.petero.droidfish move like this

theostavrides commented 4 years ago

It would be really great if this was implemented. I see that someone made a pull request to integrate click moves but it wasn't working for me.

vesper8 commented 4 years ago

I forked the project and made click-and-drop work with 1.0 using as inspiration this PR: https://github.com/oakmac/chessboardjs/pull/138 by @pino

It works really well and the modification was very simple. I want to create a PR but because this file https://github.com/oakmac/chessboardjs/blob/master/lib/chessboard.js has a "mixed line endings issue", as you can see from the warning if you try to edit it on Github. I cannot create a PR without causing the entire file to become one big diff. I reported this to Github so we'll see what they say. @oakmac please consider fixing the issue with the mixed line endings, and please consider adding the below modifications as a very simple click-to-move that doesn't break anything and still triggers the same checks as the normal drag-and-drop alternative

Anyway here are the modifications.. very simple stuff

replace

    var squareSize = 16

by

    var squareSize = 16
    var clickMove = false

replace

    function dropDraggedPieceOnSquare (square) {

      removeSquareHighlights()

by

    function dropDraggedPieceOnSquare (square) {

      // if destination is same as source, piece stays picked up and is dropped at the next clicked square.
      if (clickMove == false) {
        if (square === draggedPieceSource) {
          clickMove = true;
          return;
        }
      }

      clickMove = false;

      removeSquareHighlights()

replace

    function stopDraggedPiece (location) {
      // determine what the action should be
      var action = 'drop'

      if (location === 'offboard' && config.dropOffBoard === 'snapback') {
        action = 'snapback'
      }

by

    function stopDraggedPiece (location) {
      // determine what the action should be
      var action = 'drop'

      if (location === 'offboard' && config.dropOffBoard === 'snapback') {
        action = 'snapback'
        clickMove = false;
      } else {
        if (clickMove == false) {
          // pick up spare piece and put it down on next clicked square
          clickMove = true;
          return;
        } else {
          // drop piece back on its origin square
          clickMove = false;
        }
      }

and voila.. that's it.. works perfectly for me on 1.0

Just download the zip from the website and apply these modifications to the non-minified version

larskuerten commented 4 years ago

I follow the instructions, it works to move but not capturing.

KGPARMAR commented 4 years ago

Thanks brother it's working find!