X-Git-Url: https://git.auder.net/doc/index.css?a=blobdiff_plain;f=public%2Fjavascripts%2Fcomponents%2Fgame.js;h=8662028c909fd0117686760e7fe1e5afe9c27c47;hb=60d9063fdfcd4b7628fbc0e0fc594f083bda8761;hp=d0d8125833d607dc25ffb1efd2226e62e0721036;hpb=a6403027a66411ead248aab0369bf3ee3a75d8ec;p=vchess.git diff --git a/public/javascripts/components/game.js b/public/javascripts/components/game.js index d0d81258..8662028c 100644 --- a/public/javascripts/components/game.js +++ b/public/javascripts/components/game.js @@ -1,6 +1,10 @@ // Game logic on a variant page: 3 modes, analyze, computer or human // TODO: envoyer juste "light move", sans FEN ni notation ...etc // TODO: if I'm an observer and player(s) disconnect/reconnect, how to find me ? +// onClick :: ask full game to remote player, and register as an observer in game +// (use gameId to communicate) +// on landing on game :: if gameId not found locally, check remotely +// ==> il manque un param dans game : "remoteId" Vue.component('my-game', { // gameId: to find the game in storage (assumption: it exists) // fen: to start from a FEN without identifiers (analyze mode) @@ -31,11 +35,11 @@ Vue.component('my-game', { }; }, watch: { - fen: function(newFen) { + fen: function() { // (Security) No effect if a computer move is in progress: if (this.mode == "computer" && this.lockCompThink) return this.$emit("computer-think"); - this.newGameFromFen(newFen); + this.newGameFromFen(); }, gameId: function() { this.loadGame(); @@ -124,6 +128,15 @@ Vue.component('my-game', { this.vr = new VariantRules(this.fen); this.fenStart = this.fen; } + // TODO: if I'm one of the players in game, then: + // Send ping to server (answer pong if opponent is connected) + if (true && !!this.conn) + { + this.conn.onopen = () => { + this.conn.send(JSON.stringify({ + code:"ping",oppid:this.oppid,gameId:this.gameId})); + }; + } // TODO: also handle "draw accepted" (use opponents array?) // --> must give this info also when sending lastState... // and, if all players agree then OK draw (end game ...etc) @@ -287,27 +300,30 @@ Vue.component('my-game', { this.endGame(this.mycolor=="w"?"0-1":"1-0"); }, translate: translate, - newGameFromFen: function(fen) { - this.vr = new VariantRules(fen); + newGameFromFen: function() { + this.vr = new VariantRules(this.fen); this.moves = []; this.cursor = -1; - this.fenStart = newFen; + this.fenStart = this.fen; this.score = "*"; if (this.mode == "analyze") { - this.mycolor = V.ParseFen(newFen).turn; + this.mycolor = V.ParseFen(this.fen).turn; this.orientation = this.mycolor; } else if (this.mode == "computer") //only other alternative (HH with gameId) { this.mycolor = (Math.random() < 0.5 ? "w" : "b"); this.orientation = this.mycolor; - this.compWorker.postMessage(["init",newFen]); + this.compWorker.postMessage(["init",this.fen]); if (this.mycolor != "w" || this.subMode == "auto") this.playComputerMove(); } }, loadGame: function() { + // TODO: ask game to remote peer if this.remoteId is set + // (or just if game not found locally) + // NOTE: if it's a corr game, ask it from server const game = getGameFromStorage(this.gameId); this.opponent.id = game.oppid; //opponent ID in case of running HH game this.opponent.name = game.oppname; //maye be blank (if anonymous)