From 8d61fc4ab7373b4a576f3f9108cdf7768ae27096 Mon Sep 17 00:00:00 2001 From: Benjamin Auder Date: Tue, 29 Jan 2019 17:40:03 +0100 Subject: [PATCH] Code reorganization --- .../javascripts/components/variantSummary.js | 30 -------- client/client_OLD/javascripts/utils/array.js | 37 ---------- client/client_OLD/javascripts/variant.js | 70 ------------------- client/client_OLD/views/app.pug | 51 -------------- client/src/App.vue | 5 +- .../javascripts => src}/base_rules.js | 18 ++--- client/src/components/Settings.vue | 14 ++-- .../javascripts => src}/components/board.js | 6 +- .../components/challengeList.js | 0 .../javascripts => src}/components/chat.js | 0 .../javascripts => src}/components/game.js | 0 .../components/gameList.js | 0 .../components/moveList.js | 0 .../components/problemSummary.js | 0 .../components/upsertUser.js | 0 .../data/challengeCheck.js | 0 .../javascripts => src}/data/nbPlayers.js | 0 .../javascripts => src}/data/userCheck.js | 0 client/src/main.js | 22 +++++- .../javascripts => src}/playCompMove.js | 0 client/src/router.js | 1 + .../stylesheets/_users.sass | 0 .../stylesheets/index.sass | 0 .../stylesheets/layout.sass | 0 .../stylesheets/variant.sass | 0 client/src/utils/array.js | 24 +++++++ .../javascripts => src}/utils/datetime.js | 4 +- client/src/utils/language.js | 31 -------- client/src/utils/misc.js | 41 +++++++++-- .../javascripts => src}/utils/printDiagram.js | 2 +- .../javascripts => src}/utils/squareId.js | 4 +- .../javascripts => src}/utils/storage.js | 0 .../javascripts => src}/variants/Alice.js | 0 .../javascripts => src}/variants/Antiking.js | 14 ++-- .../Atomic.js => src/variants/Atomic_OLD.js} | 0 .../javascripts => src}/variants/Baroque.js | 16 ++--- .../javascripts => src}/variants/Berolina.js | 0 .../javascripts => src}/variants/Checkered.js | 4 +- .../javascripts => src}/variants/Chess960.js | 0 .../variants/Crazyhouse.js | 0 .../javascripts => src}/variants/Dark.js | 2 +- .../variants/Extinction.js | 0 .../javascripts => src}/variants/Grand.js | 18 ++--- .../javascripts => src}/variants/Losers.js | 14 ++-- .../javascripts => src}/variants/Magnetic.js | 0 .../javascripts => src}/variants/Marseille.js | 2 +- .../javascripts => src}/variants/Switching.js | 0 .../variants/Upsidedown.js | 12 ++-- .../variants/Wildebeest.js | 14 ++-- .../javascripts => src}/variants/Zen.js | 0 client/src/views/About.vue | 5 -- client/src/views/Game.vue | 12 ++++ .../components/room.js => src/views/Hall.vue} | 18 +++++ client/src/views/Home.vue | 31 ++++++++ .../tabGames.js => src/views/MyGames.vue} | 5 ++ .../problems.js => src/views/Problems.vue} | 22 ++++++ client/src/views/Test.vue | 22 ------ .../views/correspondance_merge_hall.js} | 0 .../components => src/views}/rules.js | 0 client/src/{modals => }/welcome/en.pug | 0 client/src/{modals => }/welcome/es.pug | 0 client/src/{modals => }/welcome/fr.pug | 0 62 files changed, 244 insertions(+), 327 deletions(-) delete mode 100644 client/client_OLD/javascripts/components/variantSummary.js delete mode 100644 client/client_OLD/javascripts/utils/array.js delete mode 100644 client/client_OLD/javascripts/variant.js delete mode 100644 client/client_OLD/views/app.pug rename client/{client_OLD/javascripts => src}/base_rules.js (98%) rename client/{client_OLD/javascripts => src}/components/board.js (98%) rename client/{client_OLD/javascripts => src}/components/challengeList.js (100%) rename client/{client_OLD/javascripts => src}/components/chat.js (100%) rename client/{client_OLD/javascripts => src}/components/game.js (100%) rename client/{client_OLD/javascripts => src}/components/gameList.js (100%) rename client/{client_OLD/javascripts => src}/components/moveList.js (100%) rename client/{client_OLD/javascripts => src}/components/problemSummary.js (100%) rename client/{client_OLD/javascripts => src}/components/upsertUser.js (100%) rename client/{client_OLD/javascripts => src}/data/challengeCheck.js (100%) rename client/{client_OLD/javascripts => src}/data/nbPlayers.js (100%) rename client/{client_OLD/javascripts => src}/data/userCheck.js (100%) rename client/{client_OLD/javascripts => src}/playCompMove.js (100%) rename client/{client_OLD => src}/stylesheets/_users.sass (100%) rename client/{client_OLD => src}/stylesheets/index.sass (100%) rename client/{client_OLD => src}/stylesheets/layout.sass (100%) rename client/{client_OLD => src}/stylesheets/variant.sass (100%) create mode 100644 client/src/utils/array.js rename client/{client_OLD/javascripts => src}/utils/datetime.js (82%) delete mode 100644 client/src/utils/language.js rename client/{client_OLD/javascripts => src}/utils/printDiagram.js (98%) rename client/{client_OLD/javascripts => src}/utils/squareId.js (81%) rename client/{client_OLD/javascripts => src}/utils/storage.js (100%) rename client/{client_OLD/javascripts => src}/variants/Alice.js (100%) rename client/{client_OLD/javascripts => src}/variants/Antiking.js (95%) rename client/{client_OLD/javascripts/variants/Atomic.js => src/variants/Atomic_OLD.js} (100%) rename client/{client_OLD/javascripts => src}/variants/Baroque.js (98%) rename client/{client_OLD/javascripts => src}/variants/Berolina.js (100%) rename client/{client_OLD/javascripts => src}/variants/Checkered.js (98%) rename client/{client_OLD/javascripts => src}/variants/Chess960.js (100%) rename client/{client_OLD/javascripts => src}/variants/Crazyhouse.js (100%) rename client/{client_OLD/javascripts => src}/variants/Dark.js (99%) rename client/{client_OLD/javascripts => src}/variants/Extinction.js (100%) rename client/{client_OLD/javascripts => src}/variants/Grand.js (97%) rename client/{client_OLD/javascripts => src}/variants/Losers.js (94%) rename client/{client_OLD/javascripts => src}/variants/Magnetic.js (100%) rename client/{client_OLD/javascripts => src}/variants/Marseille.js (99%) rename client/{client_OLD/javascripts => src}/variants/Switching.js (100%) rename client/{client_OLD/javascripts => src}/variants/Upsidedown.js (90%) rename client/{client_OLD/javascripts => src}/variants/Wildebeest.js (95%) rename client/{client_OLD/javascripts => src}/variants/Zen.js (100%) delete mode 100644 client/src/views/About.vue create mode 100644 client/src/views/Game.vue rename client/{client_OLD/javascripts/components/room.js => src/views/Hall.vue} (95%) rename client/{client_OLD/javascripts/components/tabGames.js => src/views/MyGames.vue} (93%) rename client/{client_OLD/javascripts/components/problems.js => src/views/Problems.vue} (97%) delete mode 100644 client/src/views/Test.vue rename client/{client_OLD/javascripts/components/correspondance.js => src/views/correspondance_merge_hall.js} (100%) rename client/{client_OLD/javascripts/components => src/views}/rules.js (100%) rename client/src/{modals => }/welcome/en.pug (100%) rename client/src/{modals => }/welcome/es.pug (100%) rename client/src/{modals => }/welcome/fr.pug (100%) diff --git a/client/client_OLD/javascripts/components/variantSummary.js b/client/client_OLD/javascripts/components/variantSummary.js deleted file mode 100644 index 16b06ce4..00000000 --- a/client/client_OLD/javascripts/components/variantSummary.js +++ /dev/null @@ -1,30 +0,0 @@ -// Show a variant summary on index -Vue.component('my-variant-summary', { - props: ['vobj','index'], - template: ` -
- -

