Code reorganization
authorBenjamin Auder <benjamin.auder@somewhere>
Tue, 29 Jan 2019 16:40:03 +0000 (17:40 +0100)
committerBenjamin Auder <benjamin.auder@somewhere>
Tue, 29 Jan 2019 16:40:03 +0000 (17:40 +0100)
62 files changed:
client/client_OLD/javascripts/components/variantSummary.js [deleted file]
client/client_OLD/javascripts/utils/array.js [deleted file]
client/client_OLD/javascripts/variant.js [deleted file]
client/client_OLD/views/app.pug [deleted file]
client/src/App.vue
client/src/base_rules.js [moved from client/client_OLD/javascripts/base_rules.js with 98% similarity]
client/src/components/Settings.vue
client/src/components/board.js [moved from client/client_OLD/javascripts/components/board.js with 98% similarity]
client/src/components/challengeList.js [moved from client/client_OLD/javascripts/components/challengeList.js with 100% similarity]
client/src/components/chat.js [moved from client/client_OLD/javascripts/components/chat.js with 100% similarity]
client/src/components/game.js [moved from client/client_OLD/javascripts/components/game.js with 100% similarity]
client/src/components/gameList.js [moved from client/client_OLD/javascripts/components/gameList.js with 100% similarity]
client/src/components/moveList.js [moved from client/client_OLD/javascripts/components/moveList.js with 100% similarity]
client/src/components/problemSummary.js [moved from client/client_OLD/javascripts/components/problemSummary.js with 100% similarity]
client/src/components/upsertUser.js [moved from client/client_OLD/javascripts/components/upsertUser.js with 100% similarity]
client/src/data/challengeCheck.js [moved from client/client_OLD/javascripts/data/challengeCheck.js with 100% similarity]
client/src/data/nbPlayers.js [moved from client/client_OLD/javascripts/data/nbPlayers.js with 100% similarity]
client/src/data/userCheck.js [moved from client/client_OLD/javascripts/data/userCheck.js with 100% similarity]
client/src/main.js
client/src/playCompMove.js [moved from client/client_OLD/javascripts/playCompMove.js with 100% similarity]
client/src/router.js
client/src/stylesheets/_users.sass [moved from client/client_OLD/stylesheets/_users.sass with 100% similarity]
client/src/stylesheets/index.sass [moved from client/client_OLD/stylesheets/index.sass with 100% similarity]
client/src/stylesheets/layout.sass [moved from client/client_OLD/stylesheets/layout.sass with 100% similarity]
client/src/stylesheets/variant.sass [moved from client/client_OLD/stylesheets/variant.sass with 100% similarity]
client/src/utils/array.js [new file with mode: 0644]
client/src/utils/datetime.js [moved from client/client_OLD/javascripts/utils/datetime.js with 82% similarity]
client/src/utils/language.js [deleted file]
client/src/utils/misc.js
client/src/utils/printDiagram.js [moved from client/client_OLD/javascripts/utils/printDiagram.js with 98% similarity]
client/src/utils/squareId.js [moved from client/client_OLD/javascripts/utils/squareId.js with 81% similarity]
client/src/utils/storage.js [moved from client/client_OLD/javascripts/utils/storage.js with 100% similarity]
client/src/variants/Alice.js [moved from client/client_OLD/javascripts/variants/Alice.js with 100% similarity]
client/src/variants/Antiking.js [moved from client/client_OLD/javascripts/variants/Antiking.js with 95% similarity]
client/src/variants/Atomic_OLD.js [moved from client/client_OLD/javascripts/variants/Atomic.js with 100% similarity]
client/src/variants/Baroque.js [moved from client/client_OLD/javascripts/variants/Baroque.js with 98% similarity]
client/src/variants/Berolina.js [moved from client/client_OLD/javascripts/variants/Berolina.js with 100% similarity]
client/src/variants/Checkered.js [moved from client/client_OLD/javascripts/variants/Checkered.js with 98% similarity]
client/src/variants/Chess960.js [moved from client/client_OLD/javascripts/variants/Chess960.js with 100% similarity]
client/src/variants/Crazyhouse.js [moved from client/client_OLD/javascripts/variants/Crazyhouse.js with 100% similarity]
client/src/variants/Dark.js [moved from client/client_OLD/javascripts/variants/Dark.js with 99% similarity]
client/src/variants/Extinction.js [moved from client/client_OLD/javascripts/variants/Extinction.js with 100% similarity]
client/src/variants/Grand.js [moved from client/client_OLD/javascripts/variants/Grand.js with 97% similarity]
client/src/variants/Losers.js [moved from client/client_OLD/javascripts/variants/Losers.js with 94% similarity]
client/src/variants/Magnetic.js [moved from client/client_OLD/javascripts/variants/Magnetic.js with 100% similarity]
client/src/variants/Marseille.js [moved from client/client_OLD/javascripts/variants/Marseille.js with 99% similarity]
client/src/variants/Switching.js [moved from client/client_OLD/javascripts/variants/Switching.js with 100% similarity]
client/src/variants/Upsidedown.js [moved from client/client_OLD/javascripts/variants/Upsidedown.js with 90% similarity]
client/src/variants/Wildebeest.js [moved from client/client_OLD/javascripts/variants/Wildebeest.js with 95% similarity]
client/src/variants/Zen.js [moved from client/client_OLD/javascripts/variants/Zen.js with 100% similarity]
client/src/views/About.vue [deleted file]
client/src/views/Game.vue [new file with mode: 0644]
client/src/views/Hall.vue [moved from client/client_OLD/javascripts/components/room.js with 95% similarity]
client/src/views/Home.vue
client/src/views/MyGames.vue [moved from client/client_OLD/javascripts/components/tabGames.js with 93% similarity]
client/src/views/Problems.vue [moved from client/client_OLD/javascripts/components/problems.js with 97% similarity]
client/src/views/Test.vue [deleted file]
client/src/views/correspondance_merge_hall.js [moved from client/client_OLD/javascripts/components/correspondance.js with 100% similarity]
client/src/views/rules.js [moved from client/client_OLD/javascripts/components/rules.js with 100% similarity]
client/src/welcome/en.pug [moved from client/src/modals/welcome/en.pug with 100% similarity]
client/src/welcome/es.pug [moved from client/src/modals/welcome/es.pug with 100% similarity]
client/src/welcome/fr.pug [moved from client/src/modals/welcome/fr.pug with 100% similarity]

