- launchGame: async function() {
- const vModule = await import("@/variants/" + this.vname + ".js");
- window.V = vModule.VariantRules;
- this.compWorker.postMessage(["scripts",this.vname]);
- this.compWorker.postMessage(["init",this.fen]);
- this.newGameFromFen(this.fen);
- },
- newGameFromFen: function(fen) {
- this.vr = new V(fen);
- this.gameInfo.fenStart = fen;
- this.gameInfo.mycolor = (Math.random() < 0.5 ? "w" : "b");
- this.gameInfo.players = ["Myself","Computer"];
- if (this.gameInfo.mycolor == "b")
- this.gameInfo.players = this.gameInfo.players.reverse();
- this.compWorker.postMessage(["init",fen]);
- if (this.gameInfo.mycolor != "w" || this.mode == "auto")
+ launchGame: function() {
+ this.compWorker.postMessage(["scripts", this.gameInfo.vname]);
+ this.compWorker.postMessage(["init", this.gameInfo.fen]);
+ this.vr = new V(this.gameInfo.fen);
+ const mycolor = Math.random() < 0.5 ? "w" : "b";
+ let players = [{ name: "Myself" }, { name: "Computer" }];
+ if (mycolor == "b") players = players.reverse();
+ this.currentUrl = document.location.href; //to avoid playing outside page
+ // NOTE: fen and fenStart are redundant in game object
+ this.game = Object.assign({}, this.gameInfo, {
+ fenStart: this.gameInfo.fen,
+ players: players,
+ mycolor: mycolor,
+ score: "*"
+ });
+ this.compWorker.postMessage(["init", this.gameInfo.fen]);
+ if (mycolor != "w" || this.gameInfo.mode == "auto")