Attempt to handle smartphone drag and drop
[vchess.git] / public / javascripts / components / game.js
index f5bef8e..84976b0 100644 (file)
@@ -242,13 +242,14 @@ Vue.component('my-game', {
                        elementArray.push(gameDiv);
                        if (!!this.vr.reserve)
                        {
+                               const shiftIdx = (this.mycolor=="w" ? 0 : 1);
                                let myReservePiecesArray = [];
                                for (let i=0; i<VariantRules.RESERVE_PIECES.length; i++)
                                {
                                        myReservePiecesArray.push(h('div',
                                        {
                                                'class': {'board':true, ['board'+sizeY]:true},
-                                               attrs: { id: this.getSquareId({x:sizeX,y:i}) }
+                                               attrs: { id: this.getSquareId({x:sizeX+shiftIdx,y:i}) }
                                        },
                                        [
                                                h('img',
@@ -272,7 +273,7 @@ Vue.component('my-game', {
                                        oppReservePiecesArray.push(h('div',
                                        {
                                                'class': {'board':true, ['board'+sizeY]:true},
-                                               attrs: { id: this.getSquareId({x:sizeX,y:i}) }
+                                               attrs: { id: this.getSquareId({x:sizeX+(1-shiftIdx),y:i}) }
                                        },
                                        [
                                                h('img',
@@ -436,9 +437,9 @@ Vue.component('my-game', {
                                        mousedown: this.mousedown,
                                        mousemove: this.mousemove,
                                        mouseup: this.mouseup,
-                                       touchdown: this.mousedown,
+                                       touchstart: this.mousedown,
                                        touchmove: this.mousemove,
-                                       touchup: this.mouseup,
+                                       touchend: this.mouseup,
                                },
                        },
                        elementArray
@@ -754,7 +755,8 @@ Vue.component('my-game', {
                                this.possibleMoves = this.mode!="idle" && this.vr.canIplay(this.mycolor,startSquare)
                                        ? this.vr.getPossibleMovesFrom(startSquare)
                                        : [];
-                               e.target.parentNode.appendChild(this.selectedPiece);
+                               // Next line add moving piece just after current image (required for Crazyhouse reserve)
+                               e.target.parentNode.insertBefore(this.selectedPiece, e.target.nextSibling);
                        }
                },
                mousemove: function(e) {