X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fviews%2FRules.vue;h=4edc428f2942e94e7fdca2911b6d3aa33d5cb3e0;hb=50aed5a15e214d31b63f6320209ac14fe5c052cb;hp=fd26f16b629b2c25862538ec49eb399335a01e2c;hpb=4473050c257453abb37cd53d8d1e6e941c49bf91;p=vchess.git diff --git a/client/src/views/Rules.vue b/client/src/views/Rules.vue index fd26f16b..4edc428f 100644 --- a/client/src/views/Rules.vue +++ b/client/src/views/Rules.vue @@ -9,7 +9,7 @@ | Beat the computer! button(v-show="gameInProgress" @click="stopGame") | Stop game - div(v-show="display=='rules'" v-html="content" class="section-content") + .section-content(v-show="display=='rules'" v-html="content") Game(v-show="display=='computer'" :gid-or-fen="fen" :mode="mode" :sub-mode="subMode" :variant="variant" @computer-think="gameInProgress=false" @game-over="stopGame") @@ -27,7 +27,7 @@ export default { data: function() { return { st: store.state, - variant: {id: 0, name: "Unknown"}, //...yet + variant: {id: 0, name: "_unknown"}, //...yet content: "", display: "rules", mode: "computer", @@ -37,27 +37,14 @@ export default { fen: "", }; }, - mounted: async function() { + watch: { + $route: function(newRoute) { + this.tryChangeVariant(newRoute.params["vname"]); + }, + }, + created: async function() { // NOTE: variant cannot be set before store is initialized - const vname = this.$route.params["vname"]; - //const idxOfVar = this.st.variants.indexOf(e => e.name == vname); - //this.variant = this.st.variants[idxOfVar]; //TODO: is it the right timing?! - this.variant.name = vname; - const vModule = await import("@/variants/" + vname + ".js"); - window.V = vModule.VariantRules; - // Method to replace diagrams in loaded HTML - const replaceByDiag = (match, p1, p2) => { - const args = this.parseFen(p2); - return getDiagram(args); - }; - // (AJAX) Request to get rules content (plain text, HTML) - // TODO: find a way to have Diagram(er) as a component, - // thus allowing images import through require(), handled by Webpack - // ==> the rules files should be less static - this.content = - // TODO: why doesn't this work? require("raw-loader!pug-plain-loader!@/rules/"...) - require("raw-loader!@/rules/" + vname + "/" + this.st.lang + ".pug") - .replace(/(fen:)([^:]*):/g, replaceByDiag); + this.tryChangeVariant(this.$route.params["vname"]); }, methods: { parseFen(fen) { @@ -69,6 +56,28 @@ export default { shadow: fenParts[3], }; }, + tryChangeVariant: async function(vname) { + if (vname == "_unknown") + return; + if (this.st.variants.length > 0) + { + const idxOfVar = this.st.variants.findIndex(e => e.name == vname); + this.variant = this.st.variants[idxOfVar]; + } + else + this.variant.name = vname; + const vModule = await import("@/variants/" + vname + ".js"); + window.V = vModule.VariantRules; + // Method to replace diagrams in loaded HTML + const replaceByDiag = (match, p1, p2) => { + const args = this.parseFen(p2); + return getDiagram(args); + }; + // (AJAX) Request to get rules content (plain text, HTML) + this.content = + require("raw-loader!@/rules/" + vname + "/" + this.st.lang + ".pug") + .replace(/(fen:)([^:]*):/g, replaceByDiag); + }, startGame: function() { if (this.gameInProgress) return; @@ -92,3 +101,114 @@ export default { }, }; + +