// elementArray.push(reserve);
// }
const eogMessage = this.getEndgameMessage(this.score);
- let elemsOfEog =
- [
- h('label',
- {
- attrs: { "for": "modal-control" },
- "class": { "modal-close": true },
- }
- ),
- h('h3',
- {
- "class": { "section": true },
- domProps: { innerHTML: eogMessage },
- }
- )
- ];
- if (this.score != "*")
- {
- elemsOfEog.push(
- h('p', //'textarea', //TODO: selectable!
- {
- domProps: { innerHTML: this.vr.getPGN(this.mycolor, this.score, this.fenStart) },
- //attrs: { "readonly": true },
- }
- )
- );
- }
const modalEog = [
h('input',
{
- attrs: { "id": "modal-control", type: "checkbox" },
+ attrs: { "id": "modal-eog", type: "checkbox" },
"class": { "modal": true },
}),
h('div',
{
"class": { "card": true, "smallpad": true },
},
- elemsOfEog
+ [
+ h('label',
+ {
+ attrs: { "for": "modal-eog" },
+ "class": { "modal-close": true },
+ }
+ ),
+ h('h3',
+ {
+ "class": { "section": true },
+ domProps: { innerHTML: eogMessage },
+ }
+ )
+ ]
)
]
)
const modalNewgame = [
h('input',
{
- attrs: { "id": "modal-control2", type: "checkbox" },
+ attrs: { "id": "modal-newgame", type: "checkbox" },
"class": { "modal": true },
}),
h('div',
[
h('label',
{
- attrs: { "id": "close-newgame", "for": "modal-control2" },
+ attrs: { "id": "close-newgame", "for": "modal-newgame" },
"class": { "modal-close": true },
}
),
actionArray
);
elementArray.push(actions);
+ if (this.score != "*")
+ {
+ elementArray.push(
+ h('div',
+ { },
+ [
+ h('p',
+ {
+ domProps: {
+ innerHTML: this.vr.getPGN(this.mycolor, this.score, this.fenStart, this.mode)
+ }
+ }
+ )
+ ]
+ )
+ );
+ }
return h(
'div',
{
const moves = JSON.parse(localStorage.getItem("moves"));
this.newGame("human", fen, mycolor, oppid, moves, true);
// Send ping to server (answer pong if opponent is connected)
- this.conn.send(JSON.stringify({code:"ping",oppid:this.oppId}));
+ this.conn.send(JSON.stringify({code:"ping",oppid:this.oppid}));
}
else if (localStorage.getItem("newgame") === variant)
{
}
else if (data.movesCount > this.vr.moves.length) //just got last move from him
this.play(data.lastMove, "animate");
+ break;
case "resign": //..you won!
this.endGame(this.mycolor=="w"?"1-0":"0-1");
break;
}
};
const socketCloseListener = () => {
- console.log("Lost connection -- reconnect");
this.conn = new WebSocket(url + "/?sid=" + this.myid + "&page=" + variant);
this.conn.addEventListener('open', socketOpenListener);
this.conn.addEventListener('message', socketMessageListener);
methods: {
endGame: function(score) {
this.score = score;
- let modalBox = document.getElementById("modal-control");
+ let modalBox = document.getElementById("modal-eog");
modalBox.checked = true;
- //setTimeout(() => { modalBox.checked = false; }, 2000); //disabled, to show PGN
+ setTimeout(() => { modalBox.checked = false; }, 2000);
if (this.mode == "human")
this.clearStorage();
this.mode = "idle";
if (this.mode == "human")
return; //no newgame while playing
if (this.seek)
+ {
delete localStorage["newgame"]; //cancel game seek
+ this.seek = false;
+ }
else
- {
- localStorage["newgame"] = variant;
this.newGame("human");
- }
- this.seek = !this.seek;
},
clickComputerGame: function() {
if (this.mode == "human")
const storageVariant = localStorage.getItem("variant");
if (!!storageVariant && storageVariant !== variant)
{
- // TODO: find a better way to ensure this. Newgame system is currently a mess.
alert("Finish your " + storageVariant + " game first!");
return;
}
// Send game request and wait..
+ localStorage["newgame"] = variant;
+ this.seek = true;
this.clearStorage(); //in case of
try {
this.conn.send(JSON.stringify({code:"newgame", fen:fen}));
}
if (continuation !== "reconnect") //TODO: bad HACK...
{
- let modalBox = document.getElementById("modal-control2");
+ let modalBox = document.getElementById("modal-newgame");
modalBox.checked = true;
setTimeout(() => { modalBox.checked = false; }, 2000);
}
// Opponent found!
if (!continuation)
{
- // Playing sound fails on game continuation:
- new Audio("/sounds/newgame.mp3").play();
- document.getElementById("modal-control2").checked = false;
+ // Not playing sound on game continuation:
+ new Audio("/sounds/newgame.mp3").play().then(() => {}).catch(err => {});
+ document.getElementById("modal-newgame").checked = false;
}
this.oppid = oppId;
this.oppConnected = true;
{
const oppCol = this.vr.turn;
const lastMove = moves[moves.length-1];
- this.vr.undo(lastMove, "ingame");
+ this.vr.undo(lastMove);
this.incheck = this.vr.getCheckSquares(lastMove, oppCol);
this.vr.play(lastMove, "ingame");
}
// Not programmatic, or animation is over
if (this.mode == "human" && this.vr.turn == this.mycolor)
this.conn.send(JSON.stringify({code:"newmove", move:move, oppid:this.oppid}));
- new Audio("/sounds/chessmove1.mp3").play();
+ new Audio("/sounds/chessmove1.mp3").play().then(() => {}).catch(err => {});
this.vr.play(move, "ingame");
if (this.mode == "human")
this.updateStorage(); //after our moves and opponent moves