Commit | Line | Data |
---|---|---|
92342261 | 1 | // Game logic on a variant page |
1d184b4c BA |
2 | Vue.component('my-game', { |
3 | data: function() { | |
4 | return { | |
5 | vr: null, //object to check moves, store them, FEN.. | |
6 | mycolor: "w", | |
7 | possibleMoves: [], //filled after each valid click/dragstart | |
92342261 | 8 | choices: [], //promotion pieces, or checkered captures... (as moves) |
1d184b4c BA |
9 | start: {}, //pixels coordinates + id of starting square (click or drag) |
10 | selectedPiece: null, //moving piece (or clicked piece) | |
92342261 | 11 | conn: null, //socket connection |
dfb4afc1 | 12 | score: "*", //'*' means 'unfinished' |
2748531f | 13 | mode: "idle", //human, friend, computer or idle (when not playing) |
1d184b4c BA |
14 | oppid: "", //opponent ID in case of HH game |
15 | oppConnected: false, | |
186516b8 | 16 | seek: false, |
762b7c9c | 17 | fenStart: "", |
4b5fe306 | 18 | incheck: [], |
3840e240 | 19 | pgnTxt: "", |
92342261 | 20 | expert: (getCookie("expert") === "1" ? true : false), |
efb20746 | 21 | gameId: "", //used to limit computer moves' time |
1d184b4c BA |
22 | }; |
23 | }, | |
24 | render(h) { | |
c94bc812 | 25 | const [sizeX,sizeY] = VariantRules.size; |
0bf75837 | 26 | const smallScreen = (screen.width <= 420); |
1d184b4c BA |
27 | // Precompute hints squares to facilitate rendering |
28 | let hintSquares = doubleArray(sizeX, sizeY, false); | |
29 | this.possibleMoves.forEach(m => { hintSquares[m.end.x][m.end.y] = true; }); | |
4b5fe306 BA |
30 | // Also precompute in-check squares |
31 | let incheckSq = doubleArray(sizeX, sizeY, false); | |
32 | this.incheck.forEach(sq => { incheckSq[sq[0]][sq[1]] = true; }); | |
1d184b4c | 33 | let elementArray = []; |
2748531f | 34 | let actionArray = []; |
1dcf83e8 BA |
35 | actionArray.push( |
36 | h('button', | |
37 | { | |
38 | on: { click: this.clickGameSeek }, | |
39 | attrs: { "aria-label": 'New online game' }, | |
40 | 'class': { | |
41 | "tooltip": true, | |
42 | "bottom": true, //display below | |
43 | "seek": this.seek, | |
44 | "playing": this.mode == "human", | |
b8a0ec4a | 45 | "small": smallScreen, |
1d184b4c | 46 | }, |
1dcf83e8 BA |
47 | }, |
48 | [h('i', { 'class': { "material-icons": true } }, "accessibility")]) | |
49 | ); | |
2748531f BA |
50 | if (["idle","computer"].includes(this.mode)) |
51 | { | |
52 | actionArray.push( | |
53 | h('button', | |
1d184b4c | 54 | { |
f3802fcd | 55 | on: { click: this.clickComputerGame }, |
1d184b4c | 56 | attrs: { "aria-label": 'New game VS computer' }, |
186516b8 BA |
57 | 'class': { |
58 | "tooltip":true, | |
0706ea91 | 59 | "bottom": true, |
2748531f | 60 | "playing": this.mode == "computer", |
b8a0ec4a | 61 | "small": smallScreen, |
186516b8 | 62 | }, |
1d184b4c BA |
63 | }, |
64 | [h('i', { 'class': { "material-icons": true } }, "computer")]) | |
2748531f BA |
65 | ); |
66 | } | |
67 | if (["idle","friend"].includes(this.mode)) | |
68 | { | |
69 | actionArray.push( | |
70 | h('button', | |
71 | { | |
72 | on: { click: this.clickFriendGame }, | |
73 | attrs: { "aria-label": 'New IRL game' }, | |
74 | 'class': { | |
75 | "tooltip":true, | |
76 | "bottom": true, | |
77 | "playing": this.mode == "friend", | |
b8a0ec4a | 78 | "small": smallScreen, |
2748531f BA |
79 | }, |
80 | }, | |
81 | [h('i', { 'class': { "material-icons": true } }, "people")]) | |
82 | ); | |
83 | } | |
1d184b4c BA |
84 | if (!!this.vr) |
85 | { | |
bdb1f12d BA |
86 | const square00 = document.getElementById("sq-0-0"); |
87 | const squareWidth = !!square00 | |
88 | ? parseFloat(window.getComputedStyle(square00).width.slice(0,-2)) | |
89 | : 0; | |
90 | const indicWidth = (squareWidth>0 ? squareWidth/2 : 20); | |
1d184b4c BA |
91 | if (this.mode == "human") |
92 | { | |
93 | let connectedIndic = h( | |
94 | 'div', | |
95 | { | |
96 | "class": { | |
bdb1f12d BA |
97 | "topindicator": true, |
98 | "indic-left": true, | |
1d184b4c BA |
99 | "connected": this.oppConnected, |
100 | "disconnected": !this.oppConnected, | |
101 | }, | |
bdb1f12d BA |
102 | style: { |
103 | "width": indicWidth + "px", | |
104 | "height": indicWidth + "px", | |
105 | }, | |
1d184b4c BA |
106 | } |
107 | ); | |
108 | elementArray.push(connectedIndic); | |
109 | } | |
bdb1f12d BA |
110 | let turnIndic = h( |
111 | 'div', | |
112 | { | |
113 | "class": { | |
114 | "topindicator": true, | |
115 | "indic-right": true, | |
116 | "white-turn": this.vr.turn=="w", | |
117 | "black-turn": this.vr.turn=="b", | |
118 | }, | |
119 | style: { | |
120 | "width": indicWidth + "px", | |
121 | "height": indicWidth + "px", | |
122 | }, | |
123 | } | |
124 | ); | |
125 | elementArray.push(turnIndic); | |
3ed62725 BA |
126 | let expertSwitch = h( |
127 | 'button', | |
128 | { | |
129 | on: { click: this.toggleExpertMode }, | |
130 | attrs: { "aria-label": 'Toggle expert mode' }, | |
131 | 'class': { | |
132 | "tooltip":true, | |
133 | "topindicator": true, | |
134 | "indic-right": true, | |
135 | "expert-switch": true, | |
136 | "expert-mode": this.expert, | |
b8a0ec4a | 137 | "small": smallScreen, |
3ed62725 BA |
138 | }, |
139 | }, | |
2748531f | 140 | [h('i', { 'class': { "material-icons": true } }, "visibility_off")] |
3ed62725 BA |
141 | ); |
142 | elementArray.push(expertSwitch); | |
1d184b4c BA |
143 | let choices = h('div', |
144 | { | |
145 | attrs: { "id": "choices" }, | |
146 | 'class': { 'row': true }, | |
147 | style: { | |
1d184b4c BA |
148 | "display": this.choices.length>0?"block":"none", |
149 | "top": "-" + ((sizeY/2)*squareWidth+squareWidth/2) + "px", | |
150 | "width": (this.choices.length * squareWidth) + "px", | |
151 | "height": squareWidth + "px", | |
152 | }, | |
153 | }, | |
154 | this.choices.map( m => { //a "choice" is a move | |
155 | return h('div', | |
156 | { | |
c94bc812 BA |
157 | 'class': { |
158 | 'board': true, | |
8a196305 | 159 | ['board'+sizeY]: true, |
c94bc812 | 160 | }, |
1d184b4c BA |
161 | style: { |
162 | 'width': (100/this.choices.length) + "%", | |
163 | 'padding-bottom': (100/this.choices.length) + "%", | |
164 | }, | |
165 | }, | |
166 | [h('img', | |
167 | { | |
4b353936 BA |
168 | attrs: { "src": '/images/pieces/' + |
169 | VariantRules.getPpath(m.appear[0].c+m.appear[0].p) + '.svg' }, | |
c94bc812 | 170 | 'class': { 'choice-piece': true }, |
1d184b4c BA |
171 | on: { "click": e => { this.play(m); this.choices=[]; } }, |
172 | }) | |
173 | ] | |
174 | ); | |
175 | }) | |
176 | ); | |
177 | // Create board element (+ reserves if needed by variant or mode) | |
178 | let gameDiv = h('div', | |
179 | { | |
180 | 'class': { 'game': true }, | |
181 | }, | |
182 | [_.range(sizeX).map(i => { | |
183 | let ci = this.mycolor=='w' ? i : sizeX-i-1; | |
184 | return h( | |
185 | 'div', | |
186 | { | |
187 | 'class': { | |
188 | 'row': true, | |
189 | }, | |
190 | style: { 'opacity': this.choices.length>0?"0.5":"1" }, | |
191 | }, | |
192 | _.range(sizeY).map(j => { | |
193 | let cj = this.mycolor=='w' ? j : sizeY-j-1; | |
194 | let elems = []; | |
195 | if (this.vr.board[ci][cj] != VariantRules.EMPTY) | |
196 | { | |
197 | elems.push( | |
198 | h( | |
199 | 'img', | |
200 | { | |
201 | 'class': { | |
202 | 'piece': true, | |
4b353936 BA |
203 | 'ghost': !!this.selectedPiece |
204 | && this.selectedPiece.parentNode.id == "sq-"+ci+"-"+cj, | |
1d184b4c BA |
205 | }, |
206 | attrs: { | |
4b353936 BA |
207 | src: "/images/pieces/" + |
208 | VariantRules.getPpath(this.vr.board[ci][cj]) + ".svg", | |
1d184b4c BA |
209 | }, |
210 | } | |
211 | ) | |
212 | ); | |
213 | } | |
3ed62725 | 214 | if (!this.expert && hintSquares[ci][cj]) |
1d184b4c BA |
215 | { |
216 | elems.push( | |
217 | h( | |
218 | 'img', | |
219 | { | |
220 | 'class': { | |
221 | 'mark-square': true, | |
222 | }, | |
223 | attrs: { | |
224 | src: "/images/mark.svg", | |
225 | }, | |
226 | } | |
227 | ) | |
228 | ); | |
229 | } | |
30ff6e04 | 230 | const lm = this.vr.lastMove; |
3300df38 BA |
231 | const showLight = !this.expert && |
232 | (this.mode!="idle" || this.cursor==this.vr.moves.length); | |
1d184b4c BA |
233 | return h( |
234 | 'div', | |
235 | { | |
236 | 'class': { | |
237 | 'board': true, | |
8a196305 | 238 | ['board'+sizeY]: true, |
3300df38 BA |
239 | 'light-square': (i+j)%2==0, |
240 | 'dark-square': (i+j)%2==1, | |
241 | 'highlight': showLight && !!lm && _.isMatch(lm.end, {x:ci,y:cj}), | |
242 | 'incheck': showLight && incheckSq[ci][cj], | |
1d184b4c BA |
243 | }, |
244 | attrs: { | |
245 | id: this.getSquareId({x:ci,y:cj}), | |
246 | }, | |
247 | }, | |
248 | elems | |
249 | ); | |
250 | }) | |
251 | ); | |
252 | }), choices] | |
253 | ); | |
204e289b BA |
254 | if (this.mode != "idle") |
255 | { | |
256 | actionArray.push( | |
257 | h('button', | |
258 | { | |
259 | on: { click: this.resign }, | |
260 | attrs: { "aria-label": 'Resign' }, | |
261 | 'class': { | |
262 | "tooltip":true, | |
263 | "bottom": true, | |
b8a0ec4a | 264 | "small": smallScreen, |
204e289b | 265 | }, |
0706ea91 | 266 | }, |
204e289b BA |
267 | [h('i', { 'class': { "material-icons": true } }, "flag")]) |
268 | ); | |
269 | } | |
e64084da BA |
270 | else if (this.vr.moves.length > 0) |
271 | { | |
272 | // A game finished, and another is not started yet: allow navigation | |
273 | actionArray = actionArray.concat([ | |
274 | h('button', | |
275 | { | |
e64084da BA |
276 | on: { click: e => this.undo() }, |
277 | attrs: { "aria-label": 'Undo' }, | |
92342261 BA |
278 | "class": { |
279 | "small": smallScreen, | |
280 | "marginleft": true, | |
281 | }, | |
e64084da BA |
282 | }, |
283 | [h('i', { 'class': { "material-icons": true } }, "fast_rewind")]), | |
284 | h('button', | |
285 | { | |
286 | on: { click: e => this.play() }, | |
287 | attrs: { "aria-label": 'Play' }, | |
b8a0ec4a | 288 | "class": { "small": smallScreen }, |
e64084da BA |
289 | }, |
290 | [h('i', { 'class': { "material-icons": true } }, "fast_forward")]), | |
291 | ] | |
292 | ); | |
293 | } | |
2748531f BA |
294 | if (this.mode == "friend") |
295 | { | |
296 | actionArray = actionArray.concat( | |
297 | [ | |
298 | h('button', | |
299 | { | |
2748531f BA |
300 | on: { click: this.undoInGame }, |
301 | attrs: { "aria-label": 'Undo' }, | |
92342261 BA |
302 | "class": { |
303 | "small": smallScreen, | |
304 | "marginleft": true, | |
305 | }, | |
2748531f BA |
306 | }, |
307 | [h('i', { 'class': { "material-icons": true } }, "undo")] | |
308 | ), | |
309 | h('button', | |
310 | { | |
311 | on: { click: () => { this.mycolor = this.vr.getOppCol(this.mycolor) } }, | |
312 | attrs: { "aria-label": 'Flip' }, | |
b8a0ec4a | 313 | "class": { "small": smallScreen }, |
2748531f BA |
314 | }, |
315 | [h('i', { 'class': { "material-icons": true } }, "cached")] | |
316 | ), | |
317 | ]); | |
318 | } | |
1d184b4c | 319 | elementArray.push(gameDiv); |
5c42c64e | 320 | if (!!this.vr.reserve) |
1221ac47 | 321 | { |
6752407b | 322 | const shiftIdx = (this.mycolor=="w" ? 0 : 1); |
5c42c64e | 323 | let myReservePiecesArray = []; |
1221ac47 BA |
324 | for (let i=0; i<VariantRules.RESERVE_PIECES.length; i++) |
325 | { | |
5c42c64e BA |
326 | myReservePiecesArray.push(h('div', |
327 | { | |
328 | 'class': {'board':true, ['board'+sizeY]:true}, | |
6752407b | 329 | attrs: { id: this.getSquareId({x:sizeX+shiftIdx,y:i}) } |
5c42c64e BA |
330 | }, |
331 | [ | |
332 | h('img', | |
1221ac47 BA |
333 | { |
334 | 'class': {"piece":true}, | |
335 | attrs: { | |
336 | "src": "/images/pieces/" + | |
337 | this.vr.getReservePpath(this.mycolor,i) + ".svg", | |
1221ac47 | 338 | } |
5c42c64e BA |
339 | }), |
340 | h('sup', | |
92342261 | 341 | {"class": { "reserve-count": true } }, |
5c42c64e BA |
342 | [ this.vr.reserve[this.mycolor][VariantRules.RESERVE_PIECES[i]] ] |
343 | ) | |
344 | ])); | |
345 | } | |
346 | let oppReservePiecesArray = []; | |
347 | const oppCol = this.vr.getOppCol(this.mycolor); | |
348 | for (let i=0; i<VariantRules.RESERVE_PIECES.length; i++) | |
349 | { | |
350 | oppReservePiecesArray.push(h('div', | |
351 | { | |
352 | 'class': {'board':true, ['board'+sizeY]:true}, | |
6752407b | 353 | attrs: { id: this.getSquareId({x:sizeX+(1-shiftIdx),y:i}) } |
5c42c64e BA |
354 | }, |
355 | [ | |
356 | h('img', | |
357 | { | |
358 | 'class': {"piece":true}, | |
359 | attrs: { | |
360 | "src": "/images/pieces/" + | |
361 | this.vr.getReservePpath(oppCol,i) + ".svg", | |
362 | } | |
363 | }), | |
364 | h('sup', | |
92342261 | 365 | {"class": { "reserve-count": true } }, |
5c42c64e BA |
366 | [ this.vr.reserve[oppCol][VariantRules.RESERVE_PIECES[i]] ] |
367 | ) | |
368 | ])); | |
1221ac47 | 369 | } |
5c42c64e BA |
370 | let reserves = h('div', |
371 | { | |
92342261 BA |
372 | 'class':{ |
373 | 'game': true, | |
374 | "reserve-div": true, | |
375 | }, | |
5c42c64e BA |
376 | }, |
377 | [ | |
378 | h('div', | |
379 | { | |
92342261 BA |
380 | 'class': { |
381 | 'row': true, | |
382 | "reserve-row-1": true, | |
383 | }, | |
5c42c64e BA |
384 | }, |
385 | myReservePiecesArray | |
386 | ), | |
1221ac47 BA |
387 | h('div', |
388 | { 'class': { 'row': true }}, | |
5c42c64e | 389 | oppReservePiecesArray |
1221ac47 | 390 | ) |
5c42c64e | 391 | ] |
1221ac47 | 392 | ); |
5c42c64e | 393 | elementArray.push(reserves); |
1221ac47 | 394 | } |
f3802fcd | 395 | const eogMessage = this.getEndgameMessage(this.score); |
1d184b4c BA |
396 | const modalEog = [ |
397 | h('input', | |
398 | { | |
ecf44502 | 399 | attrs: { "id": "modal-eog", type: "checkbox" }, |
1d184b4c BA |
400 | "class": { "modal": true }, |
401 | }), | |
402 | h('div', | |
403 | { | |
c148615e | 404 | attrs: { "role": "dialog", "aria-labelledby": "modal-eog" }, |
1d184b4c BA |
405 | }, |
406 | [ | |
407 | h('div', | |
408 | { | |
409 | "class": { "card": true, "smallpad": true }, | |
410 | }, | |
01a135e2 BA |
411 | [ |
412 | h('label', | |
413 | { | |
414 | attrs: { "for": "modal-eog" }, | |
415 | "class": { "modal-close": true }, | |
416 | } | |
417 | ), | |
418 | h('h3', | |
419 | { | |
420 | "class": { "section": true }, | |
421 | domProps: { innerHTML: eogMessage }, | |
422 | } | |
423 | ) | |
424 | ] | |
1d184b4c BA |
425 | ) |
426 | ] | |
427 | ) | |
428 | ]; | |
429 | elementArray = elementArray.concat(modalEog); | |
430 | } | |
431 | const modalNewgame = [ | |
432 | h('input', | |
433 | { | |
ecf44502 | 434 | attrs: { "id": "modal-newgame", type: "checkbox" }, |
1d184b4c BA |
435 | "class": { "modal": true }, |
436 | }), | |
437 | h('div', | |
438 | { | |
c148615e | 439 | attrs: { "role": "dialog", "aria-labelledby": "modal-newgame" }, |
1d184b4c BA |
440 | }, |
441 | [ | |
442 | h('div', | |
443 | { | |
444 | "class": { "card": true, "smallpad": true }, | |
445 | }, | |
446 | [ | |
447 | h('label', | |
448 | { | |
ecf44502 | 449 | attrs: { "id": "close-newgame", "for": "modal-newgame" }, |
1d184b4c BA |
450 | "class": { "modal-close": true }, |
451 | } | |
452 | ), | |
453 | h('h3', | |
454 | { | |
455 | "class": { "section": true }, | |
456 | domProps: { innerHTML: "New game" }, | |
457 | } | |
458 | ), | |
459 | h('p', | |
460 | { | |
461 | "class": { "section": true }, | |
462 | domProps: { innerHTML: "Waiting for opponent..." }, | |
463 | } | |
464 | ) | |
465 | ] | |
466 | ) | |
467 | ] | |
468 | ) | |
469 | ]; | |
470 | elementArray = elementArray.concat(modalNewgame); | |
2748531f BA |
471 | const modalFenEdit = [ |
472 | h('input', | |
473 | { | |
474 | attrs: { "id": "modal-fenedit", type: "checkbox" }, | |
475 | "class": { "modal": true }, | |
476 | }), | |
477 | h('div', | |
478 | { | |
479 | attrs: { "role": "dialog", "aria-labelledby": "modal-fenedit" }, | |
480 | }, | |
481 | [ | |
482 | h('div', | |
483 | { | |
484 | "class": { "card": true, "smallpad": true }, | |
485 | }, | |
486 | [ | |
487 | h('label', | |
488 | { | |
489 | attrs: { "id": "close-fenedit", "for": "modal-fenedit" }, | |
490 | "class": { "modal-close": true }, | |
491 | } | |
492 | ), | |
493 | h('h3', | |
494 | { | |
495 | "class": { "section": true }, | |
496 | domProps: { innerHTML: "Position + flags (FEN):" }, | |
497 | } | |
498 | ), | |
499 | h('input', | |
500 | { | |
501 | attrs: { | |
502 | "id": "input-fen", | |
503 | type: "text", | |
504 | value: VariantRules.GenRandInitFen(), | |
505 | }, | |
506 | } | |
507 | ), | |
508 | h('button', | |
509 | { | |
510 | on: { click: | |
511 | () => { | |
512 | const fen = document.getElementById("input-fen").value; | |
513 | document.getElementById("modal-fenedit").checked = false; | |
514 | this.newGame("friend", fen); | |
515 | } | |
516 | }, | |
517 | domProps: { innerHTML: "Ok" }, | |
518 | } | |
519 | ), | |
520 | h('button', | |
521 | { | |
522 | on: { click: | |
523 | () => { | |
524 | document.getElementById("input-fen").value = | |
525 | VariantRules.GenRandInitFen(); | |
526 | } | |
527 | }, | |
528 | domProps: { innerHTML: "Random" }, | |
529 | } | |
530 | ), | |
531 | ] | |
532 | ) | |
533 | ] | |
534 | ) | |
535 | ]; | |
536 | elementArray = elementArray.concat(modalFenEdit); | |
1d184b4c BA |
537 | const actions = h('div', |
538 | { | |
539 | attrs: { "id": "actions" }, | |
540 | 'class': { 'text-center': true }, | |
541 | }, | |
542 | actionArray | |
543 | ); | |
544 | elementArray.push(actions); | |
01a135e2 BA |
545 | if (this.score != "*") |
546 | { | |
547 | elementArray.push( | |
548 | h('div', | |
01ca2adc | 549 | { attrs: { id: "pgn-div" } }, |
01a135e2 | 550 | [ |
01ca2adc BA |
551 | h('a', |
552 | { | |
553 | attrs: { | |
554 | id: "download", | |
555 | href: "#", | |
556 | } | |
557 | } | |
558 | ), | |
01a135e2 BA |
559 | h('p', |
560 | { | |
01ca2adc BA |
561 | attrs: { id: "pgn-game" }, |
562 | on: { click: this.download }, | |
85be503d BA |
563 | domProps: { innerHTML: this.pgnTxt } |
564 | } | |
565 | ) | |
566 | ] | |
567 | ) | |
568 | ); | |
569 | } | |
570 | else if (this.mode != "idle") | |
571 | { | |
2748531f | 572 | // Show current FEN |
85be503d BA |
573 | elementArray.push( |
574 | h('div', | |
575 | { attrs: { id: "fen-div" } }, | |
576 | [ | |
577 | h('p', | |
578 | { | |
579 | attrs: { id: "fen-string" }, | |
2748531f | 580 | domProps: { innerHTML: this.vr.getFen() } |
01a135e2 BA |
581 | } |
582 | ) | |
583 | ] | |
584 | ) | |
585 | ); | |
586 | } | |
1d184b4c BA |
587 | return h( |
588 | 'div', | |
589 | { | |
590 | 'class': { | |
591 | "col-sm-12":true, | |
592 | "col-md-8":true, | |
593 | "col-md-offset-2":true, | |
594 | "col-lg-6":true, | |
595 | "col-lg-offset-3":true, | |
596 | }, | |
dda21a71 | 597 | // NOTE: click = mousedown + mouseup |
1d184b4c BA |
598 | on: { |
599 | mousedown: this.mousedown, | |
600 | mousemove: this.mousemove, | |
601 | mouseup: this.mouseup, | |
ffea77d9 BA |
602 | touchstart: this.mousedown, |
603 | touchmove: this.mousemove, | |
604 | touchend: this.mouseup, | |
1d184b4c BA |
605 | }, |
606 | }, | |
607 | elementArray | |
608 | ); | |
609 | }, | |
610 | created: function() { | |
611 | const url = socketUrl; | |
612 | const continuation = (localStorage.getItem("variant") === variant); | |
b019d603 | 613 | this.myid = continuation ? localStorage.getItem("myid") : getRandString(); |
92ff5bae BA |
614 | if (!continuation) |
615 | { | |
92342261 BA |
616 | // HACK: play a small silent sound to allow "new game" sound later |
617 | // if tab not focused (TODO: does it really work ?!) | |
92ff5bae BA |
618 | new Audio("/sounds/silent.mp3").play().then(() => {}).catch(err => {}); |
619 | } | |
1d184b4c | 620 | this.conn = new WebSocket(url + "/?sid=" + this.myid + "&page=" + variant); |
d35f20e4 | 621 | const socketOpenListener = () => { |
1d184b4c BA |
622 | if (continuation) |
623 | { | |
dfb4afc1 BA |
624 | const fen = localStorage.getItem("fen"); |
625 | const mycolor = localStorage.getItem("mycolor"); | |
626 | const oppid = localStorage.getItem("oppid"); | |
627 | const moves = JSON.parse(localStorage.getItem("moves")); | |
628 | this.newGame("human", fen, mycolor, oppid, moves, true); | |
a29d9d6b | 629 | // Send ping to server (answer pong if opponent is connected) |
ecf44502 | 630 | this.conn.send(JSON.stringify({code:"ping",oppid:this.oppid})); |
1d184b4c | 631 | } |
30ff6e04 BA |
632 | else if (localStorage.getItem("newgame") === variant) |
633 | { | |
634 | // New game request has been cancelled on disconnect | |
001344b9 | 635 | this.newGame("human", undefined, undefined, undefined, undefined, "reconnect"); |
30ff6e04 | 636 | } |
1d184b4c | 637 | }; |
d35f20e4 | 638 | const socketMessageListener = msg => { |
1d184b4c BA |
639 | const data = JSON.parse(msg.data); |
640 | switch (data.code) | |
641 | { | |
642 | case "newgame": //opponent found | |
92342261 BA |
643 | // oppid: opponent socket ID |
644 | this.newGame("human", data.fen, data.color, data.oppid); | |
1d184b4c BA |
645 | break; |
646 | case "newmove": //..he played! | |
647 | this.play(data.move, "animate"); | |
648 | break; | |
f3802fcd | 649 | case "pong": //received if we sent a ping (game still alive on our side) |
1d184b4c | 650 | this.oppConnected = true; |
a29d9d6b | 651 | const L = this.vr.moves.length; |
f3802fcd | 652 | // Send our "last state" informations to opponent |
a29d9d6b BA |
653 | this.conn.send(JSON.stringify({ |
654 | code:"lastate", | |
f3802fcd | 655 | oppid:this.oppid, |
a29d9d6b BA |
656 | lastMove:L>0?this.vr.moves[L-1]:undefined, |
657 | movesCount:L, | |
658 | })); | |
1d184b4c | 659 | break; |
a29d9d6b BA |
660 | case "lastate": //got opponent infos about last move (we might have resigned) |
661 | if (this.mode!="human" || this.oppid!=data.oppid) | |
662 | { | |
663 | // OK, we resigned | |
664 | this.conn.send(JSON.stringify({ | |
665 | code:"lastate", | |
f3802fcd | 666 | oppid:this.oppid, |
a29d9d6b BA |
667 | lastMove:undefined, |
668 | movesCount:-1, | |
669 | })); | |
670 | } | |
671 | else if (data.movesCount < 0) | |
672 | { | |
673 | // OK, he resigned | |
674 | this.endGame(this.mycolor=="w"?"1-0":"0-1"); | |
675 | } | |
676 | else if (data.movesCount < this.vr.moves.length) | |
677 | { | |
678 | // We must tell last move to opponent | |
679 | const L = this.vr.moves.length; | |
680 | this.conn.send(JSON.stringify({ | |
681 | code:"lastate", | |
f3802fcd | 682 | oppid:this.oppid, |
a29d9d6b BA |
683 | lastMove:this.vr.moves[L-1], |
684 | movesCount:L, | |
685 | })); | |
686 | } | |
687 | else if (data.movesCount > this.vr.moves.length) //just got last move from him | |
688 | this.play(data.lastMove, "animate"); | |
ecf44502 | 689 | break; |
1d184b4c | 690 | case "resign": //..you won! |
dfb4afc1 | 691 | this.endGame(this.mycolor=="w"?"1-0":"0-1"); |
1d184b4c | 692 | break; |
f3802fcd | 693 | // TODO: also use (dis)connect info to count online players? |
1d184b4c BA |
694 | case "connect": |
695 | case "disconnect": | |
696 | if (this.mode == "human" && this.oppid == data.id) | |
697 | this.oppConnected = (data.code == "connect"); | |
698 | break; | |
699 | } | |
700 | }; | |
d35f20e4 | 701 | const socketCloseListener = () => { |
d35f20e4 BA |
702 | this.conn = new WebSocket(url + "/?sid=" + this.myid + "&page=" + variant); |
703 | this.conn.addEventListener('open', socketOpenListener); | |
704 | this.conn.addEventListener('message', socketMessageListener); | |
705 | this.conn.addEventListener('close', socketCloseListener); | |
706 | }; | |
707 | this.conn.onopen = socketOpenListener; | |
708 | this.conn.onmessage = socketMessageListener; | |
709 | this.conn.onclose = socketCloseListener; | |
e64084da BA |
710 | // Listen to keyboard left/right to navigate in game |
711 | document.onkeydown = event => { | |
2748531f | 712 | if (this.mode == "idle" && !!this.vr && this.vr.moves.length > 0 |
e64084da BA |
713 | && [37,39].includes(event.keyCode)) |
714 | { | |
715 | event.preventDefault(); | |
716 | if (event.keyCode == 37) //Back | |
717 | this.undo(); | |
718 | else //Forward (39) | |
719 | this.play(); | |
720 | } | |
721 | }; | |
1d184b4c BA |
722 | }, |
723 | methods: { | |
01ca2adc BA |
724 | download: function() { |
725 | let content = document.getElementById("pgn-game").innerHTML; | |
726 | content = content.replace(/<br>/g, "\n"); | |
727 | // Prepare and trigger download link | |
728 | let downloadAnchor = document.getElementById("download"); | |
729 | downloadAnchor.setAttribute("download", "game.pgn"); | |
92342261 BA |
730 | downloadAnchor.href = "data:text/plain;charset=utf-8," + |
731 | encodeURIComponent(content); | |
01ca2adc BA |
732 | downloadAnchor.click(); |
733 | }, | |
dfb4afc1 BA |
734 | endGame: function(score) { |
735 | this.score = score; | |
ecf44502 | 736 | let modalBox = document.getElementById("modal-eog"); |
186516b8 | 737 | modalBox.checked = true; |
204e289b | 738 | // Variants may have special PGN structure (so next function isn't defined here) |
3840e240 BA |
739 | this.pgnTxt = this.vr.getPGN(this.mycolor, this.score, this.fenStart, this.mode); |
740 | setTimeout(() => { modalBox.checked = false; }, 2000); | |
1d184b4c BA |
741 | if (this.mode == "human") |
742 | this.clearStorage(); | |
3840e240 | 743 | this.mode = "idle"; |
e64084da | 744 | this.cursor = this.vr.moves.length; //to navigate in finished game |
1d184b4c BA |
745 | this.oppid = ""; |
746 | }, | |
f3802fcd BA |
747 | getEndgameMessage: function(score) { |
748 | let eogMessage = "Unfinished"; | |
749 | switch (this.score) | |
750 | { | |
751 | case "1-0": | |
752 | eogMessage = "White win"; | |
753 | break; | |
754 | case "0-1": | |
755 | eogMessage = "Black win"; | |
756 | break; | |
757 | case "1/2": | |
758 | eogMessage = "Draw"; | |
759 | break; | |
760 | } | |
761 | return eogMessage; | |
762 | }, | |
762b7c9c BA |
763 | setStorage: function() { |
764 | localStorage.setItem("myid", this.myid); | |
765 | localStorage.setItem("variant", variant); | |
766 | localStorage.setItem("mycolor", this.mycolor); | |
767 | localStorage.setItem("oppid", this.oppid); | |
768 | localStorage.setItem("fenStart", this.fenStart); | |
769 | localStorage.setItem("moves", JSON.stringify(this.vr.moves)); | |
1d184b4c | 770 | localStorage.setItem("fen", this.vr.getFen()); |
762b7c9c BA |
771 | }, |
772 | updateStorage: function() { | |
dfb4afc1 | 773 | localStorage.setItem("moves", JSON.stringify(this.vr.moves)); |
762b7c9c | 774 | localStorage.setItem("fen", this.vr.getFen()); |
1d184b4c BA |
775 | }, |
776 | clearStorage: function() { | |
777 | delete localStorage["variant"]; | |
778 | delete localStorage["myid"]; | |
779 | delete localStorage["mycolor"]; | |
780 | delete localStorage["oppid"]; | |
762b7c9c | 781 | delete localStorage["fenStart"]; |
1d184b4c | 782 | delete localStorage["fen"]; |
dfb4afc1 | 783 | delete localStorage["moves"]; |
1d184b4c | 784 | }, |
c148615e BA |
785 | // HACK because mini-css tooltips are persistent after click... |
786 | getRidOfTooltip: function(elt) { | |
787 | elt.style.visibility = "hidden"; | |
788 | setTimeout(() => { elt.style.visibility="visible"; }, 100); | |
789 | }, | |
790 | clickGameSeek: function(e) { | |
791 | this.getRidOfTooltip(e.currentTarget); | |
f3802fcd BA |
792 | if (this.mode == "human") |
793 | return; //no newgame while playing | |
794 | if (this.seek) | |
01a135e2 | 795 | { |
283d06a4 | 796 | this.conn.send(JSON.stringify({code:"cancelnewgame"})); |
f3802fcd | 797 | delete localStorage["newgame"]; //cancel game seek |
01a135e2 BA |
798 | this.seek = false; |
799 | } | |
f3802fcd | 800 | else |
f3802fcd | 801 | this.newGame("human"); |
f3802fcd | 802 | }, |
c148615e BA |
803 | clickComputerGame: function(e) { |
804 | this.getRidOfTooltip(e.currentTarget); | |
f3802fcd BA |
805 | if (this.mode == "human") |
806 | return; //no newgame while playing | |
807 | this.newGame("computer"); | |
808 | }, | |
2748531f BA |
809 | clickFriendGame: function(e) { |
810 | this.getRidOfTooltip(e.currentTarget); | |
811 | document.getElementById("modal-fenedit").checked = true; | |
812 | }, | |
c148615e BA |
813 | toggleExpertMode: function(e) { |
814 | this.getRidOfTooltip(e.currentTarget); | |
815 | this.expert = !this.expert; | |
b019d603 | 816 | setCookie("expert", this.expert ? "1" : "0"); |
c148615e | 817 | }, |
2748531f BA |
818 | resign: function(e) { |
819 | this.getRidOfTooltip(e.currentTarget); | |
c148615e BA |
820 | if (this.mode == "human" && this.oppConnected) |
821 | { | |
822 | try { | |
823 | this.conn.send(JSON.stringify({code: "resign", oppid: this.oppid})); | |
824 | } catch (INVALID_STATE_ERR) { | |
825 | return; //socket is not ready (and not yet reconnected) | |
826 | } | |
827 | } | |
828 | this.endGame(this.mycolor=="w"?"0-1":"1-0"); | |
829 | }, | |
dfb4afc1 | 830 | newGame: function(mode, fenInit, color, oppId, moves, continuation) { |
55eb331d | 831 | const fen = fenInit || VariantRules.GenRandInitFen(); |
1d184b4c BA |
832 | console.log(fen); //DEBUG |
833 | if (mode=="human" && !oppId) | |
834 | { | |
cd3174c5 BA |
835 | const storageVariant = localStorage.getItem("variant"); |
836 | if (!!storageVariant && storageVariant !== variant) | |
837 | { | |
cd3174c5 BA |
838 | alert("Finish your " + storageVariant + " game first!"); |
839 | return; | |
840 | } | |
1d184b4c | 841 | // Send game request and wait.. |
01a135e2 BA |
842 | localStorage["newgame"] = variant; |
843 | this.seek = true; | |
1d184b4c | 844 | this.clearStorage(); //in case of |
d35f20e4 BA |
845 | try { |
846 | this.conn.send(JSON.stringify({code:"newgame", fen:fen})); | |
847 | } catch (INVALID_STATE_ERR) { | |
848 | return; //nothing achieved | |
849 | } | |
f3802fcd | 850 | if (continuation !== "reconnect") //TODO: bad HACK... |
a68d899d | 851 | { |
ecf44502 | 852 | let modalBox = document.getElementById("modal-newgame"); |
a68d899d BA |
853 | modalBox.checked = true; |
854 | setTimeout(() => { modalBox.checked = false; }, 2000); | |
855 | } | |
1d184b4c BA |
856 | return; |
857 | } | |
b019d603 | 858 | this.gameId = getRandString(); |
dfb4afc1 | 859 | this.vr = new VariantRules(fen, moves || []); |
c148615e | 860 | this.score = "*"; |
3840e240 | 861 | this.pgnTxt = ""; //redundant with this.score = "*", but cleaner |
1d184b4c | 862 | this.mode = mode; |
1fcaa356 | 863 | this.incheck = []; //in case of |
2748531f | 864 | this.fenStart = (continuation ? localStorage.getItem("fenStart") : fen); |
1d184b4c BA |
865 | if (mode=="human") |
866 | { | |
867 | // Opponent found! | |
868 | if (!continuation) | |
869 | { | |
ecf44502 | 870 | // Not playing sound on game continuation: |
ea8417ff | 871 | new Audio("/sounds/newgame.mp3").play().then(() => {}).catch(err => {}); |
ecf44502 | 872 | document.getElementById("modal-newgame").checked = false; |
1d184b4c BA |
873 | } |
874 | this.oppid = oppId; | |
875 | this.oppConnected = true; | |
876 | this.mycolor = color; | |
186516b8 | 877 | this.seek = false; |
e64a4eff BA |
878 | if (!!moves && moves.length > 0) //imply continuation |
879 | { | |
e64a4eff | 880 | const lastMove = moves[moves.length-1]; |
cd4cad04 | 881 | this.vr.undo(lastMove); |
46302e64 | 882 | this.incheck = this.vr.getCheckSquares(lastMove); |
e64a4eff BA |
883 | this.vr.play(lastMove, "ingame"); |
884 | } | |
186516b8 | 885 | delete localStorage["newgame"]; |
762b7c9c | 886 | this.setStorage(); //in case of interruptions |
1d184b4c | 887 | } |
2748531f | 888 | else if (mode == "computer") |
1d184b4c | 889 | { |
f3c10e18 | 890 | this.mycolor = Math.random() < 0.5 ? 'w' : 'b'; |
1d184b4c BA |
891 | if (this.mycolor == 'b') |
892 | setTimeout(this.playComputerMove, 500); | |
893 | } | |
2748531f | 894 | //else: against a (IRL) friend: nothing more to do |
1d184b4c BA |
895 | }, |
896 | playComputerMove: function() { | |
4b353936 | 897 | const timeStart = Date.now(); |
92342261 BA |
898 | // We use moves' count to know if search finished: |
899 | const nbMoves = this.vr.moves.length; | |
efb20746 | 900 | const gameId = this.gameId; //to know if game was reset before timer end |
3c09dc49 BA |
901 | setTimeout( |
902 | () => { | |
efb20746 BA |
903 | if (gameId != this.gameId) |
904 | return; //game stopped | |
3c09dc49 BA |
905 | const L = this.vr.moves.length; |
906 | if (nbMoves == L || !this.vr.moves[L-1].notation) //move search didn't finish | |
907 | this.vr.shouldReturn = true; | |
908 | }, 5000); | |
46302e64 | 909 | const compMove = this.vr.getComputerMove(); |
4b353936 BA |
910 | // (first move) HACK: avoid selecting elements before they appear on page: |
911 | const delay = Math.max(500-(Date.now()-timeStart), 0); | |
912 | setTimeout(() => this.play(compMove, "animate"), delay); | |
1d184b4c BA |
913 | }, |
914 | // Get the identifier of a HTML table cell from its numeric coordinates o.x,o.y. | |
915 | getSquareId: function(o) { | |
916 | // NOTE: a separator is required to allow any size of board | |
917 | return "sq-" + o.x + "-" + o.y; | |
918 | }, | |
919 | // Inverse function | |
920 | getSquareFromId: function(id) { | |
921 | let idParts = id.split('-'); | |
922 | return [parseInt(idParts[1]), parseInt(idParts[2])]; | |
923 | }, | |
924 | mousedown: function(e) { | |
925 | e = e || window.event; | |
44461547 BA |
926 | let ingame = false; |
927 | let elem = e.target; | |
928 | while (!ingame && elem !== null) | |
929 | { | |
930 | if (elem.classList.contains("game")) | |
931 | { | |
932 | ingame = true; | |
933 | break; | |
934 | } | |
935 | elem = elem.parentElement; | |
936 | } | |
937 | if (!ingame) //let default behavior (click on button...) | |
938 | return; | |
1d184b4c BA |
939 | e.preventDefault(); //disable native drag & drop |
940 | if (!this.selectedPiece && e.target.classList.contains("piece")) | |
941 | { | |
942 | // Next few lines to center the piece on mouse cursor | |
943 | let rect = e.target.parentNode.getBoundingClientRect(); | |
944 | this.start = { | |
945 | x: rect.x + rect.width/2, | |
946 | y: rect.y + rect.width/2, | |
947 | id: e.target.parentNode.id | |
948 | }; | |
949 | this.selectedPiece = e.target.cloneNode(); | |
950 | this.selectedPiece.style.position = "absolute"; | |
951 | this.selectedPiece.style.top = 0; | |
952 | this.selectedPiece.style.display = "inline-block"; | |
953 | this.selectedPiece.style.zIndex = 3000; | |
954 | let startSquare = this.getSquareFromId(e.target.parentNode.id); | |
2748531f BA |
955 | const iCanPlay = this.mode!="idle" |
956 | && (this.mode=="friend" || this.vr.canIplay(this.mycolor,startSquare)); | |
957 | this.possibleMoves = iCanPlay ? this.vr.getPossibleMovesFrom(startSquare) : []; | |
92342261 BA |
958 | // Next line add moving piece just after current image |
959 | // (required for Crazyhouse reserve) | |
5bd679d5 | 960 | e.target.parentNode.insertBefore(this.selectedPiece, e.target.nextSibling); |
1d184b4c BA |
961 | } |
962 | }, | |
963 | mousemove: function(e) { | |
964 | if (!this.selectedPiece) | |
965 | return; | |
966 | e = e || window.event; | |
967 | // If there is an active element, move it around | |
968 | if (!!this.selectedPiece) | |
969 | { | |
ffea77d9 BA |
970 | const [offsetX,offsetY] = !!e.clientX |
971 | ? [e.clientX,e.clientY] //desktop browser | |
972 | : [e.changedTouches[0].pageX, e.changedTouches[0].pageY]; //smartphone | |
973 | this.selectedPiece.style.left = (offsetX-this.start.x) + "px"; | |
974 | this.selectedPiece.style.top = (offsetY-this.start.y) + "px"; | |
1d184b4c BA |
975 | } |
976 | }, | |
977 | mouseup: function(e) { | |
978 | if (!this.selectedPiece) | |
979 | return; | |
980 | e = e || window.event; | |
981 | // Read drop target (or parentElement, parentNode... if type == "img") | |
92342261 | 982 | this.selectedPiece.style.zIndex = -3000; //HACK to find square from final coords |
ffea77d9 BA |
983 | const [offsetX,offsetY] = !!e.clientX |
984 | ? [e.clientX,e.clientY] | |
985 | : [e.changedTouches[0].pageX, e.changedTouches[0].pageY]; | |
986 | let landing = document.elementFromPoint(offsetX, offsetY); | |
1d184b4c | 987 | this.selectedPiece.style.zIndex = 3000; |
92342261 BA |
988 | // Next condition: classList.contains(piece) fails because of marks |
989 | while (landing.tagName == "IMG") | |
1d184b4c | 990 | landing = landing.parentNode; |
92342261 BA |
991 | if (this.start.id == landing.id) |
992 | { | |
993 | // A click: selectedPiece and possibleMoves are already filled | |
1d184b4c | 994 | return; |
92342261 | 995 | } |
1d184b4c BA |
996 | // OK: process move attempt |
997 | let endSquare = this.getSquareFromId(landing.id); | |
998 | let moves = this.findMatchingMoves(endSquare); | |
999 | this.possibleMoves = []; | |
1000 | if (moves.length > 1) | |
1001 | this.choices = moves; | |
1002 | else if (moves.length==1) | |
1003 | this.play(moves[0]); | |
1004 | // Else: impossible move | |
1005 | this.selectedPiece.parentNode.removeChild(this.selectedPiece); | |
1006 | delete this.selectedPiece; | |
1007 | this.selectedPiece = null; | |
1008 | }, | |
1009 | findMatchingMoves: function(endSquare) { | |
1010 | // Run through moves list and return the matching set (if promotions...) | |
1011 | let moves = []; | |
1012 | this.possibleMoves.forEach(function(m) { | |
1013 | if (endSquare[0] == m.end.x && endSquare[1] == m.end.y) | |
1014 | moves.push(m); | |
1015 | }); | |
1016 | return moves; | |
1017 | }, | |
1018 | animateMove: function(move) { | |
1019 | let startSquare = document.getElementById(this.getSquareId(move.start)); | |
1020 | let endSquare = document.getElementById(this.getSquareId(move.end)); | |
1021 | let rectStart = startSquare.getBoundingClientRect(); | |
1022 | let rectEnd = endSquare.getBoundingClientRect(); | |
1023 | let translation = {x:rectEnd.x-rectStart.x, y:rectEnd.y-rectStart.y}; | |
92ff5bae BA |
1024 | let movingPiece = |
1025 | document.querySelector("#" + this.getSquareId(move.start) + " > img.piece"); | |
92342261 | 1026 | // HACK for animation (with positive translate, image slides "under background") |
1d184b4c BA |
1027 | // Possible improvement: just alter squares on the piece's way... |
1028 | squares = document.getElementsByClassName("board"); | |
1029 | for (let i=0; i<squares.length; i++) | |
1030 | { | |
1031 | let square = squares.item(i); | |
1032 | if (square.id != this.getSquareId(move.start)) | |
1033 | square.style.zIndex = "-1"; | |
1034 | } | |
92342261 BA |
1035 | movingPiece.style.transform = "translate(" + translation.x + "px," + |
1036 | translation.y + "px)"; | |
1d184b4c BA |
1037 | movingPiece.style.transitionDuration = "0.2s"; |
1038 | movingPiece.style.zIndex = "3000"; | |
1039 | setTimeout( () => { | |
1040 | for (let i=0; i<squares.length; i++) | |
1041 | squares.item(i).style.zIndex = "auto"; | |
1042 | movingPiece.style = {}; //required e.g. for 0-0 with KR swap | |
1043 | this.play(move); | |
1044 | }, 200); | |
1045 | }, | |
1046 | play: function(move, programmatic) { | |
e64084da BA |
1047 | if (!move) |
1048 | { | |
1049 | // Navigate after game is over | |
1050 | if (this.cursor >= this.vr.moves.length) | |
1051 | return; //already at the end | |
1052 | move = this.vr.moves[this.cursor++]; | |
1053 | } | |
1d184b4c BA |
1054 | if (!!programmatic) //computer or human opponent |
1055 | { | |
1056 | this.animateMove(move); | |
1057 | return; | |
1058 | } | |
1059 | // Not programmatic, or animation is over | |
1060 | if (this.mode == "human" && this.vr.turn == this.mycolor) | |
a29d9d6b | 1061 | this.conn.send(JSON.stringify({code:"newmove", move:move, oppid:this.oppid})); |
ea8417ff | 1062 | new Audio("/sounds/chessmove1.mp3").play().then(() => {}).catch(err => {}); |
e64084da | 1063 | if (this.mode != "idle") |
3300df38 BA |
1064 | { |
1065 | this.incheck = this.vr.getCheckSquares(move); //is opponent in check? | |
e64084da | 1066 | this.vr.play(move, "ingame"); |
3300df38 | 1067 | } |
e64084da | 1068 | else |
3300df38 | 1069 | { |
e64084da | 1070 | VariantRules.PlayOnBoard(this.vr.board, move); |
3300df38 BA |
1071 | this.$forceUpdate(); //TODO: ?! |
1072 | } | |
1d184b4c BA |
1073 | if (this.mode == "human") |
1074 | this.updateStorage(); //after our moves and opponent moves | |
e64084da BA |
1075 | if (this.mode != "idle") |
1076 | { | |
1077 | const eog = this.vr.checkGameOver(); | |
1078 | if (eog != "*") | |
1079 | this.endGame(eog); | |
1080 | } | |
1081 | if (this.mode == "computer" && this.vr.turn != this.mycolor) | |
1d184b4c BA |
1082 | setTimeout(this.playComputerMove, 500); |
1083 | }, | |
e64084da BA |
1084 | undo: function() { |
1085 | // Navigate after game is over | |
1086 | if (this.cursor == 0) | |
1087 | return; //already at the beginning | |
3300df38 BA |
1088 | if (this.cursor == this.vr.moves.length) |
1089 | this.incheck = []; //in case of... | |
e64084da BA |
1090 | const move = this.vr.moves[--this.cursor]; |
1091 | VariantRules.UndoOnBoard(this.vr.board, move); | |
1092 | this.$forceUpdate(); //TODO: ?! | |
2748531f BA |
1093 | }, |
1094 | undoInGame: function() { | |
1095 | const lm = this.vr.lastMove; | |
1096 | if (!!lm) | |
1097 | this.vr.undo(lm); | |
1098 | }, | |
1d184b4c BA |
1099 | }, |
1100 | }) |