Adjust comments, add a few TODOs + remove DEBUG in play/undo
[vchess.git] / public / javascripts / components / game.js
index f5bef8e..72b5da9 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',
@@ -431,14 +432,14 @@ Vue.component('my-game', {
                                        "col-lg-6":true,
                                        "col-lg-offset-3":true,
                                },
-                               // NOTE: click = mousedown + mouseup --> what about smartphone?!
+                               // NOTE: click = mousedown + mouseup
                                on: {
                                        mousedown: this.mousedown,
                                        mousemove: this.mousemove,
                                        mouseup: this.mouseup,
-                                       touchdown: this.mousedown,
-                                       touchmove: this.mousemove,
-                                       touchup: this.mouseup,
+//                                     touchstart: this.mousedown, //TODO...
+//                                     touchmove: this.mousemove,
+//                                     touchend: this.mouseup,
                                },
                        },
                        elementArray
@@ -735,6 +736,19 @@ Vue.component('my-game', {
                },
                mousedown: function(e) {
                        e = e || window.event;
+                       let ingame = false;
+                       let elem = e.target;
+                       while (!ingame && elem !== null)
+                       {
+                               if (elem.classList.contains("game"))
+                               {
+                                       ingame = true;
+                                       break;
+                               }
+                               elem = elem.parentElement;
+                       }
+                       if (!ingame) //let default behavior (click on button...)
+                               return;
                        e.preventDefault(); //disable native drag & drop
                        if (!this.selectedPiece && e.target.classList.contains("piece"))
                        {
@@ -754,7 +768,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) {