Attempt to fix selected piece over smartphone menu
[vchess.git] / client / src / views / Game.vue
1 <template lang="pug">
2 main
3 input#modalChat.modal(type="checkbox" @click="resetChatColor()")
4 div#chatWrap(role="dialog" data-checkbox="modalChat")
5 #chat.card
6 label.modal-close(for="modalChat")
7 #participants
8 span {{ Object.keys(people).length + " " + st.tr["participant(s):"] }}
9 span(v-for="p in Object.values(people)" v-if="!!p.name")
10 | {{ p.name }}
11 span.anonymous(v-if="Object.values(people).some(p => !p.name)")
12 | + @nonymous
13 Chat(:players="game.players" :pastChats="game.chats"
14 :newChat="newChat" @mychat="processChat")
15 .row
16 #aboveBoard.col-sm-12.col-md-9.col-md-offset-3.col-lg-10.col-lg-offset-2
17 span.variant-cadence {{ game.cadence }}
18 span.variant-name {{ game.vname }}
19 button#chatBtn(onClick="doClick('modalChat')") Chat
20 #actions(v-if="game.score=='*'")
21 button(@click="clickDraw()" :class="{['draw-' + drawOffer]: true}")
22 | {{ st.tr["Draw"] }}
23 button(v-if="!!game.mycolor" @click="abortGame()") {{ st.tr["Abort"] }}
24 button(v-if="!!game.mycolor" @click="resign()") {{ st.tr["Resign"] }}
25 #playersInfo
26 p
27 span.name(:class="{connected: isConnected(0)}")
28 | {{ game.players[0].name || "@nonymous" }}
29 span.time(v-if="game.score=='*'") {{ virtualClocks[0] }}
30 span.split-names -
31 span.name(:class="{connected: isConnected(1)}")
32 | {{ game.players[1].name || "@nonymous" }}
33 span.time(v-if="game.score=='*'") {{ virtualClocks[1] }}
34 BaseGame(:game="game" :vr="vr" @newmove="processMove" @gameover="gameOver")
35 </template>
36
37 <script>
38 import BaseGame from "@/components/BaseGame.vue";
39 import Chat from "@/components/Chat.vue";
40 import { store } from "@/store";
41 import { GameStorage } from "@/utils/gameStorage";
42 import { ppt } from "@/utils/datetime";
43 import { extractTime } from "@/utils/timeControl";
44 import { getRandString } from "@/utils/alea";
45 import { ArrayFun } from "@/utils/array";
46 import { processModalClick } from "@/utils/modalClick";
47 import { getScoreMessage } from "@/utils/scoring";
48 import params from "@/parameters";
49 export default {
50 name: 'my-game',
51 components: {
52 BaseGame,
53 Chat,
54 },
55 // gameRef: to find the game in (potentially remote) storage
56 data: function() {
57 return {
58 st: store.state,
59 gameRef: { //given in URL (rid = remote ID)
60 id: "",
61 rid: ""
62 },
63 game: { //passed to BaseGame
64 players:[{name:""},{name:""}],
65 chats: [],
66 rendered: false,
67 },
68 virtualClocks: [0, 0], //initialized with true game.clocks
69 vr: null, //"variant rules" object initialized from FEN
70 drawOffer: "",
71 people: {}, //players + observers
72 lastate: undefined, //used if opponent send lastate before game is ready
73 repeat: {}, //detect position repetition
74 newChat: "",
75 conn: null,
76 connexionString: "",
77 // Related to (killing of) self multi-connects:
78 newConnect: {},
79 killed: {},
80 };
81 },
82 watch: {
83 "$route": function(to, from) {
84 this.gameRef.id = to.params["id"];
85 this.gameRef.rid = to.query["rid"];
86 this.loadGame();
87 },
88 "game.clocks": function(newState) {
89 if (this.game.moves.length < 2 || this.game.score != "*")
90 {
91 // 1st move not completed yet, or game over: freeze time
92 this.virtualClocks = newState.map(s => ppt(s));
93 return;
94 }
95 const currentTurn = this.vr.turn;
96 const colorIdx = ["w","b"].indexOf(currentTurn);
97 let countdown = newState[colorIdx] -
98 (Date.now() - this.game.initime[colorIdx])/1000;
99 this.virtualClocks = [0,1].map(i => {
100 const removeTime = i == colorIdx
101 ? (Date.now() - this.game.initime[colorIdx])/1000
102 : 0;
103 return ppt(newState[i] - removeTime);
104 });
105 let clockUpdate = setInterval(() => {
106 if (countdown < 0 || this.vr.turn != currentTurn || this.game.score != "*")
107 {
108 clearInterval(clockUpdate);
109 if (countdown < 0)
110 this.gameOver(this.vr.turn=="w" ? "0-1" : "1-0", this.st.tr["Time"]);
111 }
112 else
113 this.$set(this.virtualClocks, colorIdx, ppt(Math.max(0, --countdown)));
114 }, 1000);
115 },
116 },
117 // NOTE: some redundant code with Hall.vue (mostly related to people array)
118 created: function() {
119 // Always add myself to players' list
120 const my = this.st.user;
121 this.$set(this.people, my.sid, {id:my.id, name:my.name});
122 this.gameRef.id = this.$route.params["id"];
123 this.gameRef.rid = this.$route.query["rid"]; //may be undefined
124 // Initialize connection
125 this.connexionString = params.socketUrl +
126 "/?sid=" + this.st.user.sid +
127 "&tmpId=" + getRandString() +
128 "&page=" + encodeURIComponent(this.$route.path);
129 this.conn = new WebSocket(this.connexionString);
130 this.conn.onmessage = this.socketMessageListener;
131 this.conn.onclose = this.socketCloseListener;
132 // Socket init required before loading remote game:
133 const socketInit = (callback) => {
134 if (!!this.conn && this.conn.readyState == 1) //1 == OPEN state
135 callback();
136 else //socket not ready yet (initial loading)
137 {
138 // NOTE: it's important to call callback without arguments,
139 // otherwise first arg is Websocket object and loadGame fails.
140 this.conn.onopen = () => { return callback() };
141 }
142 };
143 if (!this.gameRef.rid) //game stored locally or on server
144 this.loadGame(null, () => socketInit(this.roomInit));
145 else //game stored remotely: need socket to retrieve it
146 {
147 // NOTE: the callback "roomInit" will be lost, so we don't provide it.
148 // --> It will be given when receiving "fullgame" socket event.
149 // A more general approach would be to store it somewhere.
150 socketInit(this.loadGame);
151 }
152 },
153 mounted: function() {
154 document.getElementById("chatWrap").addEventListener(
155 "click", processModalClick);
156 },
157 beforeDestroy: function() {
158 this.send("disconnect");
159 },
160 methods: {
161 roomInit: function() {
162 // Notify the room only now that I connected, because
163 // messages might be lost otherwise (if game loading is slow)
164 this.send("connect");
165 this.send("pollclients");
166 },
167 send: function(code, obj) {
168 if (!!this.conn)
169 {
170 this.conn.send(JSON.stringify(
171 Object.assign(
172 {code: code},
173 obj,
174 )
175 ));
176 }
177 },
178 isConnected: function(index) {
179 const player = this.game.players[index];
180 // Is it me ?
181 if (this.st.user.sid == player.sid || this.st.user.id == player.uid)
182 return true;
183 // Try to find a match in people:
184 return Object.keys(this.people).some(sid => sid == player.sid) ||
185 Object.values(this.people).some(p => p.id == player.uid);
186 },
187 socketMessageListener: function(msg) {
188 if (!this.conn)
189 return;
190 const data = JSON.parse(msg.data);
191 switch (data.code)
192 {
193 case "pollclients":
194 data.sockIds.forEach(sid => {
195 this.$set(this.people, sid, {id:0, name:""});
196 if (sid != this.st.user.sid)
197 {
198 this.send("askidentity", {target:sid});
199 // Ask potentially missed last state, if opponent and I play
200 if (!!this.game.mycolor
201 && this.game.type == "live" && this.game.score == "*"
202 && this.game.players.some(p => p.sid == sid))
203 {
204 this.send("asklastate", {target:sid});
205 }
206 }
207 });
208 break;
209 case "connect":
210 if (!this.people[data.from])
211 this.$set(this.people, data.from, {name:"", id:0});
212 if (!this.people[data.from].name)
213 {
214 this.newConnect[data.from] = true; //for self multi-connects tests
215 this.send("askidentity", {target:data.from});
216 }
217 break;
218 case "disconnect":
219 this.$delete(this.people, data.from);
220 break;
221 case "killed":
222 // I logged in elsewhere:
223 alert(this.st.tr["New connexion detected: tab now offline"]);
224 // TODO: this fails. See https://github.com/websockets/ws/issues/489
225 //this.conn.removeEventListener("message", this.socketMessageListener);
226 //this.conn.removeEventListener("close", this.socketCloseListener);
227 //this.conn.close();
228 this.conn = null;
229 break;
230 case "askidentity":
231 {
232 // Request for identification (TODO: anonymous shouldn't need to reply)
233 const me = {
234 // Decompose to avoid revealing email
235 name: this.st.user.name,
236 sid: this.st.user.sid,
237 id: this.st.user.id,
238 };
239 this.send("identity", {data:me, target:data.from});
240 break;
241 }
242 case "identity":
243 {
244 const user = data.data;
245 if (!!user.name) //otherwise anonymous
246 {
247 // If I multi-connect, kill current connexion if no mark (I'm older)
248 if (this.newConnect[user.sid] && user.id > 0
249 && user.id == this.st.user.id && user.sid != this.st.user.sid)
250 {
251 if (!this.killed[this.st.user.sid])
252 {
253 this.send("killme", {sid:this.st.user.sid});
254 this.killed[this.st.user.sid] = true;
255 }
256 }
257 if (user.sid != this.st.user.sid) //I already know my identity...
258 {
259 this.$set(this.people, user.sid,
260 {
261 id: user.id,
262 name: user.name,
263 });
264 }
265 }
266 delete this.newConnect[user.sid];
267 break;
268 }
269 case "askgame":
270 // Send current (live) game if not asked by any of the players
271 if (this.game.type == "live"
272 && this.game.players.every(p => p.sid != data.from[0]))
273 {
274 const myGame = {
275 id: this.game.id,
276 fen: this.game.fen,
277 players: this.game.players,
278 vid: this.game.vid,
279 cadence: this.game.cadence,
280 score: this.game.score,
281 rid: this.st.user.sid, //useful in Hall if I'm an observer
282 };
283 this.send("game", {data:myGame, target:data.from});
284 }
285 break;
286 case "askfullgame":
287 this.send("fullgame", {data:this.game, target:data.from});
288 break;
289 case "fullgame":
290 // Callback "roomInit" to poll clients only after game is loaded
291 this.loadGame(data.data, this.roomInit);
292 break;
293 case "asklastate":
294 // Sending last state if I played a move or score != "*"
295 if ((this.game.moves.length > 0 && this.vr.turn != this.game.mycolor)
296 || this.game.score != "*" || this.drawOffer == "sent")
297 {
298 // Send our "last state" informations to opponent
299 const L = this.game.moves.length;
300 const myIdx = ["w","b"].indexOf(this.game.mycolor);
301 const myLastate = {
302 // NOTE: lastMove (when defined) includes addTime
303 lastMove: (L>0 ? this.game.moves[L-1] : undefined),
304 // Since we played a move (or abort or resign),
305 // only drawOffer=="sent" is possible
306 drawSent: this.drawOffer == "sent",
307 score: this.game.score,
308 movesCount: L,
309 initime: this.game.initime[1-myIdx], //relevant only if I played
310 };
311 this.send("lastate", {data:myLastate, target:data.from});
312 }
313 break;
314 case "lastate": //got opponent infos about last move
315 this.lastate = data.data;
316 if (this.game.rendered) //game is rendered (Board component)
317 this.processLastate();
318 //else: will be processed when game is ready
319 break;
320 case "newmove":
321 {
322 const move = data.data;
323 if (!!move.cancelDrawOffer) //opponent refuses draw
324 {
325 this.drawOffer = "";
326 // NOTE for corr games: drawOffer reset by player in turn
327 if (this.game.type == "live" && !!this.game.mycolor)
328 GameStorage.update(this.gameRef.id, {drawOffer: ""});
329 }
330 this.$set(this.game, "moveToPlay", move);
331 break;
332 }
333 case "resign":
334 this.gameOver(data.side=="b" ? "1-0" : "0-1", "Resign");
335 break;
336 case "abort":
337 this.gameOver("?", "Abort");
338 break;
339 case "draw":
340 this.gameOver("1/2", data.data);
341 break;
342 case "drawoffer":
343 // NOTE: observers don't know who offered draw
344 this.drawOffer = "received";
345 break;
346 case "newchat":
347 this.newChat = data.data;
348 if (!document.getElementById("modalChat").checked)
349 document.getElementById("chatBtn").classList.add("somethingnew");
350 break;
351 }
352 },
353 socketCloseListener: function() {
354 this.conn = new WebSocket(this.connexionString);
355 this.conn.addEventListener('message', this.socketMessageListener);
356 this.conn.addEventListener('close', this.socketCloseListener);
357 },
358 // lastate was received, but maybe game wasn't ready yet:
359 processLastate: function() {
360 const data = this.lastate;
361 this.lastate = undefined; //security...
362 const L = this.game.moves.length;
363 if (data.movesCount > L)
364 {
365 // Just got last move from him
366 this.$set(this.game, "moveToPlay", Object.assign({initime: data.initime}, data.lastMove));
367 }
368 if (data.drawSent)
369 this.drawOffer = "received";
370 if (data.score != "*")
371 {
372 this.drawOffer = "";
373 if (this.game.score == "*")
374 this.gameOver(data.score);
375 }
376 },
377 clickDraw: function() {
378 if (!this.game.mycolor)
379 return; //I'm just spectator
380 if (["received","threerep"].includes(this.drawOffer))
381 {
382 if (!confirm(this.st.tr["Accept draw?"]))
383 return;
384 const message = (this.drawOffer == "received"
385 ? "Mutual agreement"
386 : "Three repetitions");
387 this.send("draw", {data:message});
388 this.gameOver("1/2", message);
389 }
390 else if (this.drawOffer == "") //no effect if drawOffer == "sent"
391 {
392 if (this.game.mycolor != this.vr.turn)
393 return alert(this.st.tr["Draw offer only in your turn"]);
394 if (!confirm(this.st.tr["Offer draw?"]))
395 return;
396 this.drawOffer = "sent";
397 this.send("drawoffer");
398 GameStorage.update(this.gameRef.id, {drawOffer: this.game.mycolor});
399 }
400 },
401 abortGame: function() {
402 if (!this.game.mycolor || !confirm(this.st.tr["Terminate game?"]))
403 return;
404 this.gameOver("?", "Abort");
405 this.send("abort");
406 },
407 resign: function(e) {
408 if (!this.game.mycolor || !confirm(this.st.tr["Resign the game?"]))
409 return;
410 this.send("resign", {data:this.game.mycolor});
411 this.gameOver(this.game.mycolor=="w" ? "0-1" : "1-0", "Resign");
412 },
413 // 3 cases for loading a game:
414 // - from indexedDB (running or completed live game I play)
415 // - from server (one correspondance game I play[ed] or not)
416 // - from remote peer (one live game I don't play, finished or not)
417 loadGame: function(game, callback) {
418 const afterRetrieval = async (game) => {
419 const vModule = await import("@/variants/" + game.vname + ".js");
420 window.V = vModule.VariantRules;
421 this.vr = new V(game.fen);
422 const gtype = (game.cadence.indexOf('d') >= 0 ? "corr" : "live");
423 const tc = extractTime(game.cadence);
424 if (!game.chats)
425 game.chats = []; //live games don't have chat history
426 if (gtype == "corr")
427 {
428 if (game.players[0].color == "b")
429 {
430 // Adopt the same convention for live and corr games: [0] = white
431 [ game.players[0], game.players[1] ] =
432 [ game.players[1], game.players[0] ];
433 }
434 // corr game: needs to compute the clocks + initime
435 // NOTE: clocks in seconds, initime in milliseconds
436 game.clocks = [tc.mainTime, tc.mainTime];
437 game.moves.sort((m1,m2) => m1.idx - m2.idx); //in case of
438 if (game.score == "*") //otherwise no need to bother with time
439 {
440 game.initime = [0, 0];
441 const L = game.moves.length;
442 if (L >= 3)
443 {
444 let addTime = [0, 0];
445 for (let i=2; i<L; i++)
446 {
447 addTime[i%2] += tc.increment -
448 (game.moves[i].played - game.moves[i-1].played) / 1000;
449 }
450 for (let i=0; i<=1; i++)
451 game.clocks[i] += addTime[i];
452 }
453 if (L >= 1)
454 game.initime[L%2] = game.moves[L-1].played;
455 }
456 // Now that we used idx and played, re-format moves as for live games
457 game.moves = game.moves.map( (m) => {
458 const s = m.squares;
459 return {
460 appear: s.appear,
461 vanish: s.vanish,
462 start: s.start,
463 end: s.end,
464 };
465 });
466 // Also sort chat messages (if any)
467 game.chats.sort( (c1,c2) => { return c2.added - c1.added; });
468 }
469 const myIdx = game.players.findIndex(p => {
470 return p.sid == this.st.user.sid || p.uid == this.st.user.id;
471 });
472 if (gtype == "live" && game.clocks[0] < 0) //game unstarted
473 {
474 game.clocks = [tc.mainTime, tc.mainTime];
475 if (game.score == "*")
476 {
477 game.initime[0] = Date.now();
478 if (myIdx >= 0)
479 {
480 // I play in this live game; corr games don't have clocks+initime
481 GameStorage.update(game.id,
482 {
483 clocks: game.clocks,
484 initime: game.initime,
485 });
486 }
487 }
488 }
489 if (!!game.drawOffer)
490 {
491 if (game.drawOffer == "t") //three repetitions
492 this.drawOffer = "threerep";
493 else
494 {
495 if (myIdx < 0)
496 this.drawOffer = "received"; //by any of the players
497 else
498 {
499 // I play in this game:
500 if ((game.drawOffer == "w" && myIdx==0) || (game.drawOffer=="b" && myIdx==1))
501 this.drawOffer = "sent";
502 else //all other cases
503 this.drawOffer = "received";
504 }
505 }
506 }
507 if (!!game.scoreMsg)
508 game.scoreMsg = this.st.tr[game.scoreMsg]; //stored in english
509 this.game = Object.assign({},
510 game,
511 // NOTE: assign mycolor here, since BaseGame could also be VS computer
512 {
513 type: gtype,
514 increment: tc.increment,
515 mycolor: [undefined,"w","b"][myIdx+1],
516 // opponent sid not strictly required (or available), but easier
517 // at least oppsid or oppid is available anyway:
518 oppsid: (myIdx < 0 ? undefined : game.players[1-myIdx].sid),
519 oppid: (myIdx < 0 ? undefined : game.players[1-myIdx].uid),
520 }
521 );
522 this.$nextTick(() => {
523 this.game.rendered = true;
524 // Did lastate arrive before game was rendered?
525 if (!!this.lastate)
526 this.processLastate();
527 });
528 this.repeat = {}; //reset: scan past moves' FEN:
529 let repIdx = 0;
530 // NOTE: vr_tmp to obtain FEN strings is redundant with BaseGame
531 let vr_tmp = new V(game.fenStart);
532 game.moves.forEach(m => {
533 vr_tmp.play(m);
534 const fenObj = V.ParseFen( vr_tmp.getFen() );
535 repIdx = fenObj.position + "_" + fenObj.turn;
536 if (!!fenObj.flags)
537 repIdx += "_" + fenObj.flags;
538 this.repeat[repIdx] = (!!this.repeat[repIdx]
539 ? this.repeat[repIdx]+1
540 : 1);
541 });
542 if (this.repeat[repIdx] >= 3)
543 this.drawOffer = "threerep";
544 if (!!callback)
545 callback();
546 };
547 if (!!game)
548 return afterRetrieval(game);
549 if (!!this.gameRef.rid)
550 {
551 // Remote live game: forgetting about callback func... (TODO: design)
552 this.send("askfullgame", {target:this.gameRef.rid});
553 }
554 else
555 {
556 // Local or corr game
557 GameStorage.get(this.gameRef.id, afterRetrieval);
558 }
559 },
560 // Post-process a move (which was just played in BaseGame)
561 processMove: function(move) {
562 if (this.game.type == "corr" && move.color == this.game.mycolor)
563 {
564
565 //TODO: if takeback, then time over occurs.
566
567 if (!confirm(this.st.tr["Move played:"] + " " + move.notation + "\n" + this.st.tr["Are you sure?"]))
568 return this.$set(this.game, "moveToUndo", move);
569 }
570 // Update storage (corr or live) if I play in the game
571 const colorIdx = ["w","b"].indexOf(move.color);
572 const nextIdx = ["w","b"].indexOf(this.vr.turn);
573 // https://stackoverflow.com/a/38750895
574 if (!!this.game.mycolor)
575 {
576 const allowed_fields = ["appear", "vanish", "start", "end"];
577 // NOTE: 'var' to see this variable outside this block
578 var filtered_move = Object.keys(move)
579 .filter(key => allowed_fields.includes(key))
580 .reduce((obj, key) => {
581 obj[key] = move[key];
582 return obj;
583 }, {});
584 }
585 // Send move ("newmove" event) to people in the room (if our turn)
586 let addTime = 0;
587 if (move.color == this.game.mycolor)
588 {
589 if (this.drawOffer == "received") //I refuse draw
590 this.drawOffer = "";
591 if (this.game.moves.length >= 2) //after first move
592 {
593 const elapsed = Date.now() - this.game.initime[colorIdx];
594 // elapsed time is measured in milliseconds
595 addTime = this.game.increment - elapsed/1000;
596 }
597 const sendMove = Object.assign({},
598 filtered_move,
599 {
600 addTime: addTime,
601 cancelDrawOffer: this.drawOffer=="",
602 });
603 this.send("newmove", {data: sendMove});
604 // (Add)Time indication: useful in case of lastate infos requested
605 move.addTime = addTime;
606 }
607 else
608 addTime = move.addTime; //supposed transmitted
609 // Update current game object:
610 this.game.moves.push(move);
611 this.game.fen = move.fen;
612 this.$set(this.game.clocks, colorIdx, this.game.clocks[colorIdx] + addTime);
613 // move.initime is set only when I receive a "lastate" move from opponent
614 this.game.initime[nextIdx] = move.initime || Date.now();
615 // If repetition detected, consider that a draw offer was received:
616 const fenObj = V.ParseFen(move.fen);
617 let repIdx = fenObj.position + "_" + fenObj.turn;
618 if (!!fenObj.flags)
619 repIdx += "_" + fenObj.flags;
620 this.repeat[repIdx] = (!!this.repeat[repIdx]
621 ? this.repeat[repIdx]+1
622 : 1);
623 if (this.repeat[repIdx] >= 3)
624 this.drawOffer = "threerep";
625 else if (this.drawOffer == "threerep")
626 this.drawOffer = "";
627 // Since corr games are stored at only one location, update should be
628 // done only by one player for each move:
629 if (!!this.game.mycolor &&
630 (this.game.type == "live" || move.color == this.game.mycolor))
631 {
632 let drawCode = "";
633 switch (this.drawOffer)
634 {
635 case "threerep":
636 drawCode = "t";
637 break;
638 case "sent":
639 drawCode = this.game.mycolor;
640 break;
641 case "received":
642 drawCode = this.vr.turn;
643 break;
644 }
645 if (this.game.type == "corr")
646 {
647 GameStorage.update(this.gameRef.id,
648 {
649 fen: move.fen,
650 move:
651 {
652 squares: filtered_move,
653 played: Date.now(),
654 idx: this.game.moves.length - 1,
655 },
656 drawOffer: drawCode || "n", //"n" for "None" to force reset (otherwise it's ignored)
657 });
658 }
659 else //live
660 {
661 GameStorage.update(this.gameRef.id,
662 {
663 fen: move.fen,
664 move: filtered_move,
665 clocks: this.game.clocks,
666 initime: this.game.initime,
667 drawOffer: drawCode,
668 });
669 }
670 }
671 },
672 resetChatColor: function() {
673 // TODO: this is called twice, once on opening an once on closing
674 document.getElementById("chatBtn").classList.remove("somethingnew");
675 },
676 processChat: function(chat) {
677 this.send("newchat", {data:chat});
678 // NOTE: anonymous chats in corr games are not stored on server (TODO?)
679 if (this.game.type == "corr" && this.st.user.id > 0)
680 GameStorage.update(this.gameRef.id, {chat: chat});
681 },
682 gameOver: function(score, scoreMsg) {
683 this.game.score = score;
684 this.game.scoreMsg = this.st.tr[(!!scoreMsg
685 ? scoreMsg
686 : getScoreMessage(score))];
687 const myIdx = this.game.players.findIndex(p => {
688 return p.sid == this.st.user.sid || p.uid == this.st.user.id;
689 });
690 if (myIdx >= 0) //OK, I play in this game
691 {
692 GameStorage.update(this.gameRef.id,
693 {score: score, scoreMsg: scoreMsg});
694 // Notify the score to main Hall. TODO: only one player (currently double send)
695 this.send("result", {gid:this.game.id, score:score});
696 }
697 },
698 },
699 };
700 </script>
701
702 <style lang="sass" scoped>
703 .connected
704 background-color: lightgreen
705
706 #participants
707 margin-left: 5px
708
709 .anonymous
710 color: grey
711 font-style: italic
712
713 #playersInfo > p
714 margin: 0
715
716 @media screen and (min-width: 768px)
717 #actions
718 width: 300px
719 @media screen and (max-width: 767px)
720 .game
721 width: 100%
722
723 #actions
724 display: inline-block
725 margin: 0
726 button
727 display: inline-block
728 margin: 0
729
730 @media screen and (max-width: 767px)
731 #aboveBoard
732 text-align: center
733 @media screen and (min-width: 768px)
734 #aboveBoard
735 margin-left: 30%
736
737 .variant-cadence
738 padding-right: 10px
739
740 .variant-name
741 font-weight: bold
742 padding-right: 10px
743
744 .name
745 font-size: 1.5rem
746 padding: 1px
747
748 .time
749 font-size: 2rem
750 display: inline-block
751 margin-left: 10px
752
753 .split-names
754 display: inline-block
755 margin: 0 15px
756
757 #chat
758 padding-top: 20px
759 max-width: 767px
760 border: none;
761
762 #chatBtn
763 margin: 0 10px 0 0
764
765 .draw-sent, .draw-sent:hover
766 background-color: lightyellow
767
768 .draw-received, .draw-received:hover
769 background-color: lightgreen
770
771 .draw-threerep, .draw-threerep:hover
772 background-color: #e4d1fc
773
774 .somethingnew
775 background-color: #c5fefe
776 </style>