From 4f51861013271a060b358884097a676e3d42d496 Mon Sep 17 00:00:00 2001
From: Benjamin Auder <benjamin.auder@somewhere>
Date: Mon, 3 Feb 2020 09:13:56 +0100
Subject: [PATCH] 'update'

---
 client/src/components/BaseGame.vue | 31 ++++++++++++++++++++----------
 client/src/main.js                 |  2 +-
 client/src/variants/Dark.js        | 20 ++++++++++---------
 client/src/views/Game.vue          |  3 +--
 client/src/views/Hall.vue          |  6 ------
 client/src/views/Rules.vue         |  4 ++--
 6 files changed, 36 insertions(+), 30 deletions(-)

diff --git a/client/src/components/BaseGame.vue b/client/src/components/BaseGame.vue
index dd8c5c86..07343c5a 100644
--- a/client/src/components/BaseGame.vue
+++ b/client/src/components/BaseGame.vue
@@ -8,10 +8,10 @@ div#baseGame(tabindex=-1 @click="() => focusBg()"
       h3#eogMessage.section {{ endgameMessage }}
   #gameContainer
     #boardContainer
-      Board(:vr="vr" :last-move="lastMove" :analyze="game.mode=='analyze'"
+      Board(:vr="vr" :last-move="lastMove" :analyze="analyze"
         :user-color="game.mycolor" :orientation="orientation"
         :vname="game.vname" @play-move="play")
-      #turnIndicator(v-if="game.vname=='Dark' && game.mode!='analyze'")
+      #turnIndicator(v-if="game.vname=='Dark' && game.score=='*'")
         | {{ turn }}
       #controls
         button(@click="gotoBegin") <<
@@ -20,12 +20,15 @@ div#baseGame(tabindex=-1 @click="() => focusBg()"
         button(@click="() => play()") >
         button(@click="gotoEnd") >>
       #pgnDiv
-        a#download(href="#")
-        button(@click="download") {{ st.tr["Download PGN"] }}
+        div(v-if="game.vname!='Dark' || game.score!='*'")
+          a#download(href="#")
+          button(@click="download") {{ st.tr["Download PGN"] }}
         button(v-if="game.vname!='Dark' && game.mode!='analyze'"
             @click="analyzePosition")
           | {{ st.tr["Analyze"] }}
-        button(@click="showRules") {{ st.tr["Rules"] }}
+        // NOTE: rather ugly hack to avoid showing twice "rules" link...
+        button(v-if="!$route.path.match('/variants/')" @click="showRules")
+          | {{ st.tr["Rules"] }}
     #movesList
       MoveList(v-if="showMoves" :score="game.score" :message="game.scoreMsg"
         :firstNum="firstMoveNumber" :moves="moves" :cursor="cursor"
@@ -74,7 +77,7 @@ export default {
   },
   computed: {
     showMoves: function() {
-      return this.game.vname != "Dark" || this.game.mode=="analyze";
+      return this.game.vname != "Dark" || this.game.score != "*";
     },
     turn: function() {
       let color = "";
@@ -85,6 +88,11 @@ export default {
         color = "Black";
       return color + " turn";
     },
+    analyze: function() {
+      return this.game.mode=="analyze" ||
+        // From Board viewpoint, a finished Dark game == analyze (TODO: unclear)
+        (this.game.vname == "Dark" && this.game.score != "*");
+    },
   },
   created: function() {
     if (!!this.game.fenStart)
@@ -132,7 +140,8 @@ export default {
       }
     },
     handleScroll: function(e) {
-      if (this.game.mode == "analyze" || this.game.score != "*")
+      // NOTE: since game.mode=="analyze" => no score, next condition is enough
+      if (this.game.score != "*")
       {
         e.preventDefault();
         if (e.deltaY < 0)
@@ -272,7 +281,7 @@ export default {
       // Forbid playing outside analyze mode, except if move is received.
       // Sufficient condition because Board already knows which turn it is.
       if (!navigate && this.game.mode!="analyze" && !receive
-        && this.cursor < this.moves.length-1)
+        && (this.game.score != "*" || this.cursor < this.moves.length-1))
       {
         return;
       }
@@ -304,8 +313,6 @@ export default {
           else
             this.moves = this.moves.slice(0,this.cursor).concat([move]);
         }
-        if (!navigate && this.game.mode!="analyze")
-          this.$emit("newmove", move); //post-processing (e.g. computer play)
         // Is opponent in check?
         this.incheck = this.vr.getCheckSquares(this.vr.turn);
         const score = this.vr.getCurrentScore();
@@ -317,6 +324,8 @@ export default {
           else //just show score on screen (allow undo)
             this.showEndgameMsg(score + " . " + message);
         }
+        if (!navigate && this.game.mode!="analyze")
+          this.$emit("newmove", move); //post-processing (e.g. computer play)
       };
       if (!!receive && this.game.vname != "Dark")
         this.animateMove(move, doPlayMove);
@@ -375,6 +384,8 @@ export default {
 <style lang="sass" scoped>
 #baseGame
   width: 100%
+  &:focus
+    outline: none
 
 #gameContainer
   margin-left: auto
diff --git a/client/src/main.js b/client/src/main.js
index 6e229362..7015362b 100644
--- a/client/src/main.js
+++ b/client/src/main.js
@@ -22,7 +22,7 @@ new Vue({
         });
       }
     });
-    // TODO: why is this wrong?
+    // TODO: why is this wrong? (Maybe because $route still uninitialized?)
     //store.initialize(this.$route.path);
     store.initialize(window.location.href.split("#")[1]);
     // NOTE: at this point, variants and tr(anslations) might be uninitialized
diff --git a/client/src/variants/Dark.js b/client/src/variants/Dark.js
index 777aacc8..bc14cfa3 100644
--- a/client/src/variants/Dark.js
+++ b/client/src/variants/Dark.js
@@ -104,11 +104,11 @@ export const VariantRules = class DarkRules extends ChessRules
 		super.updateVariables(move);
 		if (move.vanish.length >= 2 && move.vanish[1].p == V.KING)
 		{
-			// We took opponent king !
+			// We took opponent king ! (because if castle vanish[1] is a rook)
 			this.kingPos[this.turn] = [-1,-1];
 		}
 
-		// Update moves for both colors:
+		// Update lights for both colors:
 		this.updateEnlightened();
 	}
 
@@ -130,7 +130,7 @@ export const VariantRules = class DarkRules extends ChessRules
 			}
 		}
 