diff --git a/client/client_OLD/javascripts/components/variantSummary.js b/client/client_OLD/javascripts/components/variantSummary.js
deleted file mode 100644 (file)
index 16b06ce..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-// Show a variant summary on index
-Vue.component('my-variant-summary', {
-       props: ['vobj','index'],
-       template: `
-               <div class="variant col-sm-12 col-md-5 col-lg-4" :id="vobj.name"
-                       :class="{'col-md-offset-1': index%2==0, 'col-lg-offset-2': index%2==0}">
-                       <a :href="url">
-                               <h4 class="boxtitle text-center">
-                                       {{ vobj.name }}
-                                       <span class="count-players">
-                                               / {{ vobj.count }}
-                                       </span>
-                               </h4>
-                               <p class="description text-center">
-                                       {{ translate(vobj.desc) }}
-                               </p>
-                       </a>
-               </div>
-       `,
-       computed: {
-               url: function() {
-                       return "/" + this.vobj.name;
-               },
-       },
-       methods: {
-               translate: function(text) {
-                       return translations[text];
-               },
-       },
-})
diff --git a/client/client_OLD/javascripts/utils/array.js b/client/client_OLD/javascripts/utils/array.js
deleted file mode 100644 (file)
index ab1ae10..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-// Remove item in array (if present)
-var removeItem = function(array, rfun)
-{
-       let index = array.findIndex(rfun);
-       if (index >= 0)
-               array.splice(index, 1);
-}
-
-// Remove several item matching a condition
-var removeMultiple = function(array, rfun)
-{
-       // Reverse loop because of the splice below
-       for (let i=array.length-1; i>=0; i--)
-       {
-               if (rfun(array[i]))
-                       array.splice(i, 1);
-       }
-}
-
-// Double array intialization
-var doubleArray = function(size1, size2, initElem)
-{
-       return _.map(_.range(size1), () => {
-               return _.map(_.range(size2), () => {
-                       return initElem; //can be undefined
-               })
-       });
-}
-
-var copyDoubleArray = function(arr)
-{
-       return _.map(_.range(arr.length), (el1,i) => {
-               return _.map(_.range(arr[0].length), (el2,j) => {
-                       return arr[i][j];
-               })
-       });
-}
diff --git a/client/client_OLD/javascripts/variant.js b/client/client_OLD/javascripts/variant.js
deleted file mode 100644 (file)
index c45de0a..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-new Vue({
-       el: "#VueElement",
-       data: {
-               display: "", //default to main hall; see "created()" function
-               gameRef: undefined, //...for now
-               probId: undefined,
-               conn: null,
-               mode: "analyze",
-               allowChat: false,
-               allowMovelist: true,
-               // Settings initialized with values from localStorage
-               settings:       {
-                       bcolor: localStorage["bcolor"] || "lichess",
-                       sound: parseInt(localStorage["sound"]) || 2,
-                       hints: parseInt(localStorage["hints"]) || 1,
-                       coords: !!eval(localStorage["coords"]),
-                       highlight: !!eval(localStorage["highlight"]),
-                       sqSize: parseInt(localStorage["sqSize"]),
-               },
-       },
-       created: function() {
-               window.onhashchange = this.setDisplay;
-               if (!!localStorage["variant"])
-                       location.hash = "#game?id=" + localStorage["gameId"];
-               else
-                       this.setDisplay();
-               // Our ID, always set (DB id if registered, collision-free random string otherwise)
-               this.myid = user.id || localStorage["myid"] || "anon-" + getRandString();
-               this.conn = new WebSocket(socketUrl + "/?sid=" + this.myid + "&page=" + variant.id);
-               const socketCloseListener = () => {
-                       this.conn = new WebSocket(socketUrl + "/?sid=" + this.myid + "&page=" + variant.id);
-               }
-               this.conn.onclose = socketCloseListener;
-       },
-       methods: {
-               // Game is over, clear storage and put it in indexedDB
-               archiveGame: function() {
-                       // TODO: ...
-                       //clearStorage();
-               },
-               setDisplay: function() {
-                       // Prevent set display if there is a running game
-                       if (!!localStorage["variant"])
-                               return;
-                       if (!location.hash)
-                               location.hash = "#room"; //default
-                       const hashParts = location.hash.substr(1).split("?");
-                       this.display = hashParts[0];
-                       if (hashParts[0] == "problems" && !!hashParts[1])
-                       {
-                               // Show a specific problem
-                               this.probId = hashParts[1].split("=")[1];
-                       }
-                       else if (hashParts[0] == "game" && !!hashParts[1])
-                       {
-                               // Show a specific game, maybe with a user ID
-                               const params = hashParts[1].split("&").filter(h => h.split("=")[1]);
-                               // TODO: Vue.set(...) probably required here
-                               this.gameRef = {
-                                       id: params[0],
-                                       uid: params[1], //may be undefined
-                               };
-                       }
-                       // Close menu on small screens:
-                       let menuToggle = document.getElementById("drawer-control");
-                       if (!!menuToggle)
-                               menuToggle.checked = false;
-               },
-       },
-});
diff --git a/client/client_OLD/views/app.pug b/client/client_OLD/views/app.pug
deleted file mode 100644 (file)
index 7137b19..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-doctype html
-html
-               main#VueElement
-                       my-upsert-user
-                       .container
-                                               v-bind:vobj="v" v-bind:index="idx" v-bind:key="v.name")
-                               .row(v-show="display=='correspondance'")
-                                       my-correspondance
-                               .row
-                                       my-room(v-show="display=='room'" :conn="conn" :settings="settings")
-                                       my-tab-games(v-show="display=='tabGames'")
-                                       my-rules(v-show="display=='rules'" :settings="settings")
-                                       my-problems(v-show="display=='problems'" :prob-id="probId" :settings="settings")
-                                       my-game(v-show="display=='game'" :game-ref="gameRef" :conn="conn"
-                                               :allow-chat="allowChat" :allow-movelist="allowMovelist"
-                                               :mode="mode" :settings="settings" @game-over="archiveGame")
-
-               // TODO: get rid of underscore
-               // (used essentially for _.random(), _.sample() and _.range())
-               script(src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.9.1/underscore-min.js")
-               // TODO: add only the necessary icons to mini-css custom build
-               script(src="//unpkg.com/feather-icons")
-               script(src="/javascripts/utils/printDiagram.js")
-               script(src="/javascripts/utils/datetime.js")
-               script(src="/javascripts/utils/squareId.js")
-               script(src="/javascripts/utils/misc.js")
-               script(src="/javascripts/utils/ajax.js")
-               script(src="/javascripts/utils/array.js")
-               script(src="/javascripts/shared/nbPlayers.js")
-               script(src="/javascripts/shared/challengeCheck.js")
-               script(src="/javascripts/shared/userCheck.js")
-               script(src="/javascripts/components/upsertUser.js")
-               script(src="/javascripts/components/variantSummary.js")
-               script(src="/javascripts/components/correspondance.js")
-               script(src="/javascripts/components/board.js")
-               script(src="/javascripts/components/chat.js")
-               script(src="/javascripts/components/gameList.js")
-               script(src="/javascripts/components/challengeList.js")
-               script(src="/javascripts/components/moveList.js")
-               script(src="/javascripts/components/game.js")
-               script(src="/javascripts/components/rules.js")
-               script(src="/javascripts/components/room.js")
-               script(src="/javascripts/components/tabGames.js")
-               script(src="/javascripts/components/problemSummary.js")
-               script(src="/javascripts/components/problems.js")
-               script(src="/javascripts/base_rules.js")
-               script(src="/javascripts/contactForm.js")
-               script(src="/javascripts/socket_url.js")
-               script(src="/javascripts/index.js")
-               script(src="/javascripts/variant.js")
-               script(src="/javascripts/app.js")
index 27e5582..745dd79 100644 (file)
@@ -12,7 +12,7 @@
         .col-sm-12.col-md-10.col-md-offset-1.col-lg-8.col-lg-offset-2
                                        img(src="./assets/images/index/unicorn.svg")
                                        .info-container
-                                               p vchess.club {{ $lang }}
+                                               p vchess.club
                                        img(src="./assets/images/index/wildebeest.svg")
     .row
       // Menu (top of page):
@@ -56,6 +56,9 @@
                                        a(href="https://github.com/yagu0/vchess") Source code
                                        p.clickable(onClick="doClick('modalContact')")
                                                = translations["Contact form"]
+  //my-game(:game-ref="gameRef" :mode="mode" :settings="settings" @game-over="archiveGame")
+  //// TODO: add only the necessary icons to mini-css custom build
+  //script(src="//unpkg.com/feather-icons")
 </template>
 
 <script>
similarity index 98%
rename from client/client_OLD/javascripts/base_rules.js
rename to client/src/base_rules.js
index 9f6ec9e..98c27af 100644 (file)
@@ -236,28 +236,28 @@ class ChessRules
                // Shuffle pieces on first and last rank
                for (let c of ["w","b"])
                {
-                       let positions = _.range(8);
+                       let positions = range(8);
 
                        // Get random squares for bishops
-                       let randIndex = 2 * _.random(3);
+                       let randIndex = 2 * random(4);
                        const bishop1Pos = positions[randIndex];
                        // The second bishop must be on a square of different color
-                       let randIndex_tmp = 2 * _.random(3) + 1;
+                       let randIndex_tmp = 2 * random(4) + 1;
                        const bishop2Pos = positions[randIndex_tmp];
                        // Remove chosen squares
                        positions.splice(Math.max(randIndex,randIndex_tmp), 1);
                        positions.splice(Math.min(randIndex,randIndex_tmp), 1);
 
                        // Get random squares for knights
-                       randIndex = _.random(5);
+                       randIndex = random(6);
                        const knight1Pos = positions[randIndex];
                        positions.splice(randIndex, 1);
-                       randIndex = _.random(4);
+                       randIndex = random(5);
                        const knight2Pos = positions[randIndex];
                        positions.splice(randIndex, 1);
 
                        // Get random square for queen
-                       randIndex = _.random(3);
+                       randIndex = random(4);
                        const queenPos = positions[randIndex];
                        positions.splice(randIndex, 1);
 
@@ -1132,7 +1132,7 @@ class ChessRules
                let moves1 = this.getAllValidMoves("computer");
 
                // Can I mate in 1 ? (for Magnetic & Extinction)
-               for (let i of _.shuffle(_.range(moves1.length)))
+               for (let i of shuffle(range(moves1.length)))
                {
                        this.play(moves1[i]);
                        let finish = (Math.abs(this.evalPosition()) >= V.THRESHOLD_MATE);
@@ -1190,7 +1190,7 @@ class ChessRules
                let candidates = [0]; //indices of candidates moves
                for (let j=1; j<moves1.length && moves1[j].eval == moves1[0].eval; j++)
                        candidates.push(j);
-               let currentBest = moves1[_.sample(candidates, 1)];
+               let currentBest = moves1[sample(candidates)];
 
                // From here, depth >= 3: may take a while, so we control time
                const timeStart = Date.now();
@@ -1218,7 +1218,7 @@ class ChessRules
                candidates = [0];
                for (let j=1; j<moves1.length && moves1[j].eval == moves1[0].eval; j++)
                        candidates.push(j);
-               return moves1[_.sample(candidates, 1)];
+               return moves1[sample(candidates)];
        }
 
        alphabeta(depth, alpha, beta)
index 34431a5..7aa0162 100644 (file)
@@ -7,28 +7,28 @@ div
       h3#settingsTitle.section {{ $tr["Preferences"] }}
       fieldset
         label(for="setSqSize") {{ $tr["Square size (in pixels). 0 for 'adaptative'"] }}
-        input#setSqSize(type="number" v-model="settings.sqSize")
+        input#setSqSize(type="number" v-model="$settings.sqSize")
       fieldset
         label(for="selectHints") {{ $tr["Show move hints?"] }}
-        select#setHints(v-model="settings.hints")
+        select#setHints(v-model="$settings.hints")
           option(value="0") {{ $tr["None"] }}
           option(value="1") {{ $tr["Moves from a square"] }}
           option(value="2") {{ $tr["Pieces which can move"] }}
       fieldset
         label(for="setHighlight") {{ $tr["Highlight squares? (Last move & checks)"] }}
-        input#setHighlight(type="checkbox" v-model="settings.highlight")
+        input#setHighlight(type="checkbox" v-model="$settings.highlight")
       fieldset
         label(for="setCoords") {{ $tr["Show board coordinates?"] }}
-        input#setCoords(type="checkbox" v-model="settings.coords")
+        input#setCoords(type="checkbox" v-model="$settings.coords")
       fieldset
         label(for="selectColor") {{ $tr["Board colors"] }}
-        select#setBcolor(v-model="settings.bcolor")
+        select#setBcolor(v-model="$settings.bcolor")
           option(value="lichess") {{ $tr["brown"] }}
           option(value="chesscom") {{ $tr["green"] }}
           option(value="chesstempo") {{ $tr["blue"] }}
       fieldset
         label(for="selectSound") {{ $tr["Play sounds?"] }}
-        select#setSound(v-model="settings.sound")
+        select#setSound(v-model="$settings.sound")
           option(value="0") {{ $tr["None"] }}
           option(value="1") {{ $tr["New game"] }}
           option(value="2") {{ $tr["All"] }}
@@ -37,7 +37,7 @@ div
 <script>
 export default {
   name: "Settings",
-  props: ["settings"],
+  //props: ["settings"],
        methods: {
     updateSettings: function(event) {
       const propName =
similarity index 98%
rename from client/client_OLD/javascripts/components/board.js
rename to client/src/components/board.js
index a59e41f..cd3373c 100644 (file)
@@ -78,7 +78,7 @@ Vue.component('my-board', {
                                        'clearer': true,
                                },
                        },
-                       [_.range(sizeX).map(i => {
+                       [...Array(sizeX).keys()].map(i => {
                                let ci = (this.orientation=='w' ? i : sizeX-i-1);
                                return h(
                                        'div',
@@ -88,7 +88,7 @@ Vue.component('my-board', {
                                                },
                                                style: { 'opacity': this.choices.length>0?"0.5":"1" },
                                        },
-                                       _.range(sizeY).map(j => {
+                                       [...Array(sizeY).keys()].map(j => {
                                                let cj = (this.orientation=='w' ? j : sizeY-j-1);
                                                let elems = [];
                                                if (this.vr.board[ci][cj] != V.EMPTY && (variant.name!="Dark"
@@ -140,7 +140,7 @@ Vue.component('my-board', {
                                                                        'in-shadow': variant.name=="Dark" && !this.gameOver
                                                                                && this.mode != "analyze"
                                                                                && !this.vr.enlightened[this.userColor][ci][cj],
-                                                                       'highlight': showLight && !!lm && _.isMatch(lm.end, {x:ci,y:cj}),
+                                                                       'highlight': showLight && !!lm && lm.end.x == ci && lm.end.y == cj,
                                                                        'incheck': showLight && incheckSq[ci][cj],
                                                                },
                                                                attrs: {
index 4659a5b..c48985d 100644 (file)
@@ -12,9 +12,6 @@ new Vue({
   render: function(h) {
     return h(App);
   },
-//  data: {
-//    lang: "",
-//  },
   watch: {
     $lang: async function(newLang) {
       // Fill modalWelcome, and import translations from "./translations/$lang.js"
@@ -42,11 +39,26 @@ new Vue({
                // NOTE: in this version, we don't say on which page we are, yet
                // ==> we'll say "enter/leave" page XY (in fact juste "enter", seemingly)
                Vue.prototype.$conn = new WebSocket(params.socketUrl + "/?sid=" + myid);
+               // Settings initialized with values from localStorage
+               Vue.prototype.$settings = {
+                       bcolor: localStorage["bcolor"] || "lichess",
+                       sound: parseInt(localStorage["sound"]) || 2,
+                       hints: parseInt(localStorage["hints"]) || 1,
+                       coords: !!eval(localStorage["coords"]),
+                       highlight: !!eval(localStorage["highlight"]),
+                       sqSize: parseInt(localStorage["sqSize"]),
+               };
+               const socketCloseListener = () => {
+                       Vue.prototype.$conn = new WebSocket(params.socketUrl + "/?sid=" + myid);
+               }
+               Vue.prototype.$conn.onclose = socketCloseListener;
                //TODO: si une partie en cours dans storage, rediriger vers cette partie
                //(à condition que l'URL n'y corresponde pas déjà !)
                // TODO: à l'arrivée sur le site : set peerID (un identifiant unique
                // en tout cas...) si pas trouvé dans localStorage "myid"
                // (l'identifiant de l'utilisateur si connecté)
+//             if (!!localStorage["variant"])
+//                     location.hash = "#game?id=" + localStorage["gameId"];
        },
        // Later, for icons (if using feather):
 //     mounted: function() {
@@ -66,3 +78,7 @@ new Vue({
 // problems: on-demand
 //
 // See https://router.vuejs.org/guide/essentials/dynamic-matching.html#reacting-to-params-changes
+//     created: function() {
+//             window.onhashchange = this.setDisplay;
+//     },
+//});
index 1507c8e..08bbf88 100644 (file)
@@ -31,5 +31,6 @@ export default new Router({
                        name: "test",
                        component: loadView("Test"),
                },
+    // TODO: gameRef, problemId: https://router.vuejs.org/guide/essentials/dynamic-matching.html
   ]
 });
diff --git a/client/src/utils/array.js b/client/src/utils/array.js
new file mode 100644 (file)
index 0000000..a8466c6
--- /dev/null
@@ -0,0 +1,24 @@
+// Remove item(s) in array (if present)
+export function remove(array, rfun, all)
+{
+  const index = array.findIndex(rfun);
+  if (index >= 0)
+  {
+    array.splice(index, 1);
+    if (!!all)
+    {
+      // Reverse loop because of the splice below
+      for (let i=array.length-1; i>=index; i--)
+      {
+        if (rfun(array[i]))
+          array.splice(i, 1);
+      }
+    }
+  }
+}
+
+// Double array intialization
+export function init(size1, size2, initElem)
+{
+  return [...Array(size1)].map(e => Array(size2).fill(initElem));
+}
similarity index 82%
rename from client/client_OLD/javascripts/utils/datetime.js
rename to client/src/utils/datetime.js
index 4f96518..3075bff 100644 (file)
@@ -3,12 +3,12 @@ function zeroPad(x)
        return (x<10 ? "0" : "") + x;
 }
 
-function getDate(d)
+export function getDate(d)
 {
        return d.getFullYear() + '-' + zeroPad(d.getMonth()+1) + '-' + zeroPad(d.getDate());
 }
 
-function getTime(d)
+export function getTime(d)
 {
        return zeroPad(d.getHours()) + ":" + zeroPad(d.getMinutes()) + ":" +
                zeroPad(d.getSeconds());
diff --git a/client/src/utils/language.js b/client/src/utils/language.js
deleted file mode 100644 (file)
index cff89ae..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-// TODO: adapt for client side https://stackoverflow.com/a/4079798
-// ==> Each translation file should be loaded dynamically
-// (each rules definition too, + modal welcome)
-
-// Select a language based on browser preferences, or cookie
-module.exports = function(req, res)
-{
-       // If preferred language already set:
-       if (!!req.cookies["lang"])
-               return req.cookies["lang"];
-
-       // Else: search and set it
-       const supportedLang = ["en","es","fr"];
-       const langString = req.headers["accept-language"];
-       let langArray = langString
-               .replace(/;q=[0-9.]+/g, "") //priority
-               .replace(/-[A-Z]+/g, "") //region (skipped for now...)
-               .split(",") //may have some duplicates, but removal is too costly
-       let bestLang = "en"; //default: English
-       for (let lang of langArray)
-       {
-               if (supportedLang.includes(lang))
-               {
-                       bestLang = lang;
-                       break;
-               }
-       }
-       // Cookie expires in 183 days (expressed in milliseconds)
-       res.cookie('lang', bestLang, { maxAge: 183*24*3600*1000 });
-       return bestLang;
-}
index 178f3cf..4a2abf7 100644 (file)
@@ -23,6 +23,42 @@ export const util =
     return defaut; //cookie not found
   },
 
+  random: function(min, max)
+  {
+    if (!max)
+    {
+      max = min;
+      min = 0;
+    }
+    return Math.floor(Math.random() * (max - min) ) + min;
+  },
+
+  // Inspired by https://github.com/jashkenas/underscore/blob/master/underscore.js
+  sample: function(arr, n)
+  {
+    n = n || 1;
+    let cpArr = arr.map(e => e);
+    for (let index = 0; index < n; index++)
+    {
+      const rand = getRandInt(index, n);
+      const temp = cpArr[index];
+      cpArr[index] = cpArr[rand];
+      cpArr[rand] = temp;
+    }
+    return cpArr.slice(0, n);
+  },
+
+  shuffle: function(arr)
+  {
+    return sample(arr, arr.length);
+  },
+
+  range: function(max)
+  {
+    return [...Array(max).keys()];
+  }
+
+  // TODO: rename into "cookie" et supprimer les deux ci-dessous
   // Random (enough) string for socket and game IDs
   getRandString: function()
   {
@@ -35,9 +71,4 @@ export const util =
   {
     document.getElementById(elemId).click(); //or ".checked = true"
   },
-
-  translate: function(msg)
-  {
-    return translations[msg];
-  },
 };
similarity index 98%
rename from client/client_OLD/javascripts/utils/printDiagram.js
rename to client/src/utils/printDiagram.js
index ba7b1e9..f3f77d8 100644 (file)
@@ -73,7 +73,7 @@ function getShadowArray(shadow)
 
 // args: object with position (mandatory), and
 // orientation, marks, shadow (optional)
-function getDiagram(args)
+export function getDiagram(args)
 {
        // Obtain the array of pieces images names:
        const board = V.GetBoard(args.position);
similarity index 81%
rename from client/client_OLD/javascripts/utils/squareId.js
rename to client/src/utils/squareId.js
index 8fec48e..a68b51f 100644 (file)
@@ -1,12 +1,12 @@
 // Get the identifier of a HTML square from its numeric coordinates o.x,o.y.
-function getSquareId(o)
+export function getSquareId(o)
 {
        // NOTE: a separator is required to allow any size of board
        return  "sq-" + o.x + "-" + o.y;
 }
 
 // Inverse function
-function getSquareFromId(id)
+export function getSquareFromId(id)
 {
        const idParts = id.split('-');
        return [parseInt(idParts[1]), parseInt(idParts[2])];
similarity index 95%
rename from client/client_OLD/javascripts/variants/Antiking.js
rename to client/src/variants/Antiking.js
index 66eb9f0..890da58 100644 (file)
@@ -150,25 +150,25 @@ class AntikingRules extends ChessRules
                let antikingPos = { "w": -1, "b": -1 };
                for (let c of ["w","b"])
                {
-                       let positions = _.range(8);
+                       let positions = range(8);
 
                        // Get random squares for bishops, but avoid corners; because,
                        // if an antiking blocks a cornered bishop, it can never be checkmated
-                       let randIndex = 2 * _.random(1,3);
+                       let randIndex = 2 * random(1,4);
                        const bishop1Pos = positions[randIndex];
-                       let randIndex_tmp = 2 * _.random(2) + 1;
+                       let randIndex_tmp = 2 * random(3) + 1;
                        const bishop2Pos = positions[randIndex_tmp];
                        positions.splice(Math.max(randIndex,randIndex_tmp), 1);
                        positions.splice(Math.min(randIndex,randIndex_tmp), 1);
 
-                       randIndex = _.random(5);
+                       randIndex = random(6);
                        const knight1Pos = positions[randIndex];
                        positions.splice(randIndex, 1);
-                       randIndex = _.random(4);
+                       randIndex = random(5);
                        const knight2Pos = positions[randIndex];
                        positions.splice(randIndex, 1);
 
-                       randIndex = _.random(3);
+                       randIndex = random(4);
                        const queenPos = positions[randIndex];
                        positions.splice(randIndex, 1);
 
@@ -177,7 +177,7 @@ class AntikingRules extends ChessRules
                        const rook2Pos = positions[2];
 
                        // Random squares for antikings
-                       antikingPos[c] = _.random(7);
+                       antikingPos[c] = random(8);
 
                        pieces[c][rook1Pos] = 'r';
                        pieces[c][knight1Pos] = 'n';
similarity index 98%
rename from client/client_OLD/javascripts/variants/Baroque.js
rename to client/src/variants/Baroque.js
index d06b99c..c394257 100644 (file)
@@ -548,34 +548,34 @@ class BaroqueRules extends ChessRules
                // Shuffle pieces on first and last rank
                for (let c of ["w","b"])
                {
-                       let positions = _.range(8);
+                       let positions = range(8);
                        // Get random squares for every piece, totally freely
 
-                       let randIndex = _.random(7);
+                       let randIndex = random(8);
                        const bishop1Pos = positions[randIndex];
                        positions.splice(randIndex, 1);
 
-                       randIndex = _.random(6);
+                       randIndex = random(7);
                        const bishop2Pos = positions[randIndex];
                        positions.splice(randIndex, 1);
 
-                       randIndex = _.random(5);
+                       randIndex = random(6);
                        const knight1Pos = positions[randIndex];
                        positions.splice(randIndex, 1);
 
-                       randIndex = _.random(4);
+                       randIndex = random(5);
                        const knight2Pos = positions[randIndex];
                        positions.splice(randIndex, 1);
 
-                       randIndex = _.random(3);
+                       randIndex = random(4);
                        const queenPos = positions[randIndex];
                        positions.splice(randIndex, 1);
 
-                       randIndex = _.random(2);
+                       randIndex = random(3);
                        const kingPos = positions[randIndex];
                        positions.splice(randIndex, 1);
 
-                       randIndex = _.random(1);
+                       randIndex = random(2);
                        const rookPos = positions[randIndex];
                        positions.splice(randIndex, 1);
                        const immobilizerPos = positions[0];
similarity index 98%
rename from client/client_OLD/javascripts/variants/Checkered.js
rename to client/src/variants/Checkered.js
index 9de46ff..1f6750b 100644 (file)
@@ -55,8 +55,8 @@ class CheckeredRules extends ChessRules
                super.setFlags(fenflags); //castleFlags
                this.pawnFlags =
                {
-                       "w": _.map(_.range(8), i => true), //pawns can move 2 squares?
-                       "b": _.map(_.range(8), i => true)
+                       "w": [...Array(8).fill(true)], //pawns can move 2 squares?
+                       "b": [...Array(8).fill(true)],
                };
                if (!fenflags)
                        return;
similarity index 99%
rename from client/client_OLD/javascripts/variants/Dark.js
rename to client/src/variants/Dark.js
index 3879d9d..76e9462 100644 (file)
@@ -282,6 +282,6 @@ class DarkRules extends ChessRules
                let candidates = [0];
                for (let j=1; j<moves.length && moves[j].eval == moves[0].eval; j++)
                        candidates.push(j);
-               return moves[_.sample(candidates, 1)];
+               return moves[sample(candidates)];
        }
 }
similarity index 97%
rename from client/client_OLD/javascripts/variants/Grand.js
rename to client/src/variants/Grand.js
index 6408847..c056244 100644 (file)
@@ -51,7 +51,7 @@ class GrandRules extends ChessRules
 
        getCapturedFen()
        {
-               let counts = _.map(_.range(14), 0);
+               let counts = [...Array(14).fill(0)];
                let i = 0;
                for (let j=0; j<V.PIECES.length; j++)
                {
@@ -329,38 +329,38 @@ class GrandRules extends ChessRules
                // Shuffle pieces on first and last rank
                for (let c of ["w","b"])
                {
-                       let positions = _.range(10);
+                       let positions = range(10);
 
                        // Get random squares for bishops
-                       let randIndex = 2 * _.random(4);
+                       let randIndex = 2 * random(5);
                        let bishop1Pos = positions[randIndex];
                        // The second bishop must be on a square of different color
-                       let randIndex_tmp = 2 * _.random(4) + 1;
+                       let randIndex_tmp = 2 * random(5) + 1;
                        let bishop2Pos = positions[randIndex_tmp];
                        // Remove chosen squares
                        positions.splice(Math.max(randIndex,randIndex_tmp), 1);
                        positions.splice(Math.min(randIndex,randIndex_tmp), 1);
 
                        // Get random squares for knights
-                       randIndex = _.random(7);
+                       randIndex = random(8);
                        let knight1Pos = positions[randIndex];
                        positions.splice(randIndex, 1);
-                       randIndex = _.random(6);
+                       randIndex = random(7);
                        let knight2Pos = positions[randIndex];
                        positions.splice(randIndex, 1);
 
                        // Get random square for queen
-                       randIndex = _.random(5);
+                       randIndex = random(6);
                        let queenPos = positions[randIndex];
                        positions.splice(randIndex, 1);
 
                        // ...random square for marshall
-                       randIndex = _.random(4);
+                       randIndex = random(5);
                        let marshallPos = positions[randIndex];
                        positions.splice(randIndex, 1);
 
                        // ...random square for cardinal
-                       randIndex = _.random(3);
+                       randIndex = random(4);
                        let cardinalPos = positions[randIndex];
                        positions.splice(randIndex, 1);
 
similarity index 94%
rename from client/client_OLD/javascripts/variants/Losers.js
rename to client/src/variants/Losers.js
index 33c8109..e1fb54c 100644 (file)
@@ -133,33 +133,33 @@ class LosersRules extends ChessRules
                // Shuffle pieces on first and last rank
                for (let c of ["w","b"])
                {
-                       let positions = _.range(8);
+                       let positions = range(8);
 
                        // Get random squares for bishops
-                       let randIndex = 2 * _.random(3);
+                       let randIndex = 2 * random(4);
                        let bishop1Pos = positions[randIndex];
                        // The second bishop must be on a square of different color
-                       let randIndex_tmp = 2 * _.random(3) + 1;
+                       let randIndex_tmp = 2 * random(4) + 1;
                        let bishop2Pos = positions[randIndex_tmp];
                        // Remove chosen squares
                        positions.splice(Math.max(randIndex,randIndex_tmp), 1);
                        positions.splice(Math.min(randIndex,randIndex_tmp), 1);
 
                        // Get random squares for knights
-                       randIndex = _.random(5);
+                       randIndex = random(6);
                        let knight1Pos = positions[randIndex];
                        positions.splice(randIndex, 1);
-                       randIndex = _.random(4);
+                       randIndex = random(5);
                        let knight2Pos = positions[randIndex];
                        positions.splice(randIndex, 1);
 
                        // Get random square for queen
-                       randIndex = _.random(3);
+                       randIndex = random(4);
                        let queenPos = positions[randIndex];
                        positions.splice(randIndex, 1);
 
                        // Random square for king (no castle)
-                       randIndex = _.random(2);
+                       randIndex = random(3);
                        let kingPos = positions[randIndex];
                        positions.splice(randIndex, 1);
 
similarity index 99%
rename from client/client_OLD/javascripts/variants/Marseille.js
rename to client/src/variants/Marseille.js
index 7d83bd5..2d4ecfa 100644 (file)
@@ -287,7 +287,7 @@ class MarseilleRules extends ChessRules
                        candidates.push(i);
                }
 
-               const selected = doubleMoves[_.sample(candidates, 1)].moves;
+               const selected = doubleMoves[sample(candidates)].moves;
                if (selected.length == 1)
                        return selected[0];
                return selected;
similarity index 90%
rename from client/client_OLD/javascripts/variants/Upsidedown.js
rename to client/src/variants/Upsidedown.js
index ecd1ff5..7198c0b 100644 (file)
@@ -16,9 +16,9 @@ class UpsidedownRules extends ChessRules
                let pieces = { "w": new Array(8), "b": new Array(8) };
                for (let c of ["w","b"])
                {
-                       let positions = _.range(8);
+                       let positions = range(8);
 
-                       let randIndex = _.random(7);
+                       let randIndex = random(8);
                        const kingPos = positions[randIndex];
                        positions.splice(randIndex, 1);
 
@@ -35,18 +35,18 @@ class UpsidedownRules extends ChessRules
                        positions.splice(knight1Index, 1);
 
                        // King+knight1 are on two consecutive squares: one light, one dark
-                       randIndex = 2 * _.random(2);
+                       randIndex = 2 * random(3);
                        const bishop1Pos = positions[randIndex];
-                       let randIndex_tmp = 2 * _.random(2) + 1;
+                       let randIndex_tmp = 2 * random(3) + 1;
                        const bishop2Pos = positions[randIndex_tmp];
                        positions.splice(Math.max(randIndex,randIndex_tmp), 1);
                        positions.splice(Math.min(randIndex,randIndex_tmp), 1);
 
-                       randIndex = _.random(3);
+                       randIndex = random(4);
                        const knight2Pos = positions[randIndex];
                        positions.splice(randIndex, 1);
 
-                       randIndex = _.random(2);
+                       randIndex = random(3);
                        const queenPos = positions[randIndex];
                        positions.splice(randIndex, 1);
 
similarity index 95%
rename from client/client_OLD/javascripts/variants/Wildebeest.js
rename to client/src/variants/Wildebeest.js
index cb95318..509586a 100644 (file)
@@ -231,14 +231,14 @@ class WildebeestRules extends ChessRules
                let pieces = { "w": new Array(10), "b": new Array(10) };
                for (let c of ["w","b"])
                {
-                       let positions = _.range(11);
+                       let positions = range(11);
 
                        // Get random squares for bishops + camels (different colors)
-                       let randIndexes = _.sample(_.range(6), 2).map(i => { return 2*i; });
+                       let randIndexes = sample(range(6), 2).map(i => { return 2*i; });
                        let bishop1Pos = positions[randIndexes[0]];
                        let camel1Pos = positions[randIndexes[1]];
                        // The second bishop (camel) must be on a square of different color
-                       let randIndexes_tmp = _.sample(_.range(5), 2).map(i => { return 2*i+1; });
+                       let randIndexes_tmp = sample(range(5), 2).map(i => { return 2*i+1; });
                        let bishop2Pos = positions[randIndexes_tmp[0]];
                        let camel2Pos = positions[randIndexes_tmp[1]];
                        for (let idx of randIndexes.concat(randIndexes_tmp)
@@ -247,19 +247,19 @@ class WildebeestRules extends ChessRules
                                positions.splice(idx, 1);
                        }
 
-                       let randIndex = _.random(6);
+                       let randIndex = random(7);
                        let knight1Pos = positions[randIndex];
                        positions.splice(randIndex, 1);
-                       randIndex = _.random(5);
+                       randIndex = random(6);
                        let knight2Pos = positions[randIndex];
                        positions.splice(randIndex, 1);
 
-                       randIndex = _.random(4);
+                       randIndex = random(5);
                        let queenPos = positions[randIndex];
                        positions.splice(randIndex, 1);
 
                        // Random square for wildebeest
-                       randIndex = _.random(3);
+                       randIndex = random(4);
                        let wildebeestPos = positions[randIndex];
                        positions.splice(randIndex, 1);
 
diff --git a/client/src/views/About.vue b/client/src/views/About.vue
deleted file mode 100644 (file)
index 3fa2807..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-<template>
-  <div class="about">
-    <h1>This is an about page</h1>
-  </div>
-</template>
diff --git a/client/src/views/Game.vue b/client/src/views/Game.vue
new file mode 100644 (file)
index 0000000..2c877b7
--- /dev/null
@@ -0,0 +1,12 @@
+<template>
+  <div class="about">
+    <h1>This is an about page</h1>
+  </div>
+</template>
+       methods: {
+               // Game is over, clear storage and put it in indexedDB
+               archiveGame: function() {
+                       // TODO: ...
+                       //clearStorage();
+               },
+       },
similarity index 95%
rename from client/client_OLD/javascripts/components/room.js
rename to client/src/views/Hall.vue
index fbf02ee..c1ef7eb 100644 (file)
@@ -1,3 +1,21 @@
+<template>
+  <div class="home">
+    <Home msg="Welcome to Your Vue.js Apppp"/>
+  </div>
+</template>
+
+<script>
+// @ is an alias to /src
+import HelloWorld from "@/components/HelloWorld.vue";
+
+export default {
+  name: "home",
+  components: {
+    HelloWorld,
+  }
+};
+</script>
+
 // main playing hall: chat + online players + current challenges + button "new game"
 // TODO: my-challenge-list, gérant clicks sur challenges, affichage, réception/émission des infos sur challenges ; de même, my-player-list
 // TODO: si on est en train de jouer une partie, le notifier aux nouveaux connectés
index 5b3c65e..1eaa6b1 100644 (file)
@@ -15,3 +15,34 @@ export default {
   }
 };
 </script>
+
+// Show a variant summary on index
+Vue.component('my-variant-summary', {
+       props: ['vobj','index'],
+       template: `
+               <div class="variant col-sm-12 col-md-5 col-lg-4" :id="vobj.name"
+                       :class="{'col-md-offset-1': index%2==0, 'col-lg-offset-2': index%2==0}">
+                       <a :href="url">
+                               <h4 class="boxtitle text-center">
+                                       {{ vobj.name }}
+                                       <span class="count-players">
+                                               / {{ vobj.count }}
+                                       </span>
+                               </h4>
+                               <p class="description text-center">
+                                       {{ translate(vobj.desc) }}
+                               </p>
+                       </a>
+               </div>
+       `,
+       computed: {
+               url: function() {
+                       return "/" + this.vobj.name;
+               },
+       },
+       methods: {
+               translate: function(text) {
+                       return translations[text];
+               },
+       },
+})
similarity index 93%
rename from client/client_OLD/javascripts/components/tabGames.js
rename to client/src/views/MyGames.vue
index 3861dba..5f183da 100644 (file)
@@ -1,3 +1,8 @@
+<template>
+  <div class="about">
+    <h1>This is an about page</h1>
+  </div>
+</template>
 // "My" games: tabs my archived local games, my correspondance games
 // + my imported games (of any type).
 // TODO: later, also add possibility to upload a game (parse PGN).
similarity index 97%
rename from client/client_OLD/javascripts/components/problems.js
rename to client/src/views/Problems.vue
index a955292..b7f217d 100644 (file)
@@ -1,3 +1,25 @@
+<template>
+  <div class="test">
+    <TestComp :vname="variant.name"/>
+  </div>
+</template>
+
+<script>
+// @ is an alias to /src
+import TestComp from "@/components/TestComp.vue";
+
+export default {
+  name: "test",
+  components: {
+    TestComp,
+  },
+       data: function() {
+               return {
+                       variant: {name: "Atomic", id: 3},
+               };
+       }
+};
+</script>
 Vue.component('my-problems', {
        props: ["probId","settings"],
        data: function () {
diff --git a/client/src/views/Test.vue b/client/src/views/Test.vue
deleted file mode 100644 (file)
index 707f0b7..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-<template>
-  <div class="test">
-    <TestComp :vname="variant.name"/>
-  </div>
-</template>
-
-<script>
-// @ is an alias to /src
-import TestComp from "@/components/TestComp.vue";
-
-export default {
-  name: "test",
-  components: {
-    TestComp,
-  },
-       data: function() {
-               return {
-                       variant: {name: "Atomic", id: 3},
-               };
-       }
-};
-</script>