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