X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=public%2Fjavascripts%2Fcomponents%2Fgame.js;h=3eb27f27130689013d72437bca18b5c61b40d8bd;hb=01ca2adce0ddcf246f184c6d19389262b0f5e6e5;hp=829beaaddc4543cc9f24c832b864d2e251440585;hpb=bdb1f12dbb7e2d72ce3a0803a0cf2626e1f821e0;p=vchess.git diff --git a/public/javascripts/components/game.js b/public/javascripts/components/game.js index 829beaad..3eb27f27 100644 --- a/public/javascripts/components/game.js +++ b/public/javascripts/components/game.js @@ -16,6 +16,7 @@ Vue.component('my-game', { seek: false, fenStart: "", incheck: [], + expert: document.cookie.length>0 ? document.cookie.substr(-1)=="1" : false, }; }, render(h) { @@ -96,6 +97,22 @@ Vue.component('my-game', { } ); elementArray.push(turnIndic); + let expertSwitch = h( + 'button', + { + on: { click: this.toggleExpertMode }, + attrs: { "aria-label": 'Toggle expert mode' }, + 'class': { + "tooltip":true, + "topindicator": true, + "indic-right": true, + "expert-switch": true, + "expert-mode": this.expert, + }, + }, + [h('i', { 'class': { "material-icons": true } }, "remove_red_eye")] + ); + elementArray.push(expertSwitch); let choices = h('div', { attrs: { "id": "choices" }, @@ -161,7 +178,7 @@ Vue.component('my-game', { ) ); } - if (hintSquares[ci][cj]) + if (!this.expert && hintSquares[ci][cj]) { elems.push( h( @@ -184,10 +201,10 @@ Vue.component('my-game', { { 'class': { 'board': true, - 'light-square': !highlight && (i+j)%2==0, - 'dark-square': !highlight && (i+j)%2==1, - 'highlight': highlight, - 'incheck': incheckSq[ci][cj], + 'light-square': (i+j)%2==0 && (this.expert || !highlight), + 'dark-square': (i+j)%2==1 && (this.expert || !highlight), + 'highlight': !this.expert && highlight, + 'incheck': !this.expert && incheckSq[ci][cj], }, attrs: { id: this.getSquareId({x:ci,y:cj}), @@ -317,10 +334,20 @@ Vue.component('my-game', { { elementArray.push( h('div', - { }, + { attrs: { id: "pgn-div" } }, [ + h('a', + { + attrs: { + id: "download", + href: "#", + } + } + ), h('p', { + attrs: { id: "pgn-game" }, + on: { click: this.download }, domProps: { innerHTML: this.vr.getPGN(this.mycolor, this.score, this.fenStart, this.mode) } @@ -453,6 +480,15 @@ Vue.component('my-game', { this.conn.onclose = socketCloseListener; }, methods: { + download: function() { + let content = document.getElementById("pgn-game").innerHTML; + content = content.replace(/
/g, "\n"); + // Prepare and trigger download link + let downloadAnchor = document.getElementById("download"); + downloadAnchor.setAttribute("download", "game.pgn"); + downloadAnchor.href = "data:text/plain;charset=utf-8," + encodeURIComponent(content); + downloadAnchor.click(); + }, endGame: function(score) { this.score = score; let modalBox = document.getElementById("modal-eog"); @@ -479,6 +515,10 @@ Vue.component('my-game', { } return eogMessage; }, + toggleExpertMode: function() { + this.expert = !this.expert; + document.cookie = "expert=" + (this.expert ? "1" : "0"); + }, resign: function() { if (this.mode == "human" && this.oppConnected) {