import { processModalClick } from "@/utils/modalClick";
import { playMove, getFilteredMove } from "@/utils/playUndo";
import { ArrayFun } from "@/utils/array";
+import afterRawLoad from "@/utils/afterRawLoad";
import params from "@/parameters";
export default {
name: "my-game",
game: {}, //passed to BaseGame
focus: !document.hidden, //will not always work... TODO
// virtualClocks will be initialized from true game.clocks
+ // TODO: clock update triggers re-rendering. Should be out of Vue
virtualClocks: [],
vr: null, //"variant rules" object initialized from FEN
rulesContent: "",
},
getGameType: function(game) {
if (!!game.id.toString().match(/^i/)) return "import";
- return game.cadence.indexOf("d") >= 0 ? "corr" : "live";
+ return (game.cadence.indexOf("d") >= 0 ? "corr" : "live");
},
// Notify something after a new move (to opponent and me on MyGames page)
notifyMyGames: function(thing, data) {
case "newmove": {
// DEBUG:
-console.log("Receive move");
-console.log(data.data);
-//moveslist not updated when receiving a move? (see in baseGame)
+//console.log("Receive move");
+//console.log(data.data);
+//moveslist not updated when receiving a move? (see in BaseGame)
const movePlus = data.data;
const movesCount = this.game.moves.length;
let gameInfo = {
id: getRandString(), //ignored if corr
fen: V.GenRandInitFen(this.game.randomness),
+ randomness: this.game.randomness,
players: [this.game.players[1], this.game.players[0]],
vid: this.game.vid,
cadence: this.game.cadence
"/games",
"POST",
{
- // cid is useful to delete the challenge:
data: { gameInfo: gameInfo },
success: (response) => {
gameInfo.id = response.gameId;
window.V = vModule[game.vname + "Rules"];
this.loadGame(game, callback);
});
- // (AJAX) Request to get rules content (plain text, HTML)
this.rulesContent =
- require(
- "raw-loader!@/translations/rules/" +
- game.vname + "/" +
- this.st.lang + ".pug"
- )
- // Next two lines fix a weird issue after last update (2019-11)
- .replace(/\\n/g, " ")
- .replace(/\\"/g, '"')
- .replace('module.exports = "', "")
- .replace(/"$/, "")
- .replace(/(fen:)([^:]*):/g, replaceByDiag);
+ afterRawLoad(
+ require(
+ "raw-loader!@/translations/rules/" +
+ game.vname + "/" + this.st.lang + ".pug"
+ ).default
+ ).replace(/(fen:)([^:]*):/g, replaceByDiag);
},
// 3 cases for loading a game:
// - from indexedDB (running or completed live game I play)
// - from server (one correspondance game I play[ed] or not)
// - from remote peer (one live game I don't play, finished or not)
fetchGame: function(callback) {
- if (Number.isInteger(this.gameRef) || !isNaN(parseInt(this.gameRef))) {
+ if (
+ Number.isInteger(this.gameRef) ||
+ !isNaN(parseInt(this.gameRef, 10))
+ ) {
// corr games identifiers are integers
ajax(
"/games",
};
if (
this.game.type == "corr" &&
- V.CorrConfirm &&
moveCol == this.game.mycolor &&
!data.receiveMyMove
) {
if (data.score == "*") this.re_setClocks();
}
};
+ if (!V.CorrConfirm) {
+ afterSetScore();
+ return;
+ }
let el = document.querySelector("#buttonsConfirm > .acceptBtn");
// We may play several moves in a row: in case of, remove listener:
let elClone = el.cloneNode(true);