X-Git-Url: https://git.auder.net/?p=vchess.git;a=blobdiff_plain;f=client%2Fsrc%2Fcomponents%2FGame.vue;h=678b914d79b75716339f3eace12fe29c5af5bcd0;hp=73c37695ea058d30323910196d5f77c896f81bef;hb=e27329232b83700d63c8fb52af6f4c2eec9a569c;hpb=c75838d9d5b52d1fbd3e419c5073ef0cfb95f40a diff --git a/client/src/components/Game.vue b/client/src/components/Game.vue index 73c37695..678b914d 100644 --- a/client/src/components/Game.vue +++ b/client/src/components/Game.vue @@ -8,7 +8,7 @@ h3#eogMessage.section {{ endgameMessage }} //Chat(:opponents="opponents" :people="people") Board(:vr="vr" :last-move="lastMove" :mode="mode" :user-color="mycolor" - :orientation="orientation" @play-move="play") + :orientation="orientation" :vname="variant.name" @play-move="play") .button-group button(@click="() => play()") Play button(@click="() => undo()") Undo @@ -46,8 +46,16 @@ import Board from "@/components/Board.vue"; //import Chat from "@/components/Chat.vue"; //import MoveList from "@/components/MoveList.vue"; import { store } from "@/store"; + +import { getSquareId } from "@/utils/squareId"; + +import Worker from 'worker-loader!@/playCompMove'; + export default { name: 'my-game', + components: { + Board, + }, // gameId: to find the game in storage (assumption: it exists) // fen: to start from a FEN without identifiers (analyze mode) // subMode: "auto" (game comp vs comp) or "corr" (correspondance game), @@ -58,7 +66,6 @@ export default { return { st: store.state, // Web worker to play computer moves without freezing interface: - compWorker: new Worker('/javascripts/playCompMove.js'), timeStart: undefined, //time when computer starts thinking vr: null, //VariantRules object, describing the game state + rules endgameMessage: "", @@ -75,6 +82,7 @@ export default { moves: [], //all moves played in current game cursor: -1, //index of the move just played lastMove: null, + compWorker: null, }; }, watch: { @@ -84,6 +92,8 @@ export default { return this.$emit("computer-think"); this.launchGame(); }, + variant: function(newVar) { + }, }, computed: { showMoves: function() { @@ -200,7 +210,7 @@ export default { this.conn.onclose = socketCloseListener; } // Computer moves web worker logic: (TODO: also for observers in HH games ?) - this.compWorker.postMessage(["scripts",this.variant.name]); + this.compWorker = new Worker(); //'/javascripts/playCompMove.js'), this.compWorker.onmessage = e => { this.lockCompThink = true; //to avoid some ghost moves let compMove = e.data; @@ -271,7 +281,8 @@ export default { }, launchGame: async function() { const vModule = await import("@/variants/" + this.variant.name + ".js"); - window.V = tModule.VariantRules; + window.V = vModule.VariantRules; + this.compWorker.postMessage(["scripts",this.variant.name]); if (this.gidOrFen.indexOf('/') >= 0) this.newGameFromFen(this.gidOrFen); else @@ -400,7 +411,7 @@ export default { document.querySelector("#" + getSquareId(move.start) + " > img.piece"); // HACK for animation (with positive translate, image slides "under background") // Possible improvement: just alter squares on the piece's way... - squares = document.getElementsByClassName("board"); + const squares = document.getElementsByClassName("board"); for (let i=0; i {}); if (this.mode == "human") { @@ -505,7 +516,7 @@ export default { this.vr.undo(move); this.cursor--; this.lastMove = (this.cursor >= 0 ? this.moves[this.cursor] : undefined); - if (this.settings.sound == 2) + if (this.st.settings.sound == 2) new Audio("/sounds/undo.mp3").play().catch(err => {}); this.incheck = this.vr.getCheckSquares(this.vr.turn); if (navigate)