<template lang="pug">
.row
.col-sm-12.col-md-10.col-md-offset-1.col-lg-8.col-lg-offset-2
- input#modalAbort.modal(type="checkbox")
- div(role="dialog" aria-labelledby="abortBoxTitle")
- .card.smallpad.small-modal.text-center
- label.modal-close(for="modalAbort")
- h3#abortBoxTitle.section {{ st.tr["Terminate game?"] }}
- button(@click="abortGame") {{ st.tr["Sorry I have to go"] }}
- button(@click="abortGame") {{ st.tr["Game seems over"] }}
- button(@click="abortGame") {{ st.tr["Opponent is gone"] }}
BaseGame(:game="game" :vr="vr" ref="basegame"
@newmove="processMove" @gameover="gameOver")
div Names: {{ game.players[0].name }} - {{ game.players[1].name }}
div(v-if="game.score=='*'") Time: {{ virtualClocks[0] }} - {{ virtualClocks[1] }}
.button-group(v-if="game.mode!='analyze' && game.score=='*'")
button(@click="offerDraw") Draw
- button(@click="() => abortGame()") Abort
+ button(@click="abortGame") Abort
button(@click="resign") Resign
textarea(v-if="game.score=='*'" v-model="corrMsg")
Chat(:players="game.players")
this.gameRef.rid = this.$route.query["rid"]; //may be undefined
if (!this.gameRef.rid)
this.loadGame(); //local or corr: can load from now
- // TODO: mode analyse (/analyze/Atomic/rn
- // ... fen = query[], vname=params[] ...
// 0.1] Ask server for room composition:
const initialize = () => {
// Poll clients + load game if stored remotely
const data = JSON.parse(msg.data);
switch (data.code)
{
+ case "duplicate":
+ alert("Warning: duplicate 'offline' connection");
+ break;
// 0.2] Receive clients list (just socket IDs)
case "pollclients":
{
{
// Send our "last state" informations to opponent
const L = this.game.moves.length;
+ let lastMove = (L>0 ? this.game.moves[L-1] : undefined);
+ if (!!lastMove && this.drawOffer == "sent")
+ lastMove.draw = true;
this.st.conn.send(JSON.stringify({
code: "lastate",
target: player.sid,
state:
{
- lastMove: (L>0 ? this.game.moves[L-1] : undefined),
+ lastMove: lastMove,
score: this.game.score,
movesCount: L,
- drawOffer: this.drawOffer,
clocks: this.game.clocks,
}
}));
this.$refs["basegame"].endGame(data.score, "Opponent action");
}
this.game.clocks = data.clocks; //TODO: check this?
- this.drawOffer = data.drawOffer; //does opponent offer draw?
+ if (!!data.lastMove.draw)
+ this.drawOffer = "received";
}
break;
}
this.game.mycolor=="w" ? "1-0" : "0-1", "Resign");
break;
case "abort":
- this.$refs["basegame"].endGame("?", "Abort: " + data.msg);
+ this.$refs["basegame"].endGame("?", "Abort");
break;
case "draw":
this.$refs["basegame"].endGame("1/2", "Mutual agreement");
case "drawoffer":
this.drawOffer = "received";
break;
+ case "drawaccepted":
+ this.gameOver("1/2");
+ break;
case "askfullgame":
- // TODO: use data.id to retrieve game in indexedDB (but for now only one running game so OK)
this.st.conn.send(JSON.stringify({code:"fullgame", game:this.game, target:data.from}));
break;
case "fullgame":
this.loadGame(data.game);
break;
- // TODO: drawaccepted (click draw button before sending move
- // ==> draw offer in move)
- // ==> on "newmove", check "drawOffer" field
case "connect":
{
this.people.push({name:"", id:0, sid:data.from});
{
if (!confirm("Accept draw?"))
return;
- const oppsid = this.getOppSid();
+ const oppsid = this.getOppSid(); //TODO: to all people...
if (!!oppsid)
this.st.conn.send(JSON.stringify({code:"draw", target:oppsid}));
this.$refs["basegame"].endGame("1/2", "Mutual agreement");
this.st.conn.send(JSON.stringify({code:"drawoffer", target:oppsid}));
}
},
- // + conn handling: "draw" message ==> agree for draw (if we have "drawOffered" at true)
- receiveDrawOffer: function() {
- //if (...)
- // TODO: ignore if preventDrawOffer is set; otherwise show modal box with option "prevent future offers"
- // if accept: send message "draw"
- },
- abortGame: function(event) {
- let modalBox = document.getElementById("modalAbort");
- if (!event)
- {
- // First call show options:
- modalBox.checked = true;
- }
- else
- {
- modalBox.checked = false; //decision made: box disappear
- const message = event.target.innerText;
- // Next line will trigger a "gameover" event, bubbling up till here
- this.$refs["basegame"].endGame("?", "Abort: " + message);
- const oppsid = this.getOppSid();
- if (!!oppsid)
+ abortGame: function() {
+ if (!confirm(this.st.tr["Terminate game?"]))
+ return;
+ // Next line will trigger a "gameover" event, bubbling up till here
+ this.$refs["basegame"].endGame("?", "Abort");
+ this.people.forEach(p => {
+ if (p.sid != this.st.user.sid)
{
this.st.conn.send(JSON.stringify({
code: "abort",
- msg: message,
- target: oppsid,
+ target: p.sid,
}));
}
- }
+ });
},
resign: function(e) {
if (!confirm("Resign the game?"))
[ game.players[1], game.players[0] ];
}
// corr game: needs to compute the clocks + initime
+ // NOTE: clocks in seconds, initime in milliseconds
game.clocks = [tc.mainTime, tc.mainTime];
game.initime = [0, 0];
const L = game.moves.length;
for (let i=2; i<L; i++)
{
addTime[i%2] += tc.increment -
- (game.moves[i].played - game.moves[i-1].played);
+ (game.moves[i].played - game.moves[i-1].played) / 1000;
}
for (let i=0; i<=1; i++)
game.clocks[i] += addTime[i];