- {{ vobj.name }} - - / {{ vobj.count }} - -

-

- {{ translate(vobj.desc) }} -

-
-
- `, - 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 index ab1ae10d..00000000 --- a/client/client_OLD/javascripts/utils/array.js +++ /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 index c45de0ac..00000000 --- a/client/client_OLD/javascripts/variant.js +++ /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 index 7137b191..00000000 --- a/client/client_OLD/views/app.pug +++ /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") diff --git a/client/src/App.vue b/client/src/App.vue index 27e5582a..745dd799 100644 --- a/client/src/App.vue +++ b/client/src/App.vue @@ -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") + // 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 diff --git a/client/src/views/Home.vue b/client/src/views/Home.vue index 5b3c65e9..1eaa6b17 100644 --- a/client/src/views/Home.vue +++ b/client/src/views/Home.vue @@ -15,3 +15,34 @@ export default { } }; + +// Show a variant summary on index +Vue.component('my-variant-summary', { + props: ['vobj','index'], + template: ` +
+ +

+ {{ vobj.name }} + + / {{ vobj.count }} + +

+

+ {{ translate(vobj.desc) }} +

+
+
+ `, + computed: { + url: function() { + return "/" + this.vobj.name; + }, + }, + methods: { + translate: function(text) { + return translations[text]; + }, + }, +}) diff --git a/client/client_OLD/javascripts/components/tabGames.js b/client/src/views/MyGames.vue similarity index 93% rename from client/client_OLD/javascripts/components/tabGames.js rename to client/src/views/MyGames.vue index 3861dbac..5f183da1 100644 --- a/client/client_OLD/javascripts/components/tabGames.js +++ b/client/src/views/MyGames.vue @@ -1,3 +1,8 @@ + // "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). diff --git a/client/client_OLD/javascripts/components/problems.js b/client/src/views/Problems.vue similarity index 97% rename from client/client_OLD/javascripts/components/problems.js rename to client/src/views/Problems.vue index a9552923..b7f217d0 100644 --- a/client/client_OLD/javascripts/components/problems.js +++ b/client/src/views/Problems.vue @@ -1,3 +1,25 @@ + + + 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 index 707f0b70..00000000 --- a/client/src/views/Test.vue +++ /dev/null @@ -1,22 +0,0 @@ - - - diff --git a/client/client_OLD/javascripts/components/correspondance.js b/client/src/views/correspondance_merge_hall.js similarity index 100% rename from client/client_OLD/javascripts/components/correspondance.js rename to client/src/views/correspondance_merge_hall.js diff --git a/client/client_OLD/javascripts/components/rules.js b/client/src/views/rules.js similarity index 100% rename from client/client_OLD/javascripts/components/rules.js rename to client/src/views/rules.js diff --git a/client/src/modals/welcome/en.pug b/client/src/welcome/en.pug similarity index 100% rename from client/src/modals/welcome/en.pug rename to client/src/welcome/en.pug diff --git a/client/src/modals/welcome/es.pug b/client/src/welcome/es.pug similarity index 100% rename from client/src/modals/welcome/es.pug rename to client/src/welcome/es.pug diff --git a/client/src/modals/welcome/fr.pug b/client/src/welcome/fr.pug similarity index 100% rename from client/src/modals/welcome/fr.pug rename to client/src/welcome/fr.pug -- 2.44.0