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"],
28 // Modal new game, and then sub-components
31 <input id="modalNewgame" type="checkbox" class"="modal"/>
32 <div role="dialog" aria-labelledby="titleFenedit">
33 <div class="card smallpad">
34 <label id="closeNewgame" for="modalNewgame" class="modal-close">
36 <h3 id="titleFenedit" class="section">
37 {{ translate("Game state (FEN):") }}
39 <input id="input-fen" type="text"/>
40 <p>TODO: cadence, adversaire (pre-filled if click on name)</p>
41 <p>Note: leave FEN blank for random</p>
42 <button @click="newGame">Launch game</button>
45 <my-chat :conn="conn" :myname="myname" :people="people"></my-chat>
46 <my-challenge-list :conn="conn"></my-challenge-list>
47 <my-player-list :conn="conn"></my-player-list>
48 <my-game-list :conn="conn" ........... my-local-game-list opposed to my-remote-ame-list ?! ...bof></my-game-list>
49 onClick :: ask full game to remote player, and register as an observer in game
50 (use gameId to communicate)
51 on landing on game :: if gameId not found locally, check remotely
52 ==> il manque un param dans game : "remoteId"
56 const socketMessageListener
= msg
=> {
57 const data
= JSON
.parse(msg
.data
);
60 case "newgame": //challenge accepted
61 // oppid: opponent socket ID (or DB id if registered)
62 this.newGame("human", data
.fen
, data
.color
, data
.oppid
, data
.gameid
);
66 const socketCloseListener
= () => {
67 this.conn
.addEventListener('message', socketMessageListener
);
68 this.conn
.addEventListener('close', socketCloseListener
);
70 this.conn
.onmessage
= socketMessageListener
;
71 this.conn
.onclose
= socketCloseListener
;
74 clickGameSeek: function(e
) {
75 if (this.mode
== "human" && this.score
== "*")
76 return; //no newgame while playing
79 this.conn
.send(JSON
.stringify({code:"cancelnewgame"}));
83 this.newGame("human");
85 newGame: function(mode
, fenInit
, color
, oppId
, gameId
) {
86 const fen
= fenInit
|| VariantRules
.GenRandInitFen();
87 console
.log(fen
); //DEBUG
88 if (mode
=="human" && !oppId
)
90 const storageVariant
= localStorage
.getItem("variant");
91 if (!!storageVariant
&& storageVariant
!== variant
.name
92 && localStorage
["score"] == "*")
94 return alert(translations
["Finish your "] +
95 storageVariant
+ translations
[" game first!"]);
97 // Send game request and wait..
99 this.conn
.send(JSON
.stringify({code:"newgame", fen:fen
, gameid: getRandString() }));
100 } catch (INVALID_STATE_ERR
) {
101 return; //nothing achieved
104 let modalBox
= document
.getElementById("modal-newgame");
105 modalBox
.checked
= true;
106 setTimeout(() => { modalBox
.checked
= false; }, 2000);
109 this.vr
= new VariantRules(fen
, []);
111 this.pgnTxt
= ""; //redundant with this.score = "*", but cleaner
114 this.fenStart
= V
.ParseFen(fen
).position
; //this is enough
118 this.gameId
= gameId
;
120 this.oppConnected
= true;
121 this.mycolor
= color
;
124 new Audio("/sounds/newgame.mp3").play().catch(err
=> {});
125 document
.getElementById("modal-newgame").checked
= false;
127 this.setStorage(); //store game state in case of interruptions
129 continueGame: function() {
130 this.oppid
= localStorage
.getItem("oppid");
131 this.mycolor
= localStorage
.getItem("mycolor");
132 const moves
= JSON
.parse(localStorage
.getItem("moves"));
133 const fen
= localStorage
.getItem("fen");
134 const score
= localStorage
.getItem("score"); //always "*" ?!
135 this.fenStart
= localStorage
.getItem("fenStart");
136 this.vr
= new VariantRules(fen
);
137 this.incheck
= this.vr
.getCheckSquares(this.vr
.turn
);
138 this.gameId
= localStorage
.getItem("gameId");
139 // Send ping to server (answer pong if opponent is connected)
140 this.conn
.send(JSON
.stringify({
141 code:"ping",oppid:this.oppid
,gameId:this.gameId
}));