Commit | Line | Data |
---|---|---|
cf2343ce | 1 | <template lang="pug"> |
7aa548e7 BA |
2 | main |
3 | .row | |
4 | .col-sm-12.col-md-10.col-md-offset-1.col-lg-8.col-lg-offset-2 | |
5 | .button-group | |
9ddaf8da | 6 | button(@click="clickReadRules()") {{ st.tr["Rules"] }} |
910d631b BA |
7 | button( |
8 | v-show="!gameInProgress" | |
9 | @click="startGame('auto')" | |
10 | ) | |
f44fd3bf | 11 | | {{ st.tr["Example game"] }} |
910d631b BA |
12 | button( |
13 | v-show="!gameInProgress" | |
14 | @click="startGame('versus')" | |
15 | ) | |
602d6bef | 16 | | {{ st.tr["Practice"] }} |
910d631b BA |
17 | button( |
18 | v-show="gameInProgress" | |
19 | @click="stopGame()" | |
20 | ) | |
602d6bef | 21 | | {{ st.tr["Stop game"] }} |
910d631b | 22 | button( |
20620465 | 23 | v-if="showAnalyzeBtn" |
910d631b BA |
24 | @click="gotoAnalyze()" |
25 | ) | |
677fe285 | 26 | | {{ st.tr["Analyse"] }} |
910d631b BA |
27 | div( |
28 | v-show="display=='rules'" | |
29 | v-html="content" | |
30 | ) | |
31 | ComputerGame( | |
32 | v-show="display=='computer'" | |
33 | :game-info="gameInfo" | |
34 | @game-over="stopGame" | |
35 | @game-stopped="gameStopped" | |
36 | ) | |
cf2343ce BA |
37 | </template> |
38 | ||
39 | <script> | |
a6088c90 | 40 | import ComputerGame from "@/components/ComputerGame.vue"; |
cf2343ce | 41 | import { store } from "@/store"; |
50aed5a1 | 42 | import { getDiagram } from "@/utils/printDiagram"; |
cf2343ce | 43 | export default { |
6808d7a1 | 44 | name: "my-rules", |
24340cae | 45 | components: { |
6808d7a1 | 46 | ComputerGame |
24340cae | 47 | }, |
cf2343ce BA |
48 | data: function() { |
49 | return { | |
50 | st: store.state, | |
cf2343ce | 51 | display: "rules", |
cf2343ce | 52 | gameInProgress: false, |
6dd02928 | 53 | // variables passed to ComputerGame: |
834c202a | 54 | gameInfo: { |
fcbc92c2 | 55 | vname: "", |
834c202a BA |
56 | mode: "versus", |
57 | fen: "", | |
6808d7a1 | 58 | score: "*" |
834c202a | 59 | } |
cf2343ce BA |
60 | }; |
61 | }, | |
42eb4eaf | 62 | watch: { |
6808d7a1 | 63 | $route: function(newRoute) { |
fcbc92c2 | 64 | this.re_setVariant(newRoute.params["vname"]); |
6808d7a1 | 65 | } |
42eb4eaf | 66 | }, |
6f093ada | 67 | created: function() { |
e2732923 | 68 | // NOTE: variant cannot be set before store is initialized |
fcbc92c2 BA |
69 | this.re_setVariant(this.$route.params["vname"]); |
70 | }, | |
71 | computed: { | |
20620465 BA |
72 | showAnalyzeBtn: function() { |
73 | return (this.display=='rules' && (!window.V || V.CanAnalyse)); | |
74 | }, | |
fcbc92c2 | 75 | content: function() { |
6808d7a1 | 76 | if (!this.gameInfo.vname) return ""; //variant not set yet |
fcbc92c2 | 77 | // (AJAX) Request to get rules content (plain text, HTML) |
6808d7a1 BA |
78 | return ( |
79 | require("raw-loader!@/translations/rules/" + | |
80 | this.gameInfo.vname + | |
81 | "/" + | |
82 | this.st.lang + | |
83 | ".pug") | |
84 | // Next two lines fix a weird issue after last update (2019-11) | |
85 | .replace(/\\n/g, " ") | |
86 | .replace(/\\"/g, '"') | |
87 | .replace('module.exports = "', "") | |
88 | .replace(/"$/, "") | |
89 | .replace(/(fen:)([^:]*):/g, this.replaceByDiag) | |
90 | ); | |
91 | } | |
cf2343ce BA |
92 | }, |
93 | methods: { | |
41cb9b94 | 94 | clickReadRules: function() { |
6808d7a1 BA |
95 | if (this.display != "rules") this.display = "rules"; |
96 | else if (this.gameInProgress) this.display = "computer"; | |
41cb9b94 | 97 | }, |
50aed5a1 BA |
98 | parseFen(fen) { |
99 | const fenParts = fen.split(" "); | |
100 | return { | |
101 | position: fenParts[0], | |
102 | marks: fenParts[1], | |
103 | orientation: fenParts[2], | |
6808d7a1 | 104 | shadow: fenParts[3] |
50aed5a1 BA |
105 | }; |
106 | }, | |
fcbc92c2 BA |
107 | // Method to replace diagrams in loaded HTML |
108 | replaceByDiag: function(match, p1, p2) { | |
109 | const args = this.parseFen(p2); | |
110 | return getDiagram(args); | |
111 | }, | |
112 | re_setVariant: async function(vname) { | |
42eb4eaf BA |
113 | const vModule = await import("@/variants/" + vname + ".js"); |
114 | window.V = vModule.VariantRules; | |
fcbc92c2 | 115 | this.gameInfo.vname = vname; |
cf2343ce | 116 | }, |
834c202a | 117 | startGame: function(mode) { |
6808d7a1 | 118 | if (this.gameInProgress) return; |
cf2343ce | 119 | this.gameInProgress = true; |
cf2343ce | 120 | this.display = "computer"; |
834c202a | 121 | this.gameInfo.mode = mode; |
41cb9b94 | 122 | this.gameInfo.score = "*"; |
834c202a | 123 | this.gameInfo.fen = V.GenRandInitFen(); |
cf2343ce | 124 | }, |
41cb9b94 BA |
125 | // user is willing to stop the game: |
126 | stopGame: function(score) { | |
127 | this.gameInfo.score = score || "?"; | |
cf2343ce | 128 | }, |
41cb9b94 BA |
129 | // The game is effectively stopped: |
130 | gameStopped: function() { | |
131 | this.gameInProgress = false; | |
132 | }, | |
5157ce0b | 133 | gotoAnalyze: function() { |
6808d7a1 BA |
134 | this.$router.push( |
135 | "/analyse/" + this.gameInfo.vname + "/?fen=" + V.GenRandInitFen() | |
136 | ); | |
137 | } | |
138 | } | |
cf2343ce BA |
139 | }; |
140 | </script> | |
50aed5a1 | 141 | |
5bcc9b31 BA |
142 | <!-- NOTE: not scoped here, because HTML is injected (TODO) --> |
143 | <style lang="sass"> | |
50aed5a1 BA |
144 | .warn |
145 | padding: 3px | |
146 | color: red | |
147 | background-color: lightgrey | |
148 | font-weight: bold | |
149 | ||
150 | figure.diagram-container | |
151 | margin: 15px 0 15px 0 | |
152 | text-align: center | |
153 | width: 100% | |
154 | display: block | |
155 | .diagram | |
156 | display: block | |
157 | width: 40% | |
158 | min-width: 240px | |
159 | margin-left: auto | |
160 | margin-right: auto | |
161 | .diag12 | |
162 | float: left | |
163 | margin-left: calc(10% - 20px) | |
164 | margin-right: 40px | |
165 | @media screen and (max-width: 630px) | |
166 | float: none | |
167 | margin: 0 auto 10px auto | |
168 | .diag22 | |
169 | float: left | |
170 | margin-right: calc(10% - 20px) | |
171 | @media screen and (max-width: 630px) | |
172 | float: none | |
173 | margin: 0 auto | |
174 | figcaption | |
175 | display: block | |
176 | clear: both | |
177 | padding-top: 5px | |
178 | font-size: 0.8em | |
179 | ||
92a523d1 BA |
180 | p.boxed |
181 | background-color: #FFCC66 | |
182 | padding: 5px | |
50aed5a1 | 183 | |
9a3049f3 BA |
184 | .bigfont |
185 | font-size: 1.2em | |
186 | ||
187 | .bold | |
188 | font-weight: bold | |
189 | ||
92a523d1 BA |
190 | .stageDelimiter |
191 | color: purple | |
50aed5a1 | 192 | |
92a523d1 BA |
193 | // To show (new) pieces, and/or there values... |
194 | figure.showPieces > img | |
195 | width: 50px | |
50aed5a1 | 196 | |
92a523d1 BA |
197 | figure.showPieces > figcaption |
198 | color: #6C6C6C | |
50aed5a1 | 199 | |
92a523d1 BA |
200 | .section-title |
201 | padding: 0 | |
50aed5a1 | 202 | |
92a523d1 BA |
203 | .section-title > h4 |
204 | padding: 5px | |
50aed5a1 | 205 | |
92a523d1 BA |
206 | ol, ul:not(.browser-default) |
207 | padding-left: 20px | |
50aed5a1 | 208 | |
92a523d1 BA |
209 | ul:not(.browser-default) |
210 | margin-top: 5px | |
50aed5a1 | 211 | |
92a523d1 BA |
212 | ul:not(.browser-default) > li |
213 | list-style-type: disc | |
50aed5a1 | 214 | </style> |