X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fviews%2FGame.vue;h=a2afb09dc20295dcb59bd4888d3c243fb9126761;hb=3d9745ae10ba867e4c1ec6e848db29c5e293420b;hp=65d46460758f23aabd7014b243b95cdd88a7ec11;hpb=f0a812b7b11bc2a1514d2aa10ecc257d10d988d5;p=vchess.git diff --git a/client/src/views/Game.vue b/client/src/views/Game.vue index 65d46460..a2afb09d 100644 --- a/client/src/views/Game.vue +++ b/client/src/views/Game.vue @@ -7,7 +7,7 @@ main ) .card label.modal-close(for="modalRules") - a#variantNameInGame(:href="'/#/variants/'+game.vname") {{ game.vname }} + a#variantNameInGame(:href="'/#/variants/'+game.vname") {{ game.vdisp }} div(v-html="rulesContent") input#modalScore.modal(type="checkbox") div#scoreDiv( @@ -78,7 +78,9 @@ main .row #aboveBoard.col-sm-12 span.variant-cadence(v-if="game.type!='import'") {{ game.cadence }} - span.variant-name {{ game.vname }} + span.variant-name + | {{ game.vname }} + | {{ !!vr ? vr.constructor.AbbreviateOptions(game.options) : '' }} span#nextGame( v-if="nextIds.length > 0" @click="showNextGame()" @@ -408,8 +410,15 @@ export default { this.conn.onopen = () => callback(); }; this.fetchGame((game) => { - if (!!game) + if (!!game) { + if (!game.options) { + // Patch for retro-compatibility (TODO: remove it) + game.options = { randomness: game.randomness }; + delete game["randomness"]; + } + else game.options = JSON.parse(game.options); this.loadVariantThenGame(game, () => socketInit(this.roomInit)); + } else // Live game stored remotely: need socket to retrieve it // NOTE: the callback "roomInit" will be lost, so it's not provided. @@ -707,7 +716,7 @@ export default { const gameToSend = Object.keys(this.game) .filter(k => [ - "id","fen","players","vid","cadence","fenStart","vname", + "id","fen","players","vid","cadence","fenStart","options", "moves","clocks","score","drawOffer","rematchOffer" ].includes(k)) .reduce( @@ -1024,7 +1033,6 @@ export default { { // (other) Game infos: constant fenStart: gameInfo.fen, - vname: this.game.vname, created: Date.now(), // Game state (including FEN): will be updated moves: [], @@ -1049,8 +1057,8 @@ export default { // Start a new game! let gameInfo = { id: getRandString(), //ignored if corr - fen: V.GenRandInitFen(this.game.randomness), - randomness: this.game.randomness, + fen: V.GenRandInitFen(this.game.options), + options: this.game.options, players: [this.game.players[1], this.game.players[0]], vid: this.game.vid, cadence: this.game.cadence @@ -1083,7 +1091,11 @@ export default { "/games", "POST", { - data: { gameInfo: gameInfo }, + data: Object.assign( + {}, + gameInfo, + { options: JSON.stringify(this.game.options) } + ), success: (response) => { gameInfo.id = response.id; notifyNewGame(); @@ -1282,18 +1294,33 @@ export default { if (!!callback) callback(); }, loadVariantThenGame: async function(game, callback) { - await import("@/variants/" + game.vname + ".js") - .then((vModule) => { - window.V = vModule[game.vname + "Rules"]; - this.loadGame(game, callback); - }); - this.rulesContent = - afterRawLoad( - require( - "raw-loader!@/translations/rules/" + - game.vname + "/" + this.st.lang + ".pug" - ).default - ).replace(/(fen:)([^:]*):/g, replaceByDiag); + const afterSetVname = async () => { + await import("@/variants/" + game.vname + ".js") + .then((vModule) => { + window.V = vModule[game.vname + "Rules"]; + this.loadGame(game, callback); + }); + this.rulesContent = + afterRawLoad( + require( + "raw-loader!@/translations/rules/" + + game.vname + "/" + this.st.lang + ".pug" + ).default + ).replace(/(fen:)([^:]*):/g, replaceByDiag); + }; + let variant = undefined; + const trySetVname = setInterval( + () => { + // this.st.variants might be uninitialized (variant == null) + variant = this.st.variants.find(v => v.id == game.vid); + if (!!variant) { + clearInterval(trySetVname); + game.vname = variant.name; + game.vdisp = variant.display; + afterSetVname(); + } + }, 500 + ); }, // 3 cases for loading a game: // - from indexedDB (running or completed live game I play) @@ -1414,7 +1441,7 @@ export default { ? this.repeat[fenObj] + 1 : 1; if (this.repeat[fenObj] >= 3) { - if (V.LoseOnRepetition) + if (this.vr.loseOnRepetition()) this.gameOver(moveCol == "w" ? "0-1" : "1-0", "Repetition"); else this.drawOffer = "threerep"; }