'update'
authorBenjamin Auder <benjamin.auder@somewhere>
Mon, 3 Feb 2020 08:13:56 +0000 (09:13 +0100)
committerBenjamin Auder <benjamin.auder@somewhere>
Mon, 3 Feb 2020 08:13:56 +0000 (09:13 +0100)
client/src/components/BaseGame.vue
client/src/main.js
client/src/variants/Dark.js
client/src/views/Game.vue
client/src/views/Hall.vue
client/src/views/Rules.vue

index dd8c5c8..07343c5 100644 (file)
@@ -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
index 6e22936..7015362 100644 (file)
@@ -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
index 777aacc..bc14cfa 100644 (file)
@@ -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...
index 8f9b946..c0c5031 100644 (file)
@@ -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 => {
index 2df03e6..0bc037a 100644 (file)
@@ -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
index 2541661..a3331d7 100644 (file)
@@ -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() {