-		// Update moves for both colors:
+		// Update lights for both colors:
 		this.updateEnlightened();
 	}
 
@@ -157,7 +157,6 @@ export const VariantRules = class DarkRules extends ChessRules
 		const color = this.turn;
 		const oppCol = V.GetOppCol(color);
 		const pawnShift = (color == "w" ? -1 : 1);
-		const kp = this.kingPos[color];
 
 		// Do not cheat: the current enlightment is all we can see
 		const myLight = JSON.parse(JSON.stringify(this.enlightened[color]));
@@ -165,6 +164,7 @@ export const VariantRules = class DarkRules extends ChessRules
 		// Can a slider on (i,j) apparently take my king?
 		// NOTE: inaccurate because assume yes if some squares are shadowed
 		const sliderTake = ([i,j], piece) => {
+		  const kp = this.kingPos[color];
 			let step = undefined;
 			if (piece == V.BISHOP)
 			{
@@ -189,10 +189,10 @@ export const VariantRules = class DarkRules extends ChessRules
 			// Check for obstacles
 			let obstacle = false;
 			for (
-				let x=kp[0]+step[0], y=kp[1]+step[1];
-				x != i && y != j;
-				x += step[0], y+= step[1])
-			{
+        let x=kp[0]+step[0], y=kp[1]+step[1];
+			  x != i && y != j;
+				x += step[0], y += step[1])
+      {
 				if (myLight[x][y] && this.board[x][y] != V.EMPTY)
 				{
 					obstacle = true;
@@ -206,6 +206,7 @@ export const VariantRules = class DarkRules extends ChessRules
 
 		// Do I see something which can take my king ?
 		const kingThreats = () => {
+		  const kp = this.kingPos[color];
 			for (let i=0; i<V.size.x; i++)
 			{
 				for (let j=0; j<V.size.y; j++)
@@ -259,7 +260,8 @@ export const VariantRules = class DarkRules extends ChessRules
 				move.eval = -maxeval;
 			}
 			this.undo(move);
-			if (!!move.eval)
+
+      if (!!move.eval)
 				continue;
 
 			move.eval = 0; //a priori...
diff --git a/client/src/views/Game.vue b/client/src/views/Game.vue
index 8f9b946a..c0c50318 100644
--- a/client/src/views/Game.vue
+++ b/client/src/views/Game.vue
@@ -10,7 +10,7 @@ main
   .row
     #aboveBoard.col-sm-12.col-md-9.col-md-offset-3.col-lg-10.col-lg-offset-2
       button#chatBtn(onClick="doClick('modalChat')") Chat
-      #actions(v-if="game.mode!='analyze' && game.score=='*'")
+      #actions(v-if="game.score=='*'")
         button(@click="clickDraw" :class="{['draw-' + drawOffer]: true}") Draw
         button(@click="abortGame") Abort
         button(@click="resign") Resign
@@ -560,7 +560,6 @@ export default {
         document.getElementById("chatBtn").style.backgroundColor = "#c5fefe";
     },
     gameOver: function(score, scoreMsg) {
-      this.game.mode = "analyze";
       this.game.score = score;
       this.game.scoreMsg = scoreMsg;
       const myIdx = this.game.players.findIndex(p => {
diff --git a/client/src/views/Hall.vue b/client/src/views/Hall.vue
index 2df03e6e..0bc037a7 100644
--- a/client/src/views/Hall.vue
+++ b/client/src/views/Hall.vue
@@ -32,8 +32,6 @@ main
   .row
     .col-sm-12.col-md-10.col-md-offset-1.col-lg-8.col-lg-offset-2
       .collapse
-        input#challengeSection(type="radio" checked aria-hidden="true" name="accordion")
-        label(for="challengeSection" aria-hidden="true") Challenges
         div
           .button-group
             button(@click="cdisplay='live'") Live Challenges
@@ -42,8 +40,6 @@ main
             :challenges="filterChallenges('live')" @click-challenge="clickChallenge")
           ChallengeList(v-show="cdisplay=='corr'"
             :challenges="filterChallenges('corr')" @click-challenge="clickChallenge")
-        input#peopleSection(type="radio" aria-hidden="true" name="accordion")
-        label(for="peopleSection" aria-hidden="true") People
         div
           .button-group
             button(@click="pdisplay='players'") Players
@@ -57,8 +53,6 @@ main
                 | {{ whatPlayerDoes(p) }}
           #chat(v-show="pdisplay=='chat'")
             Chat(:players="[]")
-        input#gameSection(type="radio" aria-hidden="true" name="accordion")
-        label(for="gameSection" aria-hidden="true") Games
         div
           .button-group
             button(@click="gdisplay='live'") Live games
diff --git a/client/src/views/Rules.vue b/client/src/views/Rules.vue
index 25416612..a3331d7d 100644
--- a/client/src/views/Rules.vue
+++ b/client/src/views/Rules.vue
@@ -10,7 +10,8 @@ main
           | Practice
         button(v-show="gameInProgress" @click="() => stopGame()")
           | Stop game
-        button(v-if="gameInfo.vname!='Dark'" @click="gotoAnalyze")
+        button(v-if="display=='rules' && gameInfo.vname!='Dark'"
+            @click="gotoAnalyze")
           | {{ st.tr["Analyze"] }}
       .section-content(v-show="display=='rules'" v-html="content")
   ComputerGame(v-show="display=='computer'" :game-info="gameInfo"
@@ -98,7 +99,6 @@ export default {
     // user is willing to stop the game:
     stopGame: function(score) {
       this.gameInfo.score = score || "?";
-      this.gameInfo.mode = "analyze";
     },
     // The game is effectively stopped:
     gameStopped: function() {
-- 
2.44.0