- // Extract times (in [milli?]seconds), set clocks,
- // store in localStorage if live (on server otherwise)
-// const fen = chall.fen || V.GenRandInitFen();
-// const game = {}; //TODO: fen, players, time ...
-// //setStorage(game); //TODO
-// game.players.forEach(p => { //...even if game is by corr (could be played live, why not...)
-// this.conn.send(
-// JSON.stringify({code:"newgame", oppid:p.id, game:game}));
-// });
-// if (this.settings.sound >= 1)
-// new Audio("/sounds/newgame.mp3").play().catch(err => {});
+ // Extract times (in [milli]seconds), set clocks
+ const tc = extractTime(gameInfo.timeControl);
+ const IPlayFirst = (gameInfo.players[0].sid == this.st.user.sid);
+ const game =
+ {
+ // Game infos: constant
+ gameId: gameInfo.gameId,
+ vname: this.getVname(gameInfo.vid),
+ fenStart: gameInfo.fen,
+ players: gameInfo.players,
+ timeControl: gameInfo.timeControl,
+ increment: tc.increment,
+ mode: "live", //function for live games only
+ // Game state: will be updated
+ fen: gameInfo.fen,
+ moves: [],
+ clocks: [...Array(gameInfo.players.length)].fill(tc.mainTime),
+ initime: (IPlayFirst ? Date.now() : undefined),
+ score: "*",
+ };
+ GameStorage.add(game);
+ if (this.st.settings.sound >= 1)
+ new Audio("/sounds/newgame.mp3").play().catch(err => {});
+ // TODO: redirect to game