X-Git-Url: https://git.auder.net/pieces/Cwda/n_white_knight.svg?a=blobdiff_plain;f=client%2Fsrc%2Fviews%2FHall.vue;h=ae45e658a4de92c45e7d3815008e6dc8244d952c;hb=9fc9541e3f5573602c8fc5911bae4f4c06f641a5;hp=6a57622026cb7c5fc5dbef3c57eb981d9447b3ec;hpb=f6f2bef10910ddb3430a40f4ab393b225250234a;p=vchess.git diff --git a/client/src/views/Hall.vue b/client/src/views/Hall.vue index 6a576220..ae45e658 100644 --- a/client/src/views/Hall.vue +++ b/client/src/views/Hall.vue @@ -178,6 +178,7 @@ export default { // ==> Moves sent by connected remote player(s) if live game // TODO: this doesn't work: choose a SID at random + // --> do we have players' names ? let url = "/" + g.id; if (g.type == "live") @@ -277,27 +278,28 @@ export default { timeControl: c.timeControl }; this.st.conn.send(JSON.stringify({code:"challenge", - challenge:myChallenge, target:data.from})); + chall:myChallenge, target:data.from})); } break; } case "askgame": { - // Send my current live games (if any) - // TODO: from indexedDB, through GameStorage. -// if (!!localStorage["gid"]) -// { -// const myGame = -// { -// // Minimal game informations: (fen+clock not required) -// id: localStorage["gid"], -// players: JSON.parse(localStorage["players"]), //array sid+id+name -// vname: localStorage["vname"], -// timeControl: localStorage["timeControl"], -// }; -// this.st.conn.send(JSON.stringify({code:"game", -// game:myGame, target:data.from})); -// } + // Send my current live game (if any) + GameStorage.getCurrent((game) => { + if (!!game) + { + const myGame = + { + // Minimal game informations: + id: game.id, + players: game.players.map(p => p.name), + vname: game.vname, + timeControl: game.timeControl, + }; + this.st.conn.send(JSON.stringify({code:"game", + game:myGame, target:data.from})); + } + }); break; } case "identity": @@ -314,8 +316,8 @@ export default { newChall.type = this.classifyObject(data.chall); const pIdx = this.people.findIndex(p => p.sid == data.from); newChall.from = this.people[pIdx]; //may be anonymous - newChall.added = Date.now(); - newChall.vname = this.getVname(newChall.vid); + newChall.added = Date.now(); //TODO: this is reception timestamp, not creation + newChall.vname = this.getVname(newChall.vid); //TODO: just send vname? this.challenges.push(newChall); break; } @@ -323,10 +325,10 @@ export default { { // Receive game from some player (+sid) // NOTE: it may be correspondance (if newgame while we are connected) - // TODO: ambiguous naming "newGame" ==> rename function ? let newGame = data.game; newGame.type = this.classifyObject(data.game); - newGame.vname = newGame.vname; + newGame.rid = data.from; + newGame.score = "*"; this.games.push(newGame); break; } @@ -337,7 +339,7 @@ export default { // Delete corresponding challenge: ArrayFun.remove(this.challenges, c => c.id == data.cid); // New game just started: data contain all informations - this.newGame(data.gameInfo); + this.startNewGame(data.gameInfo); break; } // * - receive "accept/cancel challenge": apply action to challenges list @@ -360,6 +362,7 @@ export default { } case "deletechallenge": { + // NOTE: the challenge may be already removed ArrayFun.remove(this.challenges, c => c.id == data.cid); break; } @@ -481,7 +484,7 @@ export default { else //accept (or refuse) a challenge { c.accepted = true; - if (!!c.to[0]) + if (!!c.to) { // TODO: if special FEN, show diagram after loading variant c.accepted = confirm("Accept challenge?"); @@ -489,17 +492,22 @@ export default { this.st.conn.send(JSON.stringify({ code: (c.accepted ? "accept" : "refuse") + "challenge", cid: c.id, target: c.from.sid})); - if (c.type == "corr" && c.accepted) + if (c.accepted) { - ajax( - "/challenges", - "PUT", - {id: this.challenges[cIdx].id} - ); + if (c.type == "corr") + { + ajax( + "/challenges", + "PUT", + {id: this.challenges[cIdx].id} + ); + } } - if (!c.accepted) + else { ArrayFun.remove(this.challenges, ch => ch.id == c.id); + if (!c.to) //TODO: send to everyone except me and opponent ? + this.sendSomethingTo("", "deletechallenge", {cid: this.challenges[cIdx].id}); if (c.type == "corr") { ajax( @@ -534,10 +542,10 @@ export default { gameInfo:gameInfo, cid:c.id, target:c.seat.sid})); // Delete corresponding challenge: ArrayFun.remove(this.challenges, ch => ch.id == c.id); - this.newGame(gameInfo); //also! + this.startNewGame(gameInfo); //also! }, // NOTE: for live games only (corr games are launched on server) - newGame: function(gameInfo) { + startNewGame: function(gameInfo) { // Extract times (in [milli]seconds), set clocks const tc = extractTime(gameInfo.timeControl); let initime = [...Array(gameInfo.players.length)];