From: Benjamin Auder Date: Tue, 29 Jan 2019 16:40:03 +0000 (+0100) Subject: Code reorganization X-Git-Url: https://git.auder.net/variants/current/css/rpsls.css?a=commitdiff_plain;h=8d61fc4ab7373b4a576f3f9108cdf7768ae27096;p=vchess.git Code reorganization --- 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