cm-chessboard 8.5.5 → 8.5.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -49,21 +49,12 @@
|
|
|
49
49
|
return // ignore this event
|
|
50
50
|
}
|
|
51
51
|
if(event.type !== INPUT_EVENT_TYPE.moveInputFinished) {
|
|
52
|
-
event.chessboard.
|
|
53
|
-
event.chessboard.removeMarkers(MARKER_TYPE.bevel)
|
|
52
|
+
event.chessboard.removeLegalMovesMarkers()
|
|
54
53
|
}
|
|
55
54
|
if (event.type === INPUT_EVENT_TYPE.moveInputStarted) {
|
|
55
|
+
// mark legal moves
|
|
56
56
|
const moves = chess.moves({square: event.squareFrom, verbose: true})
|
|
57
|
-
|
|
58
|
-
if (move.promotion && move.promotion !== "q") {
|
|
59
|
-
continue
|
|
60
|
-
}
|
|
61
|
-
if (event.chessboard.getPiece(move.to)) {
|
|
62
|
-
event.chessboard.addMarker(MARKER_TYPE.bevel, move.to)
|
|
63
|
-
} else {
|
|
64
|
-
event.chessboard.addMarker(MARKER_TYPE.dot, move.to)
|
|
65
|
-
}
|
|
66
|
-
}
|
|
57
|
+
event.chessboard.addLegalMovesMarkers(moves)
|
|
67
58
|
return moves.length > 0
|
|
68
59
|
} else if (event.type === INPUT_EVENT_TYPE.validateMoveInput) {
|
|
69
60
|
const move = {from: event.squareFrom, to: event.squareTo, promotion: event.promotion}
|
package/package.json
CHANGED
|
@@ -39,6 +39,8 @@ export class Markers extends Extension {
|
|
|
39
39
|
chessboard.addMarker = this.addMarker.bind(this)
|
|
40
40
|
chessboard.getMarkers = this.getMarkers.bind(this)
|
|
41
41
|
chessboard.removeMarkers = this.removeMarkers.bind(this)
|
|
42
|
+
chessboard.addLegalMovesMarkers = this.addLegalMovesMarkers.bind(this)
|
|
43
|
+
chessboard.removeLegalMovesMarkers = this.removeLegalMovesMarkers.bind(this)
|
|
42
44
|
this.markerGroupDown = Svg.addElement(chessboard.view.markersLayer, "g", {class: "markers"})
|
|
43
45
|
this.markerGroupUp = Svg.addElement(chessboard.view.markersTopLayer, "g", {class: "markers"})
|
|
44
46
|
this.markers = []
|
|
@@ -82,6 +84,24 @@ export class Markers extends Extension {
|
|
|
82
84
|
)
|
|
83
85
|
}
|
|
84
86
|
|
|
87
|
+
addLegalMovesMarkers(moves) {
|
|
88
|
+
for (const move of moves) {
|
|
89
|
+
if (move.promotion && move.promotion !== "q") {
|
|
90
|
+
continue
|
|
91
|
+
}
|
|
92
|
+
if (this.chessboard.getPiece(move.to)) {
|
|
93
|
+
this.chessboard.addMarker(MARKER_TYPE.bevel, move.to)
|
|
94
|
+
} else {
|
|
95
|
+
this.chessboard.addMarker(MARKER_TYPE.dot, move.to)
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
removeLegalMovesMarkers() {
|
|
101
|
+
this.chessboard.removeMarkers(MARKER_TYPE.bevel)
|
|
102
|
+
this.chessboard.removeMarkers(MARKER_TYPE.dot)
|
|
103
|
+
}
|
|
104
|
+
|
|
85
105
|
drawMarker(marker) {
|
|
86
106
|
let markerGroup
|
|
87
107
|
if (marker.type.position === 'above') {
|