Skip to content

Commit 061c4a3

Browse files
Create first minimal prototype of move
1 parent 289bfad commit 061c4a3

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

Diff for: app/src/chessboard/vue-chessboard.js

+28-5
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,35 @@ class VueChessboard {
2323
}
2424

2525
makeMove(fromAreaId, targetAreaId) {
26-
const { left, top, width, height } = this.element.getBoundingClientRect();
27-
2826
const fromCoords = squareToCoords(fromAreaId);
29-
const piece = this.element.querySelector(`.piece.square-${fromCoords.join('')}`);
30-
if (piece) {
31-
alert('at least im here');
27+
const pieceElement = this.element.querySelector(`.piece.square-${fromCoords.join('')}`);
28+
if (pieceElement) {
29+
const toCoords = squareToCoords(targetAreaId);
30+
const { left, top, width } = this.element.getBoundingClientRect();
31+
const squareWidth = width / 8;
32+
const correction = squareWidth / 2;
33+
34+
pieceElement.dispatchEvent(new MouseEvent("mousedown", {
35+
bubbles: true,
36+
cancelable: true,
37+
view: window,
38+
which: 0,
39+
clientX: left + (squareWidth) * Number(fromCoords[0]) - correction,
40+
clientY: top + width - (squareWidth) * Number(fromCoords[1]) + correction,
41+
}));
42+
43+
const mouseupEvent = new MouseEvent("mouseup", {
44+
bubbles: true,
45+
cancelable: true,
46+
view: window,
47+
which: 0,
48+
clientX: left + (squareWidth) * Number(toCoords[0]) - correction,
49+
clientY: top + width - (squareWidth) * Number(toCoords[1]) + correction,
50+
});
51+
52+
pieceElement.dispatchEvent(mouseupEvent);
53+
54+
console.log('here');
3255
}
3356
}
3457

0 commit comments

Comments
 (0)