X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=public%2Fjavascripts%2Fcomponents%2Fboard.js;fp=public%2Fjavascripts%2Fcomponents%2Fboard.js;h=cec6049eeebce78b1fb406f8428dd58b3f67fe7a;hb=fd373b27c15a98f891e1158639abc50e19466449;hp=6110cfb8ea232f6ae9801ad6c414db9d08d55273;hpb=e5dc87e0e8f2d53a910b2b42ed2a0a39ea6787aa;p=vchess.git diff --git a/public/javascripts/components/board.js b/public/javascripts/components/board.js index 6110cfb8..cec6049e 100644 --- a/public/javascripts/components/board.js +++ b/public/javascripts/components/board.js @@ -1,10 +1,7 @@ Vue.component('my-board', { // Last move cannot be guessed from here, and is required to highlight squares - // gotoMove : juste set FEN depuis FEN stocké dans le coup (TODO) - // send event after each move (or undo), to notify what was played - // also notify end of game (which returns here later through prop...) - props: ["fen","moveToPlay","moveToUndo", - "analyze","lastMove","orientation","userColor","gameOver"], + // vr: object to check moves, print board... + props: ["vr","lastMove","mode","orientation","userColor","gameOver"], data: function () { return { hints: (!localStorage["hints"] ? true : localStorage["hints"] === "1"), @@ -14,24 +11,8 @@ Vue.component('my-board', { selectedPiece: null, //moving piece (or clicked piece) incheck: [], start: {}, //pixels coordinates + id of starting square (click or drag) - vr: null, //object to check moves, store them, FEN.. }; }, - watch: { - // NOTE: maybe next 3 should be encapsulated in object to be watched (?) - fen: function(newFen) { - this.vr = new VariantRules(newFen); - }, - moveToPlay: function(move) { - this.play(move, "animate"); - }, - moveToUndo: function(move) { - this.undo(move); - }, - }, - created: function() { - this.vr = new VariantRules(this.fen); - }, render(h) { const [sizeX,sizeY] = [V.size.x,V.size.y]; // Precompute hints squares to facilitate rendering @@ -191,7 +172,7 @@ Vue.component('my-board', { ])); } let oppReservePiecesArray = []; - const oppCol = this.vr.getOppCol(this.userColor); + const oppCol = V.GetOppCol(this.userColor); for (let i=0; i img.piece"); - // HACK for animation (with positive translate, image slides "under background") - // Possible improvement: just alter squares on the piece's way... - squares = document.getElementsByClassName("board"); - for (let i=0; i { - for (let i=0; i {}); - // Is opponent in check? - this.incheck = this.vr.getCheckSquares(this.vr.turn); - const eog = this.vr.getCurrentScore(); - if (eog != "*") - { - // TODO: notify end of game (give score) - } - }, - undo: function(move) { - this.vr.undo(move); - if (this.sound == 2) - new Audio("/sounds/undo.mp3").play().catch(err => {}); - this.incheck = this.vr.getCheckSquares(this.vr.turn); + play: function(move) { + this.$emit('play-move', move); }, }, })