cm-chess 3.0.1 → 3.1.0
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/package.json +1 -1
- package/src/Chess.js +10 -8
package/package.json
CHANGED
package/src/Chess.js
CHANGED
|
@@ -33,10 +33,10 @@ export const EVENT_TYPE = {
|
|
|
33
33
|
initialized: "initialized"
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
function publishEvent(observers,
|
|
36
|
+
function publishEvent(observers, event) {
|
|
37
37
|
for (const observer of observers) {
|
|
38
38
|
setTimeout(() => {
|
|
39
|
-
observer(
|
|
39
|
+
observer(event)
|
|
40
40
|
})
|
|
41
41
|
}
|
|
42
42
|
}
|
|
@@ -182,7 +182,7 @@ export class Chess {
|
|
|
182
182
|
} else {
|
|
183
183
|
throw Error("Invalid fen " + fen)
|
|
184
184
|
}
|
|
185
|
-
publishEvent(this.observers, EVENT_TYPE.initialized,
|
|
185
|
+
publishEvent(this.observers, {type: EVENT_TYPE.initialized, fen: fen})
|
|
186
186
|
}
|
|
187
187
|
|
|
188
188
|
/**
|
|
@@ -192,7 +192,7 @@ export class Chess {
|
|
|
192
192
|
*/
|
|
193
193
|
loadPgn(pgn) {
|
|
194
194
|
this.pgn = new Pgn(pgn)
|
|
195
|
-
publishEvent(this.observers, EVENT_TYPE.initialized,
|
|
195
|
+
publishEvent(this.observers, {type: EVENT_TYPE.initialized, pgn: pgn})
|
|
196
196
|
}
|
|
197
197
|
|
|
198
198
|
/**
|
|
@@ -205,10 +205,12 @@ export class Chess {
|
|
|
205
205
|
move(move, previousMove = undefined, sloppy = true) {
|
|
206
206
|
try {
|
|
207
207
|
const moveResult = this.pgn.history.addMove(move, previousMove, sloppy)
|
|
208
|
-
publishEvent(this.observers,
|
|
208
|
+
publishEvent(this.observers,
|
|
209
|
+
{type: EVENT_TYPE.legalMove, move: move, previousMove: previousMove})
|
|
209
210
|
return moveResult
|
|
210
211
|
} catch (e) {
|
|
211
|
-
publishEvent(this.observers,
|
|
212
|
+
publishEvent(this.observers,
|
|
213
|
+
{type: EVENT_TYPE.illegalMove, move: move, previousMove: previousMove})
|
|
212
214
|
return null
|
|
213
215
|
}
|
|
214
216
|
}
|
|
@@ -257,7 +259,7 @@ export class Chess {
|
|
|
257
259
|
* @returns {string} the PGN of the game.
|
|
258
260
|
*/
|
|
259
261
|
renderPgn(renderHeader = true, renderComments = true, renderNags = true) {
|
|
260
|
-
return this.pgn.render(renderHeader, renderComments, renderNags)
|
|
262
|
+
return this.pgn.render(renderHeader, renderComments, renderNags)
|
|
261
263
|
}
|
|
262
264
|
|
|
263
265
|
/**
|
|
@@ -317,7 +319,7 @@ export class Chess {
|
|
|
317
319
|
return element.ply === move.ply
|
|
318
320
|
})
|
|
319
321
|
move.variation = move.variation.splice(index)
|
|
320
|
-
publishEvent(this.observers, EVENT_TYPE.undoMove,
|
|
322
|
+
publishEvent(this.observers, {type: EVENT_TYPE.undoMove, move: move})
|
|
321
323
|
}
|
|
322
324
|
|
|
323
325
|
plyCount() {
|