cm-chessboard 8.3.2 → 8.3.4
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.
- package/README.md +22 -13
- package/package.json +1 -1
- package/src/model/Extension.js +2 -2
- package/examples/test-getPiece.html +0 -21
package/README.md
CHANGED
|
@@ -87,7 +87,7 @@ To enable the user to move the pieces, you have to enable the move input.
|
|
|
87
87
|
const board = new Chessboard(document.getElementById("board"), {
|
|
88
88
|
position: FEN.start,
|
|
89
89
|
assetsUrl: "../assets/",
|
|
90
|
-
extensions: [{class: Markers}] // Looks better with markers
|
|
90
|
+
extensions: [{class: Markers}] // Looks better with markers. (Don't forget to also include the CSS for the markers)
|
|
91
91
|
})
|
|
92
92
|
|
|
93
93
|
board.enableMoveInput(inputHandler) // This enables the move input
|
|
@@ -218,25 +218,34 @@ board.enableMoveInput((event) => {
|
|
|
218
218
|
The event has the following **`event.type`**:
|
|
219
219
|
|
|
220
220
|
- **`INPUT_EVENT_TYPE.moveInputStarted`**: User started the move input, `event.squareFrom` contains the coordinates.
|
|
221
|
-
Return true or false to validate the start square.
|
|
222
|
-
- **`INPUT_EVENT_TYPE.validateMoveInput`**:
|
|
223
|
-
contain the coordinates. Return true or false to validate the move
|
|
224
|
-
- **`INPUT_EVENT_TYPE.moveInputCanceled`**:
|
|
225
|
-
outside the board.
|
|
221
|
+
Return `true` or `false` to validate the start square. `false` cancels the move.
|
|
222
|
+
- **`INPUT_EVENT_TYPE.validateMoveInput`**: To validate the users move input. `event.squareFrom` and `event.squareTo`
|
|
223
|
+
contain the coordinates. Return `true` or `false` to validate the move. `false` cancels the move.
|
|
224
|
+
- **`INPUT_EVENT_TYPE.moveInputCanceled`**: The user canceled the move with clicking again on the start square, clicking
|
|
225
|
+
outside the board or right click.
|
|
226
|
+
- **`INPUT_EVENT_TYPE.moveInputFinished`**: Fired after the move was made.
|
|
227
|
+
- **`INPUT_EVENT_TYPE.movingOverSquare`**: Fired, when the user moves the piece over a square. `event.square` contains
|
|
228
|
+
the coordinates.
|
|
226
229
|
|
|
227
230
|
```javascript
|
|
228
231
|
chessboard.enableMoveInput((event) => {
|
|
232
|
+
console.log("move input", event)
|
|
229
233
|
switch (event.type) {
|
|
230
234
|
case INPUT_EVENT_TYPE.moveInputStarted:
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
return true
|
|
235
|
+
log(`moveInputStarted: ${event.squareFrom}`)
|
|
236
|
+
return true // false cancels move
|
|
234
237
|
case INPUT_EVENT_TYPE.validateMoveInput:
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
return true
|
|
238
|
+
log(`validateMoveInput: ${event.squareFrom}-${event.squareTo}`)
|
|
239
|
+
return true // false cancels move
|
|
238
240
|
case INPUT_EVENT_TYPE.moveInputCanceled:
|
|
239
|
-
|
|
241
|
+
log(`moveInputCanceled`)
|
|
242
|
+
break
|
|
243
|
+
case INPUT_EVENT_TYPE.moveInputFinished:
|
|
244
|
+
log(`moveInputFinished`)
|
|
245
|
+
break
|
|
246
|
+
case INPUT_EVENT_TYPE.movingOverSquare:
|
|
247
|
+
log(`movingOverSquare: ${event.square}`)
|
|
248
|
+
break
|
|
240
249
|
}
|
|
241
250
|
}, COLOR.white)
|
|
242
251
|
```
|
package/package.json
CHANGED
package/src/model/Extension.js
CHANGED
|
@@ -12,7 +12,7 @@ export const EXTENSION_POINT = {
|
|
|
12
12
|
beforeRedrawBoard: "beforeRedrawBoard", // called before redrawing the board
|
|
13
13
|
afterRedrawBoard: "afterRedrawBoard", // called after redrawing the board
|
|
14
14
|
redrawBoard: "redrawBoard", // called after redrawing the board, DEPRECATED, use afterRedrawBoard 2023-09-18
|
|
15
|
-
animation: "animation", // called on animation start, end and on every animation frame
|
|
15
|
+
animation: "animation", // called on animation start, end, and on every animation frame
|
|
16
16
|
destroy: "destroy" // called, before the board is destroyed
|
|
17
17
|
}
|
|
18
18
|
|
|
@@ -23,7 +23,7 @@ export class Extension {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
registerExtensionPoint(name, callback) {
|
|
26
|
-
if(name === EXTENSION_POINT.redrawBoard) {
|
|
26
|
+
if(name === EXTENSION_POINT.redrawBoard) { // deprecated 2023-09-18
|
|
27
27
|
console.warn("EXTENSION_POINT.redrawBoard is deprecated, use EXTENSION_POINT.afterRedrawBoard")
|
|
28
28
|
name = EXTENSION_POINT.afterRedrawBoard
|
|
29
29
|
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<link rel="stylesheet" href="../assets/chessboard.css">
|
|
5
|
-
<title>frame test</title>
|
|
6
|
-
</head>
|
|
7
|
-
<body>
|
|
8
|
-
Board:
|
|
9
|
-
<div id="board"></div>
|
|
10
|
-
|
|
11
|
-
<script type="module">
|
|
12
|
-
import { Chessboard } from '../src/Chessboard.js'
|
|
13
|
-
|
|
14
|
-
const board = new Chessboard(document.getElementById('board'), {
|
|
15
|
-
position: 'start',
|
|
16
|
-
sprite: {url: '../assets/images/chessboard-sprite.svg'},
|
|
17
|
-
style: {borderType: 'frame'}
|
|
18
|
-
})
|
|
19
|
-
</script>
|
|
20
|
-
</body>
|
|
21
|
-
</html>
|