1 // Load rules on variant page
2 Vue
.component('my-rules', {
9 subMode: "", //'auto' for game CPU vs CPU
10 gameInProgress: false,
17 <div class="col-sm-12 col-md-10 col-md-offset-1 col-lg-8 col-lg-offset-2">
18 <div class="button-group">
19 <button @click="display='rules'">
22 <button v-show="!gameInProgress" @click="watchComputerGame">
25 <button v-show="!gameInProgress" @click="playAgainstComputer">
28 <button v-show="gameInProgress" @click="stopGame">
32 <div v-show="display=='rules'" v-html="content" class="section-content"></div>
33 <my-game v-show="display=='computer'" :mycolor="mycolor" :settings="settings"
34 :allow-movelist="allowMovelist" :mode="mode" :sub-mode="subMode" :fen="fen"
35 @computer-think="gameInProgress=false" @game-over="stopGame">
40 // AJAX request to get rules content (plain text, HTML)
41 ajax("/rules/" + variant
.name
, "GET", response
=> {
42 let replaceByDiag
= (match
, p1
, p2
) => {
43 const args
= this.parseFen(p2
);
44 return getDiagram(args
);
46 this.content
= response
.replace(/(fen:)([^:]*):/g, replaceByDiag
);
51 const fenParts
= fen
.split(" ");
53 position: fenParts
[0],
55 orientation: fenParts
[2],
59 startGame: function() {
60 if (this.gameInProgress
)
62 this.gameInProgress
= true;
63 this.mode
= "computer";
64 this.display
= "computer";
65 this.fen
= V
.GenRandInitFen();
67 stopGame: function() {
68 this.gameInProgress
= false;
69 this.mode
= "analyze";
71 playAgainstComputer: function() {
75 watchComputerGame: function() {
76 this.subMode
= "auto";