Add initial FEN to PGN; shorten end of game window
authorBenjamin Auder <benjamin.auder@somewhere>
Fri, 16 Nov 2018 18:41:52 +0000 (19:41 +0100)
committerBenjamin Auder <benjamin.auder@somewhere>
Fri, 16 Nov 2018 18:41:52 +0000 (19:41 +0100)
public/javascripts/base_rules.js
public/javascripts/components/game.js

index 0a5c0e7..de1a0d0 100644 (file)
@@ -1012,7 +1012,7 @@ class ChessRules
        }
 
        // The score is already computed when calling this function
-       getPGN(mycolor, score)
+       getPGN(mycolor, score, fenStart)
        {
                let pgn = "";
                pgn += '[Site "vchess.club"]<br>';
@@ -1020,7 +1020,8 @@ class ChessRules
                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++)
                {
index 592a700..81ced5b 100644 (file)
@@ -15,6 +15,7 @@ Vue.component('my-game', {
                        oppid: "", //opponent ID in case of HH game
                        oppConnected: false,
                        seek: false,
+                       fenStart: "",
                };
        },
        render(h) {
@@ -230,12 +231,6 @@ Vue.component('my-game', {
                                        }
                                ),
                                h('h3',
-                                       {
-                                               "class": { "section": true },
-                                               domProps: { innerHTML: "End of game" },
-                                       }
-                               ),
-                               h('p',
                                        {
                                                "class": { "section": true },
                                                domProps: { innerHTML: eogMessage },
@@ -247,7 +242,7 @@ Vue.component('my-game', {
                                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 },
                                                }
                                        )
@@ -430,22 +425,25 @@ Vue.component('my-game', {
                        }
                        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"];
                },
@@ -469,6 +467,9 @@ Vue.component('my-game', {
                        }
                        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!
@@ -483,6 +484,7 @@ Vue.component('my-game', {
                                this.mycolor = color;
                                this.seek = false;
                                delete localStorage["newgame"];
+                               this.setStorage(); //in case of interruptions
                        }
                        else //against computer
                        {