File tree 1 file changed +28
-5
lines changed
1 file changed +28
-5
lines changed Original file line number Diff line number Diff line change @@ -23,12 +23,35 @@ class VueChessboard {
23
23
}
24
24
25
25
makeMove ( fromAreaId , targetAreaId ) {
26
- const { left, top, width, height } = this . element . getBoundingClientRect ( ) ;
27
-
28
26
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' ) ;
32
55
}
33
56
}
34
57
You can’t perform that action at this time.
0 commit comments