X-Git-Url: https://git.auder.net/doc/index.css?a=blobdiff_plain;f=public%2Fjavascripts%2Fcomponents%2Frules.js;h=0f27d5327177c9f18d664869a6b024ea09dc6c37;hb=d337a94cd6d38bb743a8935017d03fe21d4ad324;hp=660f0be9976e56109716fed35aed292a3affb755;hpb=da06a6eb0237123ce43fdb01cb06246b8b57f5e5;p=vchess.git diff --git a/public/javascripts/components/rules.js b/public/javascripts/components/rules.js index 660f0be9..0f27d532 100644 --- a/public/javascripts/components/rules.js +++ b/public/javascripts/components/rules.js @@ -1,18 +1,50 @@ // Load rules on variant page Vue.component('my-rules', { + props: ["settings"], data: function() { - return { content: "" }; + return { + content: "", + display: "rules", + mode: "computer", + subMode: "", //'auto' for game CPU vs CPU + gameInProgress: false, + mycolor: "w", + allowMovelist: true, + fen: "", + }; }, - template: `
`, + template: ` +
+
+ + + + +
+
+ + +
+ `, mounted: function() { // AJAX request to get rules content (plain text, HTML) - ajax("/rules/" + variant, "GET", response => { + ajax("/rules/" + variant.name, "GET", response => { let replaceByDiag = (match, p1, p2) => { - const args = self.parseFen(p2); + const args = this.parseFen(p2); return getDiagram(args); }; - self.content = response.replace(/(fen:)([^:]*):/g, replaceByDiag); - } + this.content = response.replace(/(fen:)([^:]*):/g, replaceByDiag); + }); }, methods: { parseFen(fen) { @@ -21,7 +53,28 @@ Vue.component('my-rules', { position: fenParts[0], marks: fenParts[1], orientation: fenParts[2], + shadow: fenParts[3], }; }, + startGame: function() { + if (this.gameInProgress) + return; + this.gameInProgress = true; + this.mode = "computer"; + this.display = "computer"; + this.fen = V.GenRandInitFen(); + }, + stopGame: function() { + this.gameInProgress = false; + this.mode = "analyze"; + }, + playAgainstComputer: function() { + this.subMode = ""; + this.startGame(); + }, + watchComputerGame: function() { + this.subMode = "auto"; + this.startGame(); + }, }, })