+ // NOTE: variants array might not be available yet, thus the two next lines
+ const variantCell = this.st.variants.filter(v => v.id == game.vid);
+ const vname = (variantCell.length > 0 ? variantCell[0].name : "");
+ if (!game.fen)
+ game.fen = game.fenStart; //game wasn't started
+ const gtype = (game.timeControl.indexOf('d') >= 0 ? "corr" : "live");
+ const tc = extractTime(game.timeControl);
+ if (gtype == "corr")
+ {
+ // corr game: needs to compute the clocks + initime
+ game.clocks = [tc.mainTime, tc.mainTime];
+ game.initime = [0, 0];
+ let addTime = [0, 0];
+ for (let i=2; i<game.moves.length; i++)
+ {
+ addTime[i%2] += tc.increment -
+ (game.moves[i].played - game.moves[i-1].played);
+ }
+ for (let i=0; i<=1; i++)
+ game.clocks[i] += addTime[i];
+ const L = game.moves.length;
+ game.initime[L%2] = game.moves[L-1].played;
+ }
+ // TODO: this is not really beautiful (uid on corr players...)
+ if (gtype == "corr" && game.players[0].color == "b")
+ [ game.players[0], game.players[1] ] = [ game.players[1], game.players[0] ];
+ const myIdx = game.players.findIndex(p => {
+ return p.sid == this.st.user.sid || p.uid == this.st.user.id;
+ });
+ if (gtype == "live" && game.clocks[0] < 0) //game unstarted
+ {
+ game.clocks = [tc.mainTime, tc.mainTime];
+ game.initime[0] = Date.now();
+ if (myIdx >= 0)
+ {
+ // I play in this live game; corr games don't have clocks+initime
+ GameStorage.update(game.id,
+ {
+ clocks: game.clocks,
+ initime: game.initime,
+ });
+ }
+ }