1 // TODO: main playing hall, chat + online players + current challenges + button "new game"
3 input#modal-newgame.modal(type="checkbox")
4 div(role="dialog" aria-labelledby="newGameTxt")
5 .card.smallpad.small-modal
6 label#close-newgame.modal-close(for="modal-newgame")
7 h3#newGameTxt= translations["New game"]
8 p= translations["Waiting for opponent..."]
10 // TODO: my-challenge-list, gérant clicks sur challenges, affichage, réception/émission des infos sur challenges ; de même, my-player-list
11 // TODO: si on est en train de jouer une partie, le notifier aux nouveaux connectés
13 Players + challenges : == "room" home of variant (surligner si nouveau défi perso et pas affichage courant)
14 joueurs en ligne (dte),
15 Nouvelle partie + défis en temps réel + parties en cours (milieu, tabs),
16 chat général (gauche, activé ou non (bool global storage)).
17 (cadences base + incrément, corr == incr >= 1jour ou base >= 7j)
18 --> correspondance: stocker sur serveur lastMove + peerId + color + movesCount + gameId + variant + timeleft
19 quand je poste un lastMove corr, supprimer mon ancien lastMove le cas échéant (tlm l'a eu)
20 fin de partie corr: garder maxi nbPlayers lastMove sur serveur, pendant 7 jours (arbitraire)
22 // TODO: au moins l'échange des coups en P2P ?
23 Vue
.component('my-room', {
24 props: ["conn","settings"],
29 // Modal new game, and then sub-components
32 <input id="modalNewgame" type="checkbox" class"="modal"/>
33 <div role="dialog" aria-labelledby="titleFenedit">
34 <div class="card smallpad">
35 <label id="closeNewgame" for="modalNewgame" class="modal-close">
37 <h3 id="titleFenedit" class="section">
38 {{ translate("Game state (FEN):") }}
40 <input id="input-fen" type="text"/>
41 <p>TODO: cadence, adversaire (pre-filled if click on name)</p>
42 <p>Note: leave FEN blank for random</p>
43 <button @click="newGame">Launch game</button>
47 <my-chat :conn="conn" :myname="myname" :people="people"></my-chat>
48 <my-challenge-list :conn="conn"></my-challenge-list>
51 <my-player-list :conn="conn"></my-player-list>
52 // TODO: also corr games (of pther players)
53 // presentation ? table ?!
54 <my-game-summary v-for="g in remoteGames"
55 v-bind:vobj="g" v-bind:game="g" v-bind:key="g.id"
56 @click="() => showGame(g.id,g.uid)">
62 // TODO: ask server for current corr games (all but mines)
63 const socketMessageListener
= msg
=> {
64 const data
= JSON
.parse(msg
.data
);
67 // TODO: also receive remote games summaries (update)
68 // (just players names, time control, and ID + player ID)
69 case "newgame": //challenge accepted
70 // oppid: opponent socket ID (or DB id if registered)
71 this.newGame("human", data
.fen
, data
.color
, data
.oppid
, data
.gameid
);
75 const socketCloseListener
= () => {
76 this.conn
.addEventListener('message', socketMessageListener
);
77 this.conn
.addEventListener('close', socketCloseListener
);
79 this.conn
.onmessage
= socketMessageListener
;
80 this.conn
.onclose
= socketCloseListener
;
83 clickGameSeek: function(e
) {
84 if (this.mode
== "human" && this.score
== "*")
85 return; //no newgame while playing
88 this.conn
.send(JSON
.stringify({code:"cancelnewgame"}));
92 this.newGame("human");
94 newGame: function(mode
, fenInit
, color
, oppId
, gameId
) {
95 const fen
= fenInit
|| VariantRules
.GenRandInitFen();
96 console
.log(fen
); //DEBUG
97 if (mode
=="human" && !oppId
)
99 const storageVariant
= localStorage
.getItem("variant");
100 if (!!storageVariant
&& storageVariant
!== variant
.name
101 && localStorage
["score"] == "*")
103 return alert(translations
["Finish your "] +
104 storageVariant
+ translations
[" game first!"]);
106 // Send game request and wait..
108 this.conn
.send(JSON
.stringify({code:"newgame", fen:fen
, gameid: getRandString() }));
109 } catch (INVALID_STATE_ERR
) {
110 return; //nothing achieved
113 let modalBox
= document
.getElementById("modal-newgame");
114 modalBox
.checked
= true;
115 setTimeout(() => { modalBox
.checked
= false; }, 2000);
118 this.vr
= new VariantRules(fen
, []);
120 this.pgnTxt
= ""; //redundant with this.score = "*", but cleaner
123 this.fenStart
= V
.ParseFen(fen
).position
; //this is enough
127 this.gameId
= gameId
;
129 this.oppConnected
= true;
130 this.mycolor
= color
;
133 new Audio("/sounds/newgame.mp3").play().catch(err
=> {});
134 document
.getElementById("modal-newgame").checked
= false;
136 this.setStorage(); //store game state in case of interruptions
138 continueGame: function() {
139 this.oppid
= localStorage
.getItem("oppid");
140 this.mycolor
= localStorage
.getItem("mycolor");
141 const moves
= JSON
.parse(localStorage
.getItem("moves"));
142 const fen
= localStorage
.getItem("fen");
143 const score
= localStorage
.getItem("score"); //always "*" ?!
144 this.fenStart
= localStorage
.getItem("fenStart");
145 this.vr
= new VariantRules(fen
);
146 this.incheck
= this.vr
.getCheckSquares(this.vr
.turn
);
147 this.gameId
= localStorage
.getItem("gameId");
148 // Send ping to server (answer pong if opponent is connected)
149 this.conn
.send(JSON
.stringify({
150 code:"ping",oppid:this.oppid
,gameId:this.gameId
}));