- lastFen, lastMove,
- timeout1, timeout2, timeout3;
-const callbackAfterConfirmation = () => {
- const result = vr.getCurrentScore(lastMove);
- if (result != "*") {
- setTimeout( () => {
- toggleVisible("gameStopped");
- send("gameover", { gid: gid });
- }, 2000);
- }
-};
-const afterPlay = (move) => {
- // Pack into one moves array, then send
- curMoves.push({
- appear: move.appear,
- vanish: move.vanish,
- start: move.start,
- end: move.end
- });
- lastMove = move;
- if (vr.turn != playerColor) {
- toggleTurnIndicator(false);
- lastFen = vr.getFen();
- const sendMove =
- () => send("newmove", {gid: gid, moves: curMoves, fen: lastFen});
- // Send move until we obtain confirmation or timeout, then callback
- sendMove();
- timeout1 = setTimeout(sendMove, 500);
- timeout2 = setTimeout(sendMove, 1500);
- timeout3 = setTimeout(
- () => alert("The move may be lost :( Please reload"),
- 3000);
+ lastFen;
+const afterPlay = (move_s, newTurn, ops) => {
+ if (ops.send) {
+ // Pack into one moves array, then send (if turn changed)
+ if (Array.isArray(move_s))
+ // Array of simple moves (e.g. Chakart)
+ Array.prototype.push.apply(curMoves, move_s);
+ else
+ // Usual case
+ curMoves.push(move_s);
+ if (newTurn != playerColor) {
+ send("newmove",
+ {gid: gid, moves: curMoves, fen: vr.getFen()},
+ {
+ retry: true,
+ error: () => alert("Move not sent: reload page")
+ }
+ );
+ }