cm-chessboard 7.6.0 → 7.6.1
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
CHANGED
|
@@ -119,7 +119,7 @@ after the animation finished.
|
|
|
119
119
|
|
|
120
120
|
### getPiece(square)
|
|
121
121
|
|
|
122
|
-
Returns the piece on a square or `
|
|
122
|
+
Returns the piece on a square or `null` if the square is empty.
|
|
123
123
|
|
|
124
124
|
### movePiece(squareFrom, squareTo, animated = false)
|
|
125
125
|
|
package/package.json
CHANGED
|
@@ -25,10 +25,10 @@ export class PromotionDialog extends Extension {
|
|
|
25
25
|
this.promotionDialogGroup = Svg.addElement(chessboard.view.interactiveTopLayer, "g", {class: "promotion-dialog-group"})
|
|
26
26
|
this.state = {
|
|
27
27
|
displayState: DISPLAY_STATE.hidden,
|
|
28
|
-
callback:
|
|
28
|
+
callback: null,
|
|
29
29
|
dialogParams: {
|
|
30
|
-
square:
|
|
31
|
-
color:
|
|
30
|
+
square: null,
|
|
31
|
+
color: null
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
}
|
package/src/model/Position.js
CHANGED
|
@@ -10,23 +10,13 @@ export const FEN = {
|
|
|
10
10
|
|
|
11
11
|
export class Position {
|
|
12
12
|
|
|
13
|
-
constructor(fen =
|
|
13
|
+
constructor(fen = FEN.empty) {
|
|
14
14
|
this.squares = new Array(64).fill(null)
|
|
15
15
|
this.setFen(fen)
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
setFen(fen = FEN.empty) {
|
|
19
|
-
|
|
20
|
-
if (fen === "start") {
|
|
21
|
-
console.warn("setting the position with the strings 'start' or 'empty' is deprecated, use FEN.start or FEN.empty", "used:", fen)
|
|
22
|
-
fenNormalized = FEN.start
|
|
23
|
-
} else if (fen === "empty" || fen === undefined) {
|
|
24
|
-
console.warn("setting the position with the strings 'start' or 'empty' is deprecated, use FEN.start or FEN.empty", "used:", fen)
|
|
25
|
-
fenNormalized = FEN.empty
|
|
26
|
-
} else {
|
|
27
|
-
fenNormalized = fen
|
|
28
|
-
}
|
|
29
|
-
const parts = fenNormalized.replace(/^\s*/, "").replace(/\s*$/, "").split(/\/|\s/)
|
|
19
|
+
const parts = fen.replace(/^\s*/, "").replace(/\s*$/, "").split(/\/|\s/)
|
|
30
20
|
for (let part = 0; part < 8; part++) {
|
|
31
21
|
const row = parts[7 - part].replace(/\d/g, (str) => {
|
|
32
22
|
const numSpaces = parseInt(str)
|
|
@@ -86,29 +76,29 @@ export class Position {
|
|
|
86
76
|
const sort = (a, b) => {
|
|
87
77
|
return sortBy.indexOf(a.name) - sortBy.indexOf(b.name)
|
|
88
78
|
}
|
|
89
|
-
for(let i=0; i<64; i++) {
|
|
79
|
+
for (let i = 0; i < 64; i++) {
|
|
90
80
|
const piece = this.squares[i]
|
|
91
|
-
if(piece) {
|
|
81
|
+
if (piece) {
|
|
92
82
|
pieces.push({
|
|
93
83
|
name: piece.charAt(1),
|
|
94
|
-
color:
|
|
84
|
+
color: piece.charAt(0),
|
|
95
85
|
position: Position.indexToSquare(i)
|
|
96
86
|
})
|
|
97
87
|
}
|
|
98
88
|
}
|
|
99
|
-
if(sortBy) {
|
|
89
|
+
if (sortBy) {
|
|
100
90
|
pieces.sort(sort)
|
|
101
91
|
}
|
|
102
92
|
return pieces
|
|
103
93
|
}
|
|
104
94
|
|
|
105
95
|
movePiece(squareFrom, squareTo) {
|
|
106
|
-
if(!this.squares[Position.squareToIndex(squareFrom)]) {
|
|
96
|
+
if (!this.squares[Position.squareToIndex(squareFrom)]) {
|
|
107
97
|
console.warn("no piece on", squareFrom)
|
|
108
98
|
return
|
|
109
99
|
}
|
|
110
100
|
this.squares[Position.squareToIndex(squareTo)] = this.squares[Position.squareToIndex(squareFrom)]
|
|
111
|
-
this.squares[Position.squareToIndex(squareFrom)] =
|
|
101
|
+
this.squares[Position.squareToIndex(squareFrom)] = null
|
|
112
102
|
}
|
|
113
103
|
|
|
114
104
|
setPiece(square, piece) {
|
|
@@ -302,7 +302,7 @@ export class ChessboardView {
|
|
|
302
302
|
|
|
303
303
|
// enable and disable move input //
|
|
304
304
|
|
|
305
|
-
enableMoveInput(eventHandler, color =
|
|
305
|
+
enableMoveInput(eventHandler, color = null) {
|
|
306
306
|
if (this.moveInputCallback) {
|
|
307
307
|
throw Error("moveInput already enabled")
|
|
308
308
|
}
|
|
@@ -324,7 +324,7 @@ export class ChessboardView {
|
|
|
324
324
|
this.chessboard.state.inputWhiteEnabled = false
|
|
325
325
|
this.chessboard.state.inputBlackEnabled = false
|
|
326
326
|
this.chessboard.state.inputEnabled = false
|
|
327
|
-
this.moveInputCallback =
|
|
327
|
+
this.moveInputCallback = null
|
|
328
328
|
this.chessboard.state.invokeExtensionPoints(EXTENSION_POINT.moveInputToggled, {enabled: false})
|
|
329
329
|
this.visualizeInputState()
|
|
330
330
|
}
|
|
@@ -110,7 +110,7 @@ export class PositionsAnimation {
|
|
|
110
110
|
}
|
|
111
111
|
appearedList.forEach((appeared) => {
|
|
112
112
|
let shortestDistance = 8
|
|
113
|
-
let foundMoved =
|
|
113
|
+
let foundMoved = null
|
|
114
114
|
disappearedList.forEach((disappeared) => {
|
|
115
115
|
if (appeared.piece === disappeared.piece) {
|
|
116
116
|
const moveDistance = PositionsAnimation.squareDistance(appeared.index, disappeared.index)
|
|
@@ -79,14 +79,14 @@ export class VisualMoveInput {
|
|
|
79
79
|
}
|
|
80
80
|
if (this.pointerMoveListener) {
|
|
81
81
|
removeEventListener(this.pointerMoveListener.type, this.pointerMoveListener)
|
|
82
|
-
this.pointerMoveListener =
|
|
82
|
+
this.pointerMoveListener = null
|
|
83
83
|
}
|
|
84
84
|
if (this.pointerUpListener) {
|
|
85
85
|
removeEventListener(this.pointerUpListener.type, this.pointerUpListener)
|
|
86
|
-
this.pointerUpListener =
|
|
86
|
+
this.pointerUpListener = null
|
|
87
87
|
}
|
|
88
88
|
this.fromSquare = params.square
|
|
89
|
-
this.toSquare =
|
|
89
|
+
this.toSquare = null
|
|
90
90
|
this.movedPiece = params.piece
|
|
91
91
|
this.startPoint = params.point
|
|
92
92
|
if (!this.pointerMoveListener && !this.pointerUpListener) {
|
|
@@ -119,7 +119,7 @@ export class VisualMoveInput {
|
|
|
119
119
|
case MOVE_INPUT_STATE.clickTo:
|
|
120
120
|
if (this.draggablePiece) {
|
|
121
121
|
Svg.removeElement(this.draggablePiece)
|
|
122
|
-
this.draggablePiece =
|
|
122
|
+
this.draggablePiece = null
|
|
123
123
|
}
|
|
124
124
|
if (prevState === MOVE_INPUT_STATE.dragTo) {
|
|
125
125
|
this.view.setPieceVisibility(params.square, true)
|
|
@@ -179,24 +179,24 @@ export class VisualMoveInput {
|
|
|
179
179
|
if (this.fromSquare && !this.toSquare && this.movedPiece) {
|
|
180
180
|
this.chessboard.state.position.setPiece(this.fromSquare, this.movedPiece)
|
|
181
181
|
}
|
|
182
|
-
this.fromSquare =
|
|
183
|
-
this.toSquare =
|
|
184
|
-
this.movedPiece =
|
|
182
|
+
this.fromSquare = null
|
|
183
|
+
this.toSquare = null
|
|
184
|
+
this.movedPiece = null
|
|
185
185
|
if (this.draggablePiece) {
|
|
186
186
|
Svg.removeElement(this.draggablePiece)
|
|
187
|
-
this.draggablePiece =
|
|
187
|
+
this.draggablePiece = null
|
|
188
188
|
}
|
|
189
189
|
if (this.pointerMoveListener) {
|
|
190
190
|
removeEventListener(this.pointerMoveListener.type, this.pointerMoveListener)
|
|
191
|
-
this.pointerMoveListener =
|
|
191
|
+
this.pointerMoveListener = null
|
|
192
192
|
}
|
|
193
193
|
if (this.pointerUpListener) {
|
|
194
194
|
removeEventListener(this.pointerUpListener.type, this.pointerUpListener)
|
|
195
|
-
this.pointerUpListener =
|
|
195
|
+
this.pointerUpListener = null
|
|
196
196
|
}
|
|
197
197
|
if (this.contextMenuListener) {
|
|
198
198
|
removeEventListener("contextmenu", this.contextMenuListener)
|
|
199
|
-
this.contextMenuListener =
|
|
199
|
+
this.contextMenuListener = null
|
|
200
200
|
}
|
|
201
201
|
this.setMoveInputState(MOVE_INPUT_STATE.waitForInputStart)
|
|
202
202
|
break
|
|
@@ -240,7 +240,7 @@ export class VisualMoveInput {
|
|
|
240
240
|
// console.log("onPointerDown", square, pieceName)
|
|
241
241
|
let color
|
|
242
242
|
if (pieceName) {
|
|
243
|
-
color = pieceName ? pieceName.substring(0, 1) :
|
|
243
|
+
color = pieceName ? pieceName.substring(0, 1) : null
|
|
244
244
|
// allow scrolling, if not pointed on draggable piece
|
|
245
245
|
if (color === "w" && this.chessboard.state.inputWhiteEnabled ||
|
|
246
246
|
color === "b" && this.chessboard.state.inputBlackEnabled) {
|
|
@@ -273,9 +273,9 @@ export class VisualMoveInput {
|
|
|
273
273
|
})
|
|
274
274
|
} else {
|
|
275
275
|
const pieceName = this.chessboard.getPiece(square)
|
|
276
|
-
const pieceColor = pieceName ? pieceName.substring(0, 1) :
|
|
276
|
+
const pieceColor = pieceName ? pieceName.substring(0, 1) : null
|
|
277
277
|
const startPieceName = this.chessboard.getPiece(this.fromSquare)
|
|
278
|
-
const startPieceColor = startPieceName ? startPieceName.substring(0, 1) :
|
|
278
|
+
const startPieceColor = startPieceName ? startPieceName.substring(0, 1) : null
|
|
279
279
|
if (color && startPieceColor === pieceColor) {
|
|
280
280
|
this.moveInputCanceledCallback(this.fromSquare, square, MOVE_CANCELED_REASON.clickedAnotherPiece)
|
|
281
281
|
if (this.moveInputStartedCallback(square)) {
|
|
@@ -330,13 +330,13 @@ export class VisualMoveInput {
|
|
|
330
330
|
if (square !== this.fromSquare && square !== this.toSquare) {
|
|
331
331
|
this.toSquare = square
|
|
332
332
|
this.movingOverSquareCallback(this.fromSquare, this.toSquare)
|
|
333
|
-
} else if (square === this.fromSquare && this.toSquare !==
|
|
334
|
-
this.toSquare =
|
|
333
|
+
} else if (square === this.fromSquare && this.toSquare !== null) {
|
|
334
|
+
this.toSquare = null
|
|
335
335
|
this.movingOverSquareCallback(this.fromSquare, null)
|
|
336
336
|
}
|
|
337
337
|
} else {
|
|
338
|
-
if (this.toSquare !==
|
|
339
|
-
this.toSquare =
|
|
338
|
+
if (this.toSquare !== null) {
|
|
339
|
+
this.toSquare = null
|
|
340
340
|
this.movingOverSquareCallback(this.fromSquare, null)
|
|
341
341
|
}
|
|
342
342
|
}
|