}
// The score is already computed when calling this function
- getPGN(mycolor, score)
+ getPGN(mycolor, score, fenStart)
{
let pgn = "";
pgn += '[Site "vchess.club"]<br>';
pgn += '[Date "' + d.getFullYear() + '-' + d.getMonth() + '-' + d.getDate() + '"]<br>';
pgn += '[White "' + (mycolor=='w'?'Myself':'Anonymous') + '"]<br>';
pgn += '[Black "' + (mycolor=='b'?'Myself':'Anonymous') + '"]<br>';
- pgn += '[Result "' + score + '"]<br>';
+ pgn += '[Fen "' + fenStart + '"]<br>';
+ pgn += '[Result "' + score + '"]<br><br>';
for (let i=0; i<this.moves.length; i++)
{
oppid: "", //opponent ID in case of HH game
oppConnected: false,
seek: false,
+ fenStart: "",
};
},
render(h) {
}
),
h('h3',
- {
- "class": { "section": true },
- domProps: { innerHTML: "End of game" },
- }
- ),
- h('p',
{
"class": { "section": true },
domProps: { innerHTML: eogMessage },
elemsOfEog.push(
h('p', //'textarea', //TODO: selectable!
{
- domProps: { innerHTML: this.vr.getPGN(this.mycolor, this.score) },
+ domProps: { innerHTML: this.vr.getPGN(this.mycolor, this.score, this.fenStart) },
//attrs: { "readonly": true },
}
)
}
this.endGame(this.mycolor=="w"?"0-1":"1-0");
},
- updateStorage: function() {
- if (!localStorage.getItem("myid"))
- {
- localStorage.setItem("myid", this.myid);
- localStorage.setItem("variant", variant);
- localStorage.setItem("mycolor", this.mycolor);
- localStorage.setItem("oppid", this.oppid);
- }
+ setStorage: function() {
+ localStorage.setItem("myid", this.myid);
+ localStorage.setItem("variant", variant);
+ localStorage.setItem("mycolor", this.mycolor);
+ localStorage.setItem("oppid", this.oppid);
+ localStorage.setItem("fenStart", this.fenStart);
+ localStorage.setItem("moves", JSON.stringify(this.vr.moves));
localStorage.setItem("fen", this.vr.getFen());
+ },
+ updateStorage: function() {
localStorage.setItem("moves", JSON.stringify(this.vr.moves));
+ localStorage.setItem("fen", this.vr.getFen());
},
clearStorage: function() {
delete localStorage["variant"];
delete localStorage["myid"];
delete localStorage["mycolor"];
delete localStorage["oppid"];
+ delete localStorage["fenStart"];
delete localStorage["fen"];
delete localStorage["moves"];
},
}
this.vr = new VariantRules(fen, moves || []);
this.mode = mode;
+ this.fenStart = continuation
+ ? localStorage.getItem("fenStart")
+ : fen.split(" ")[0]; //Only the position matters
if (mode=="human")
{
// Opponent found!
this.mycolor = color;
this.seek = false;
delete localStorage["newgame"];
+ this.setStorage(); //in case of interruptions
}
else //against computer
{