X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fviews%2FRules.vue;h=09d5e06a7879cd5bd2e5e5409c6156b4db5d1975;hb=eaa5ad3e93b761fefb16b32071be0b439761f843;hp=d96f1edc7afd442882fbcabf566d115c5a7f01b4;hpb=d2edca6dfaafed2d1ab8d5941dbb77ed801798f6;p=vchess.git diff --git a/client/src/views/Rules.vue b/client/src/views/Rules.vue index d96f1edc..09d5e06a 100644 --- a/client/src/views/Rules.vue +++ b/client/src/views/Rules.vue @@ -26,7 +26,7 @@ main | {{ st.tr["Analysis mode"] }} .row .col-sm-12.col-md-8.col-md-offset-2.col-lg-6.col-lg-offset-3 - h4#variantName(v-show="display=='rules'") {{ gameInfo.vname }} + h4#variantName(v-show="display=='rules'") {{ getVariantDisplay }} div( v-show="display=='rules'" v-html="content" @@ -44,6 +44,7 @@ import ComputerGame from "@/components/ComputerGame.vue"; import { store } from "@/store"; import { replaceByDiag } from "@/utils/printDiagram"; import { CompgameStorage } from "@/utils/compgameStorage"; +import afterRawLoad from "@/utils/afterRawLoad"; export default { name: "my-rules", components: { @@ -75,21 +76,19 @@ export default { showAnalyzeBtn: function() { return !!this.V && this.V.CanAnalyze; }, + getVariantDisplay: function() { + if (!this.gameInfo.vname) return ""; //variant not set yet + return this.st.variants.find(v => v.name == this.gameInfo.vname).display; + }, content: function() { if (!this.gameInfo.vname) return ""; //variant not set yet - // (AJAX) Request to get rules content (plain text, HTML) return ( - require( - "raw-loader!@/translations/rules/" + - this.gameInfo.vname + "/" + - this.st.lang + ".pug" - ) - // Next two lines fix a weird issue after last update (2019-11) - .replace(/\\n/g, " ") - .replace(/\\"/g, '"') - .replace('module.exports = "', "") - .replace(/"$/, "") - .replace(/(fen:)([^:]*):/g, replaceByDiag) + afterRawLoad( + require( + "raw-loader!@/translations/rules/" + + this.gameInfo.vname + "/" + this.st.lang + ".pug" + ).default + ).replace(/(fen:)([^:]*):/g, replaceByDiag) ); } }, @@ -99,6 +98,10 @@ export default { else if (this.gameInProgress) this.display = "computer"; }, re_setVariant: async function(vname) { + const key = "rr_" + vname; + if (!localStorage.getItem(key)) + // Mark rules as "read" + localStorage.setItem(key, '1'); await import("@/variants/" + vname + ".js") .then((vModule) => { this.V = window.V = vModule[vname + "Rules"]; @@ -121,12 +124,16 @@ export default { this.gameInfo.mode = mode; if (this.gameInfo.mode == "versus") { CompgameStorage.get(this.gameInfo.vname, (game) => { - // NOTE: game might be null + // NOTE: game might be null (if none stored yet) + if (!!game && !V.IsGoodFen(game.fen)) { + // Some issues with stored game: delete + CompgameStorage.remove(game.vname); + game = null; + } this.$refs["compgame"].launchGame(game); }); - } else { - this.$refs["compgame"].launchGame(); } + else this.$refs["compgame"].launchGame(); }, // The user wants to stop the game: stopGame: function() {