cm-chessboard 5.3.3 → 5.4.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
@@ -16,10 +16,11 @@ aspects of chess games.
16
16
  - Uses SVG for rendering
17
17
  - [Allows adding **extensions** to extend the functionality](https://shaack.com/projekte/cm-chessboard/examples/extensions/chessboard-arrows-extension.html)
18
18
 
19
- ## Extensions 🆕
19
+ ## Extensions
20
20
 
21
21
  - [Accessibility Extension](https://shaack.com/projekte/cm-chessboard/examples/extensions/chessboard-accessibility-extension.html)
22
22
  - [Arrows Extension](https://shaack.com/projekte/cm-chessboard/examples/extensions/chessboard-arrows-extension.html) (by [@barakmich](https://github.com/barakmich))
23
+ - [PromotionDialog Extension](https://shaack.com/projekte/cm-chessboard/examples/extensions/chessboard-promotion-dialog-extension.html) 🆕
23
24
 
24
25
  ## Demo and repository
25
26
 
@@ -26,7 +26,7 @@
26
26
  <h3>The chessboard</h3>
27
27
  <div class="board" id="board"></div>
28
28
  <button style="margin-bottom: 10px"
29
- onclick="window.setOrientation()">Switch Orientation
29
+ onclick="window.switchOrientation()">Switch Orientation
30
30
  </button>
31
31
  <script type="module">
32
32
  import {Chessboard} from "../../src/cm-chessboard/Chessboard.js"
@@ -0,0 +1,50 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport"
6
+ content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
7
+ <meta http-equiv="X-UA-Compatible" content="ie=edge">
8
+ <link rel="stylesheet" href="../styles/examples.css"/>
9
+ <link rel="stylesheet" href="../../assets/styles/cm-chessboard.css">
10
+ <link rel="stylesheet" href="../../src/cm-chessboard/extensions/promotion-dialog/assets/promotion-dialog.css"/>
11
+ <title>cm-chessboard promotion extension</title>
12
+ </head>
13
+ <body>
14
+ <h1><a href="../..">cm-chessboard</a></h1>
15
+ <h2>Example of the cm-chessboard PromotionDialog extension</h2>
16
+ <div id="chessboard" class="board-max-width" style="margin-bottom: 1rem">
17
+ </div>
18
+ <button style="margin-bottom: 10px"
19
+ onclick="window.switchOrientation()">Switch Orientation
20
+ </button>
21
+ <script type="module">
22
+ import {Chessboard, COLOR, INPUT_EVENT_TYPE} from "../../src/cm-chessboard/Chessboard.js"
23
+ import {PromotionDialog} from "../../src/cm-chessboard/extensions/promotion-dialog/PromotionDialog.js"
24
+
25
+ const chessboard = new Chessboard(document.getElementById("chessboard"), {
26
+ position: "2P1k3/8/8/8/6r1/8/8/2R1K3 w - - 0 1",
27
+ sprite: {
28
+ url: "../../assets/images/chessboard-sprite.svg", // pieces and markers are stored in a sprite file
29
+ },
30
+ extensions: [
31
+ {class: PromotionDialog, props: {}}
32
+ ]
33
+ })
34
+ chessboard.enableMoveInput((event) => {
35
+ console.log("8610fe", event)
36
+ if(event === INPUT_EVENT_TYPE.validateMoveInput) {
37
+
38
+ }
39
+ return true
40
+ })
41
+ chessboard.showPromotionDialog("c8", COLOR.white, (event) => {
42
+ console.log(event)
43
+ chessboard.setPiece(event.square, event.piece, true)
44
+ })
45
+ window.switchOrientation = function () {
46
+ chessboard.setOrientation(chessboard.getOrientation() === 'w' ? 'b' : 'w')
47
+ }
48
+ </script>
49
+ </body>
50
+ </html>
@@ -55,6 +55,12 @@ await board.movePiece("d5", "f4")
55
55
  })
56
56
  let i = 0
57
57
  window.setPosition = (position, animated) => {
58
+ if(position === "start") {
59
+ position = FEN.start
60
+ }
61
+ if(position === "empty") {
62
+ position = FEN.empty
63
+ }
58
64
  i++
59
65
  return board.setPosition(position, animated)
60
66
  }
package/index.html CHANGED
@@ -30,17 +30,18 @@ It works, it is cool and it is easy to use. 👍</p>
30
30
  <ul>
31
31
  <li><a href="examples/extensions/chessboard-accessibility-extension.html">Accessibility extension</a></li>
32
32
  <li><a href="examples/extensions/chessboard-arrows-extension.html">Arrows extension</a></li>
33
- <li><a href="examples/extensions/chessboard-promotion-extension.html">Promotion extension</a> 🆕</li>
33
+ <li><a href="examples/extensions/chessboard-promotion-dialog-extension.html">PromotionDialog extension</a> 🆕</li>
34
34
  </ul>
35
35
  </div>
36
36
  <h2>Chessboard</h2>
37
37
  <div class="board" id="board"></div>
38
38
  <script type="module">
39
39
  import {Chessboard} from "./src/cm-chessboard/Chessboard.js"
40
+ import {FEN} from "./src/cm-chessboard/model/Position.js"
40
41
 
41
42
  const chess = new Chess()
42
43
  const board = new Chessboard(document.getElementById("board"), {
43
- position: "start"
44
+ position: FEN.start
44
45
  })
45
46
  const interval = setInterval(() => {
46
47
  makeRandomMove()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cm-chessboard",
3
- "version": "5.3.3",
3
+ "version": "5.4.1",
4
4
  "description": "A JavaScript chessboard which is lightweight, ES6 module based, responsive, SVG rendered and without dependencies.",
5
5
  "keywords": [
6
6
  "chess",
@@ -39,7 +39,7 @@ export const MARKER_TYPE = {
39
39
  }
40
40
  export const PIECE = {
41
41
  wp: "wp", wb: "wb", wn: "wn", wr: "wr", wq: "wq", wk: "wk",
42
- bp: "bp", bb: "bb", bn: "bn", br: "br", bq: "bq", bk: "bk",
42
+ bp: "bp", bb: "bb", bn: "bn", br: "br", bq: "bq", bk: "bk"
43
43
  }
44
44
 
45
45
  export class Chessboard {
@@ -39,7 +39,7 @@ export class Arrows extends Extension {
39
39
  this.registerMethod("addArrow", this.addArrow)
40
40
  this.registerMethod("getArrows", this.getArrows)
41
41
  this.registerMethod("removeArrows", this.removeArrows)
42
- this.arrowGroup = Svg.addElement(chessboard.view.piecesLayer, "g", {class: "arrows"})
42
+ this.arrowGroup = Svg.addElement(chessboard.view.markersTopLayer, "g", {class: "arrows"})
43
43
  this.arrows = []
44
44
  }
45
45
 
@@ -0,0 +1,122 @@
1
+ /**
2
+ * Author and copyright: Stefan Haack (https://shaack.com)
3
+ * Repository: https://github.com/shaack/cm-chessboard
4
+ * License: MIT, see file 'LICENSE'
5
+ */
6
+ import {Extension, EXTENSION_POINT} from "../../model/Extension.js"
7
+ import {COLOR, PIECE} from "../../Chessboard.js"
8
+ import {DomUtils, Svg} from "../../view/ChessboardView.js"
9
+
10
+ export class PromotionDialog extends Extension {
11
+
12
+ constructor(chessboard, props) {
13
+ super(chessboard, props)
14
+
15
+ this.registerExtensionPoint(EXTENSION_POINT.redrawBoard, this.redrawDialog.bind(this))
16
+ this.registerMethod("showPromotionDialog", this.showPromotionDialog)
17
+ this.promotionDialogGroup = Svg.addElement(chessboard.view.markersTopLayer, "g", {class: "promotion-dialog-group"})
18
+ DomUtils.delegate(this.promotionDialogGroup, "click", ".promotion-dialog-button",
19
+ this.promotionDialogOnClickPiece.bind(this))
20
+ this.state = {
21
+ isShown: false,
22
+ color: undefined,
23
+ square: undefined,
24
+ callback: undefined
25
+ }
26
+
27
+ }
28
+
29
+ drawPieceButton(piece, point) {
30
+ const squareWidth = this.chessboard.view.squareWidth
31
+ const squareHeight = this.chessboard.view.squareHeight
32
+ Svg.addElement(this.promotionDialogGroup,
33
+ "rect", {
34
+ x: point.x, y: point.y, width: squareWidth, height: squareHeight,
35
+ class: "promotion-dialog-button",
36
+ "data-piece": piece
37
+ })
38
+ this.chessboard.view.drawPiece(this.promotionDialogGroup, piece, point)
39
+ }
40
+
41
+ redrawDialog() {
42
+ if (!this.state.square) {
43
+ return
44
+ }
45
+ const squareWidth = this.chessboard.view.squareWidth
46
+ const squareHeight = this.chessboard.view.squareHeight
47
+ const squareCenterPoint = this.chessboard.view.squareToPoint(this.state.square)
48
+ squareCenterPoint.x = squareCenterPoint.x + squareWidth / 2
49
+ squareCenterPoint.y = squareCenterPoint.y + squareHeight / 2
50
+ while (this.promotionDialogGroup.firstChild) {
51
+ this.promotionDialogGroup.removeChild(this.promotionDialogGroup.firstChild)
52
+ }
53
+ if (this.state.isShown) {
54
+ let turned = false
55
+ const rank = parseInt(this.state.square.charAt(1), 10)
56
+ if (this.chessboard.getOrientation() === COLOR.white && rank < 5 ||
57
+ this.chessboard.getOrientation() === COLOR.black && rank >= 5) {
58
+ turned = true
59
+ }
60
+ const offsetY = turned ? -4 * squareHeight : 0
61
+ const offsetX = squareCenterPoint.x + squareWidth > this.chessboard.view.width ? -squareWidth : 0
62
+ Svg.addElement(this.promotionDialogGroup,
63
+ "rect", {
64
+ x: squareCenterPoint.x + offsetX,
65
+ y: squareCenterPoint.y + offsetY,
66
+ width: squareWidth,
67
+ height: squareHeight * 4,
68
+ class: "promotion-dialog"
69
+ })
70
+ if (turned) {
71
+ this.drawPieceButton(PIECE[this.state.color + "q"], {
72
+ x: squareCenterPoint.x + offsetX,
73
+ y: squareCenterPoint.y - squareHeight
74
+ })
75
+ this.drawPieceButton(PIECE[this.state.color + "r"], {
76
+ x: squareCenterPoint.x + offsetX,
77
+ y: squareCenterPoint.y - squareHeight * 2
78
+ })
79
+ this.drawPieceButton(PIECE[this.state.color + "b"], {
80
+ x: squareCenterPoint.x + offsetX,
81
+ y: squareCenterPoint.y - squareHeight * 3
82
+ })
83
+ this.drawPieceButton(PIECE[this.state.color + "n"], {
84
+ x: squareCenterPoint.x + offsetX,
85
+ y: squareCenterPoint.y - squareHeight * 4
86
+ })
87
+ } else {
88
+ this.drawPieceButton(PIECE[this.state.color + "q"], {
89
+ x: squareCenterPoint.x + offsetX,
90
+ y: squareCenterPoint.y
91
+ })
92
+ this.drawPieceButton(PIECE[this.state.color + "r"], {
93
+ x: squareCenterPoint.x + offsetX,
94
+ y: squareCenterPoint.y + squareHeight
95
+ })
96
+ this.drawPieceButton(PIECE[this.state.color + "b"], {
97
+ x: squareCenterPoint.x + offsetX,
98
+ y: squareCenterPoint.y + squareHeight * 2
99
+ })
100
+ this.drawPieceButton(PIECE[this.state.color + "n"], {
101
+ x: squareCenterPoint.x + offsetX,
102
+ y: squareCenterPoint.y + squareHeight * 3
103
+ })
104
+ }
105
+ }
106
+ }
107
+
108
+ promotionDialogOnClickPiece(event) {
109
+ this.state.callback({square: this.state.square, piece: event.target.dataset.piece})
110
+ this.state.isShown = false
111
+ this.redrawDialog()
112
+ }
113
+
114
+ showPromotionDialog(square, color, callback) {
115
+ this.state.isShown = true
116
+ this.state.square = square
117
+ this.state.color = color
118
+ this.state.callback = callback
119
+ this.redrawDialog()
120
+ }
121
+
122
+ }
@@ -0,0 +1,15 @@
1
+ svg.cm-chessboard .promotion-dialog-group .promotion-dialog {
2
+ fill: black;
3
+ fill-opacity: 0.3;
4
+ stroke: rgba(0, 0, 0, 0.3); }
5
+
6
+ svg.cm-chessboard .promotion-dialog-group .promotion-dialog-button {
7
+ fill: transparent;
8
+ cursor: pointer; }
9
+ svg.cm-chessboard .promotion-dialog-group .promotion-dialog-button:hover {
10
+ fill: rgba(0, 0, 0, 0.2); }
11
+
12
+ svg.cm-chessboard .promotion-dialog-group .piece-group {
13
+ pointer-events: none; }
14
+
15
+ /*# sourceMappingURL=promotion-dialog.css.map */
@@ -0,0 +1,9 @@
1
+ {
2
+ "version": 3,
3
+ "file": "promotion-dialog.css",
4
+ "sources": [
5
+ "promotion-dialog.scss"
6
+ ],
7
+ "names": [],
8
+ "mappings": "AAAA,AAEI,GAFD,AAAA,cAAc,CACf,uBAAuB,CACrB,iBAAiB,CAAC;EAChB,IAAI,EAAE,KAAK;EACX,YAAY,EAAE,GAAG;EACjB,MAAM,EAAE,kBAAkB,GAC3B;;AANL,AAQI,GARD,AAAA,cAAc,CACf,uBAAuB,CAOrB,wBAAwB,CAAC;EACvB,IAAI,EAAE,WAAW;EACjB,MAAM,EAAE,OAAO,GAKhB;EAfL,AAYM,GAZH,AAAA,cAAc,CACf,uBAAuB,CAOrB,wBAAwB,CAIpB,KAAK,CAAC;IACN,IAAI,EAAE,kBAAkB,GACzB;;AAdP,AAiBI,GAjBD,AAAA,cAAc,CACf,uBAAuB,CAgBrB,YAAY,CAAC;EACX,cAAc,EAAE,IAAI,GACrB"
9
+ }
@@ -0,0 +1,22 @@
1
+ svg.cm-chessboard {
2
+ .promotion-dialog-group {
3
+ .promotion-dialog {
4
+ fill: black;
5
+ fill-opacity: 0.3;
6
+ stroke: rgba(0, 0, 0, 0.3)
7
+ }
8
+
9
+ .promotion-dialog-button {
10
+ fill: transparent;
11
+ cursor: pointer;
12
+
13
+ &:hover {
14
+ fill: rgba(0, 0, 0, 0.2)
15
+ }
16
+ }
17
+
18
+ .piece-group {
19
+ pointer-events: none;
20
+ }
21
+ }
22
+ }
@@ -20,10 +20,10 @@ export class Position {
20
20
  setFen(fen = FEN.empty) {
21
21
  let fenNormalized
22
22
  if (fen === "start") {
23
- console.warn("setting the position with the strings 'start' or 'empty' is deprecated, use FEN.start or FEN.empty")
23
+ console.warn("setting the position with the strings 'start' or 'empty' is deprecated, use FEN.start or FEN.empty", "used:", fen)
24
24
  fenNormalized = FEN.start
25
25
  } else if (fen === "empty" || fen === undefined) {
26
- console.warn("setting the position with the strings 'start' or 'empty' is deprecated, use FEN.start or FEN.empty")
26
+ console.warn("setting the position with the strings 'start' or 'empty' is deprecated, use FEN.start or FEN.empty", "used:", fen)
27
27
  fenNormalized = FEN.empty
28
28
  } else {
29
29
  fenNormalized = fen
@@ -140,6 +140,8 @@ export class ChessboardView {
140
140
  this.markersGroup = Svg.addElement(this.markersLayer, "g", {class: "markers"})
141
141
  this.piecesLayer = Svg.addElement(this.svg, "g", {class: "pieces-layer"})
142
142
  this.piecesGroup = Svg.addElement(this.piecesLayer, "g", {class: "pieces"})
143
+ this.markersTopLayer = Svg.addElement(this.svg, "g", {class: "markers-top-layer"})
144
+ // this.markersTopGroup = Svg.addElement(this.markersTopLayer, "g", {class: "markers-top"})
143
145
  }
144
146
 
145
147
  updateMetrics() {
@@ -278,7 +280,7 @@ export class ChessboardView {
278
280
  for (let i = 0; i < 64; i++) {
279
281
  const pieceName = squares[i]
280
282
  if (pieceName) {
281
- this.drawPiece(Position.indexToSquare(i), pieceName)
283
+ this.drawPieceOnSquare(Position.indexToSquare(i), pieceName)
282
284
  }
283
285
  }
284
286
  for (const childNode of childNodes) {
@@ -286,8 +288,35 @@ export class ChessboardView {
286
288
  }
287
289
  }
288
290
 
289
- drawPiece(square, pieceName) {
290
- const pieceGroup = Svg.addElement(this.piecesGroup, "g")
291
+ drawPiece(parentGroup, pieceName, point) {
292
+ const pieceGroup = Svg.addElement(parentGroup, "g", {})
293
+ pieceGroup.setAttribute("data-piece", pieceName)
294
+ pieceGroup.setAttribute("class", "piece-group")
295
+ const transform = (this.svg.createSVGTransform())
296
+ transform.setTranslate(point.x, point.y)
297
+ pieceGroup.transform.baseVal.appendItem(transform)
298
+ const spriteUrl = this.chessboard.props.sprite.cache ? "" : this.chessboard.props.sprite.url
299
+ const pieceUse = Svg.addElement(pieceGroup, "use", {
300
+ href: `${spriteUrl}#${pieceName}`,
301
+ class: "piece"
302
+ })
303
+ const transformScale = (this.svg.createSVGTransform())
304
+ transformScale.setScale(this.scalingY, this.scalingY)
305
+ pieceUse.transform.baseVal.appendItem(transformScale)
306
+ const transformTranslate = (this.svg.createSVGTransform())
307
+ transformTranslate.setTranslate(this.pieceXTranslate, 0)
308
+ pieceUse.transform.baseVal.appendItem(transformTranslate)
309
+ return pieceGroup
310
+ }
311
+
312
+ drawPieceOnSquare(square, pieceName) {
313
+ const point = this.squareToPoint(square)
314
+ const pieceGroup = this.drawPiece(this.piecesGroup, pieceName, point)
315
+ pieceGroup.setAttribute("data-square", square)
316
+ return pieceGroup
317
+
318
+ /*
319
+ const pieceGroup = Svg.addElement(this.piecesGroup, "g", {})
291
320
  pieceGroup.setAttribute("data-piece", pieceName)
292
321
  pieceGroup.setAttribute("data-square", square)
293
322
  const point = this.squareToPoint(square)
@@ -303,11 +332,10 @@ export class ChessboardView {
303
332
  const transformTranslate = (this.svg.createSVGTransform())
304
333
  transformTranslate.setTranslate(this.pieceXTranslate, 0)
305
334
  pieceUse.transform.baseVal.appendItem(transformTranslate)
306
- // scale
307
- const transformScale = (this.svg.createSVGTransform())
308
- transformScale.setScale(this.scalingY, this.scalingY)
309
- pieceUse.transform.baseVal.appendItem(transformScale)
310
- return pieceGroup
335
+
336
+ */
337
+
338
+ // return pieceGroup
311
339
  }
312
340
 
313
341
  setPieceVisibility(square, visible = true) {
@@ -395,14 +423,17 @@ export class ChessboardView {
395
423
  const data = {
396
424
  chessboard: this.chessboard,
397
425
  type: INPUT_EVENT_TYPE.moveInputStarted,
398
- square: square
426
+ square: square,
427
+ piece: this.chessboard.getPiece(square)
399
428
  }
400
- this.chessboard.state.invokeExtensionPoints(EXTENSION_POINT.moveInput, data) // TODO use the return value of this EP
401
429
  if (this.moveInputCallback) {
402
- return this.moveInputCallback(data)
403
- } else {
404
- return true
430
+ // the "oldschool" move input validator
431
+ data.moveInputCallbackResult = this.moveInputCallback(data)
405
432
  }
433
+ // the new extension points
434
+ const extensionPointsResult = this.chessboard.state.invokeExtensionPoints(EXTENSION_POINT.moveInput, data)
435
+ // validates, when moveInputCallbackResult and extensionPointsResult are true
436
+ return !(extensionPointsResult === false || !data.moveInputCallbackResult);
406
437
  }
407
438
 
408
439
  validateMoveInputCallback(squareFrom, squareTo) {
@@ -419,7 +450,6 @@ export class ChessboardView {
419
450
  }
420
451
  // the new extension points
421
452
  const extensionPointsResult = this.chessboard.state.invokeExtensionPoints(EXTENSION_POINT.moveInput, data)
422
- // console.log("5b0d1f", extensionPointsResult, data.moveInputCallbackResult)
423
453
  // validates, when moveInputCallbackResult and extensionPointsResult are true
424
454
  return !(extensionPointsResult === false || !data.moveInputCallbackResult);
425
455
  }
@@ -532,3 +562,23 @@ export class Svg {
532
562
  }
533
563
 
534
564
  }
565
+
566
+ export class DomUtils {
567
+ static delegate(element, eventName, selector, handler) {
568
+ const eventListener = function (event) {
569
+ let target = event.target
570
+ while (target && target !== this) {
571
+ if (target.matches(selector)) {
572
+ handler.call(target, event)
573
+ }
574
+ target = target.parentNode
575
+ }
576
+ }
577
+ element.addEventListener(eventName, eventListener)
578
+ return {
579
+ remove: function () {
580
+ element.removeEventListener(eventName, eventListener)
581
+ }
582
+ }
583
+ }
584
+ }
@@ -147,7 +147,7 @@ export class PositionsAnimation {
147
147
  animatedItem.toPoint = this.view.indexToPoint(change.toIndex)
148
148
  break
149
149
  case CHANGE_TYPE.appear:
150
- animatedItem.element = this.view.drawPiece(Position.indexToSquare(change.atIndex), change.piece)
150
+ animatedItem.element = this.view.drawPieceOnSquare(Position.indexToSquare(change.atIndex), change.piece)
151
151
  animatedItem.element.style.opacity = 0
152
152
  break
153
153
  case CHANGE_TYPE.disappear:
@@ -1,35 +0,0 @@
1
- <!doctype html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <meta name="viewport"
6
- content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
7
- <meta http-equiv="X-UA-Compatible" content="ie=edge">
8
- <link rel="stylesheet" href="../styles/examples.css"/>
9
- <link rel="stylesheet" href="../../assets/styles/cm-chessboard.css">
10
- <title>cm-chessboard promotion extension</title>
11
- </head>
12
- <body>
13
- <h1>Example of the cm-chessboard Promotion extension</h1>
14
- <p>Try to move the pawn to the c8</p>
15
- <div id="chessboard" class="board-max-width">
16
- </div>
17
- <script type="module">
18
- import {Chessboard} from "../../src/cm-chessboard/Chessboard.js"
19
- import {Promotion} from "../../src/cm-chessboard/extensions/promotion/Promotion.js"
20
-
21
- const chessboard = new Chessboard(document.getElementById("chessboard"), {
22
- position: "4k3/2P5/8/8/8/8/3Q1Q2/4K2R w K - 0 1",
23
- sprite: {
24
- url: "../../assets/images/chessboard-sprite.svg", // pieces and markers are stored in a sprite file
25
- },
26
- extensions: [
27
- {class: Promotion, props: {}}
28
- ]
29
- })
30
- chessboard.enableMoveInput((move) => {
31
- return true
32
- })
33
- </script>
34
- </body>
35
- </html>
@@ -1,36 +0,0 @@
1
- /**
2
- * Author and copyright: Stefan Haack (https://shaack.com)
3
- * Repository: https://github.com/shaack/cm-chessboard
4
- * License: MIT, see file 'LICENSE'
5
- */
6
- import {Extension, EXTENSION_POINT} from "../../model/Extension.js"
7
- import {INPUT_EVENT_TYPE, PIECE} from "../../Chessboard.js"
8
-
9
- export class Promotion extends Extension {
10
-
11
- constructor(chessboard, props) {
12
- super(chessboard, props)
13
- this.registerExtensionPoint(EXTENSION_POINT.moveInput, this.onMoveInput.bind(this))
14
- }
15
-
16
- onMoveInput(event) {
17
- if(event.type === INPUT_EVENT_TYPE.validateMoveInput) {
18
- console.log(this)
19
- console.log("976000", event,
20
- this.chessboard.getPiece(event.squareFrom),
21
- this.chessboard.getPiece(event.squareTo))
22
- if(event.piece === PIECE.wp && event.squareTo.charAt(1) === "8") {
23
- return false
24
- }
25
- }
26
- }
27
-
28
- showPromotionDialog(event) {
29
- this.promotionDialog = document.createElement("div")
30
- this.promotionDialog.style.width = "50px"
31
- this.promotionDialog.style.height = "50px"
32
- this.promotionDialog.style.backgroundColor = "white"
33
- // this.chessboard.view.
34
- }
35
-
36
- }