Explorar el Código

ungrey create game button and add game to db onclick

Martin Le Baut hace 5 años
padre
commit
931326ee7c

+ 11 - 180
package-lock.json

@@ -1275,12 +1275,6 @@
       "integrity": "sha512-78AdXtlhpCHT0K3EytMpn4JNxaf5tbqbLcbIRoQIHzpTIyjpxLQKRoxU55ujBXAtg3Nl2h/XWvfDa9dsMOd0pQ==",
       "dev": true
     },
-    "@types/tough-cookie": {
-      "version": "2.3.6",
-      "resolved": "https://registry.npmjs.org/@types/tough-cookie/-/tough-cookie-2.3.6.tgz",
-      "integrity": "sha512-wHNBMnkoEBiRAd3s8KTKwIuO9biFtTf0LehITzBhSco+HQI0xkXZbLOD55SW3Aqw3oUkHstkm5SPv58yaAdFPQ==",
-      "dev": true
-    },
     "@types/uglify-js": {
       "version": "3.0.4",
       "resolved": "https://registry.npmjs.org/@types/uglify-js/-/uglify-js-3.0.4.tgz",
@@ -1867,12 +1861,6 @@
       "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=",
       "dev": true
     },
-    "asynckit": {
-      "version": "0.4.0",
-      "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
-      "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=",
-      "dev": true
-    },
     "atob": {
       "version": "2.1.2",
       "resolved": "https://registry.npmjs.org/atob/-/atob-2.1.2.tgz",
@@ -2064,16 +2052,6 @@
       "resolved": "https://registry.npmjs.org/big.js/-/big.js-5.2.2.tgz",
       "integrity": "sha512-vyL2OymJxmarO8gxMr0mhChsO9QGwhynfuu4+MHTAW6czfq9humCB7rKpUjDd9YUiDPU4mzpyupFSvOClAwbmQ=="
     },
-    "binary": {
-      "version": "0.3.0",
-      "resolved": "https://registry.npmjs.org/binary/-/binary-0.3.0.tgz",
-      "integrity": "sha1-n2BVO8XOjDOG87VTz/R0Yq3sqnk=",
-      "dev": true,
-      "requires": {
-        "buffers": "~0.1.1",
-        "chainsaw": "~0.1.0"
-      }
-    },
     "binary-extensions": {
       "version": "1.13.1",
       "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-1.13.1.tgz",
@@ -3091,12 +3069,6 @@
       "integrity": "sha1-JuYe0UIvtw3ULm42cp7VHYVf6Nk=",
       "dev": true
     },
-    "buffers": {
-      "version": "0.1.1",
-      "resolved": "https://registry.npmjs.org/buffers/-/buffers-0.1.1.tgz",
-      "integrity": "sha1-skV5w77U1tOWru5tmorn9Ugqt7s=",
-      "dev": true
-    },
     "builtin-status-codes": {
       "version": "3.0.0",
       "resolved": "https://registry.npmjs.org/builtin-status-codes/-/builtin-status-codes-3.0.0.tgz",
@@ -3219,15 +3191,6 @@
         "type-detect": "^4.0.5"
       }
     },
-    "chainsaw": {
-      "version": "0.1.0",
-      "resolved": "https://registry.npmjs.org/chainsaw/-/chainsaw-0.1.0.tgz",
-      "integrity": "sha1-XqtQsor+WAdNDVgpE4iCi15fvJg=",
-      "dev": true,
-      "requires": {
-        "traverse": ">=0.3.0 <0.4"
-      }
-    },
     "chalk": {
       "version": "2.4.2",
       "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz",
@@ -3416,15 +3379,6 @@
         "delayed-stream": "~1.0.0"
       }
     },
-    "combined-stream": {
-      "version": "1.0.8",
-      "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
-      "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
-      "dev": true,
-      "requires": {
-        "delayed-stream": "~1.0.0"
-      }
-    },
     "commander": {
       "version": "2.20.1",
       "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.1.tgz",
@@ -4206,56 +4160,6 @@
       "integrity": "sha1-6zkTMzRYd1y4TNGh+uBiEGu4dUU=",
       "dev": true
     },
-    "decompress-zip": {
-      "version": "0.3.2",
-      "resolved": "https://registry.npmjs.org/decompress-zip/-/decompress-zip-0.3.2.tgz",
-      "integrity": "sha512-Ab1QY4LrWMrUuo53lLnmGOby7v8ryqxJ+bKibKSiPisx+25mhut1dScVBXAYx14i/PqSrFZvR2FRRazhLbvL+g==",
-      "dev": true,
-      "requires": {
-        "binary": "^0.3.0",
-        "graceful-fs": "^4.1.3",
-        "mkpath": "^0.1.0",
-        "nopt": "^3.0.1",
-        "q": "^1.1.2",
-        "readable-stream": "^1.1.8",
-        "touch": "0.0.3"
-      },
-      "dependencies": {
-        "isarray": {
-          "version": "0.0.1",
-          "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz",
-          "integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=",
-          "dev": true
-        },
-        "nopt": {
-          "version": "3.0.6",
-          "resolved": "https://registry.npmjs.org/nopt/-/nopt-3.0.6.tgz",
-          "integrity": "sha1-xkZdvwirzU2zWTF/eaxopkayj/k=",
-          "dev": true,
-          "requires": {
-            "abbrev": "1"
-          }
-        },
-        "readable-stream": {
-          "version": "1.1.14",
-          "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz",
-          "integrity": "sha1-fPTFTvZI44EwhMY23SB54WbAgdk=",
-          "dev": true,
-          "requires": {
-            "core-util-is": "~1.0.0",
-            "inherits": "~2.0.1",
-            "isarray": "0.0.1",
-            "string_decoder": "~0.10.x"
-          }
-        },
-        "string_decoder": {
-          "version": "0.10.31",
-          "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz",
-          "integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=",
-          "dev": true
-        }
-      }
-    },
     "dedent": {
       "version": "0.7.0",
       "resolved": "https://registry.npmjs.org/dedent/-/dedent-0.7.0.tgz",
@@ -5759,28 +5663,6 @@
       "integrity": "sha1-+8cfDEGt6zf5bFd60e1C2P2sypE=",
       "dev": true
     },
-    "form-data": {
-      "version": "2.3.3",
-      "resolved": "https://registry.npmjs.org/form-data/-/form-data-2.3.3.tgz",
-      "integrity": "sha512-1lLKB2Mu3aGP1Q/2eCOx0fNbRMe7XdwktwOruhfqqd0rIJWwN4Dh+E3hrPSlDCXnSR7UtZ1N38rVXm+6+MEhJQ==",
-      "dev": true,
-      "requires": {
-        "asynckit": "^0.4.0",
-        "combined-stream": "^1.0.6",
-        "mime-types": "^2.1.12"
-      }
-    },
-    "form-data": {
-      "version": "2.5.1",
-      "resolved": "https://registry.npmjs.org/form-data/-/form-data-2.5.1.tgz",
-      "integrity": "sha512-m21N3WOmEEURgk6B9GLOE4RuWOFf28Lhh9qGYeNlGq4VDXUlJy2th2slBNU8Gp8EzloYZOibZJ7t5ecIrFSjVA==",
-      "dev": true,
-      "requires": {
-        "asynckit": "^0.4.0",
-        "combined-stream": "^1.0.6",
-        "mime-types": "^2.1.12"
-      }
-    },
     "forwarded": {
       "version": "0.1.2",
       "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.2.tgz",
@@ -7051,17 +6933,6 @@
         "sshpk": "^1.7.0"
       }
     },
-    "http-signature": {
-      "version": "1.2.0",
-      "resolved": "https://registry.npmjs.org/http-signature/-/http-signature-1.2.0.tgz",
-      "integrity": "sha1-muzZJRFHcvPZW2WmCruPfBj7rOE=",
-      "dev": true,
-      "requires": {
-        "assert-plus": "^1.0.0",
-        "jsprim": "^1.2.2",
-        "sshpk": "^1.7.0"
-      }
-    },
     "https-browserify": {
       "version": "1.0.0",
       "resolved": "https://registry.npmjs.org/https-browserify/-/https-browserify-1.0.0.tgz",
@@ -8225,12 +8096,6 @@
         "minimist": "^1.2.5"
       }
     },
-    "mkpath": {
-      "version": "0.1.0",
-      "resolved": "https://registry.npmjs.org/mkpath/-/mkpath-0.1.0.tgz",
-      "integrity": "sha1-dVSm+Nhxg0zJe1RisSLEwSTW3pE=",
-      "dev": true
-    },
     "mocha": {
       "version": "7.1.1",
       "resolved": "https://registry.npmjs.org/mocha/-/mocha-7.1.1.tgz",
@@ -8529,28 +8394,6 @@
       "integrity": "sha512-iyam8fBuCUpWeKPGpaNMetEocMt364qkCsfL9JuhjXX6dRnguRVOfk2GZaDpPjcOKiiXCPINZC1GczQ7iTq3Zw==",
       "dev": true
     },
-    "ngrok": {
-      "version": "3.2.7",
-      "resolved": "https://registry.npmjs.org/ngrok/-/ngrok-3.2.7.tgz",
-      "integrity": "sha512-B7K15HM0qRZplL2aO/yfxixYubH0M50Pfu0fa4PDcmXP7RC+wyYzu6YtX77BBHHCfbwCzkObX6YdO8ThpCR6Lg==",
-      "dev": true,
-      "requires": {
-        "@types/node": "^8.10.50",
-        "@types/request": "^2.48.2",
-        "decompress-zip": "^0.3.2",
-        "request": "^2.88.0",
-        "request-promise-native": "^1.0.7",
-        "uuid": "^3.3.2"
-      },
-      "dependencies": {
-        "@types/node": {
-          "version": "8.10.59",
-          "resolved": "https://registry.npmjs.org/@types/node/-/node-8.10.59.tgz",
-          "integrity": "sha512-8RkBivJrDCyPpBXhVZcjh7cQxVBSmRk9QM7hOketZzp6Tg79c0N8kkpAIito9bnJ3HCVCHVYz+KHTEbfQNfeVQ==",
-          "dev": true
-        }
-      }
-    },
     "nice-try": {
       "version": "1.0.5",
       "resolved": "https://registry.npmjs.org/nice-try/-/nice-try-1.0.5.tgz",
@@ -9975,6 +9818,17 @@
         "uuid": "^3.3.2"
       },
       "dependencies": {
+        "form-data": {
+          "version": "2.3.3",
+          "resolved": "https://registry.npmjs.org/form-data/-/form-data-2.3.3.tgz",
+          "integrity": "sha512-1lLKB2Mu3aGP1Q/2eCOx0fNbRMe7XdwktwOruhfqqd0rIJWwN4Dh+E3hrPSlDCXnSR7UtZ1N38rVXm+6+MEhJQ==",
+          "dev": true,
+          "requires": {
+            "asynckit": "^0.4.0",
+            "combined-stream": "^1.0.6",
+            "mime-types": "^2.1.12"
+          }
+        },
         "qs": {
           "version": "6.5.2",
           "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.2.tgz",
@@ -10697,23 +10551,6 @@
         "tweetnacl": "~0.14.0"
       }
     },
-    "sshpk": {
-      "version": "1.16.1",
-      "resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.16.1.tgz",
-      "integrity": "sha512-HXXqVUq7+pcKeLqqZj6mHFUMvXtOJt1uoUx09pFW6011inTMxqI8BA8PM95myrIyyKwdnzjdFjLiE6KBPVtJIg==",
-      "dev": true,
-      "requires": {
-        "asn1": "~0.2.3",
-        "assert-plus": "^1.0.0",
-        "bcrypt-pbkdf": "^1.0.0",
-        "dashdash": "^1.12.0",
-        "ecc-jsbn": "~0.1.1",
-        "getpass": "^0.1.1",
-        "jsbn": "~0.1.0",
-        "safer-buffer": "^2.0.2",
-        "tweetnacl": "~0.14.0"
-      }
-    },
     "ssri": {
       "version": "6.0.1",
       "resolved": "https://registry.npmjs.org/ssri/-/ssri-6.0.1.tgz",
@@ -10749,12 +10586,6 @@
       "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz",
       "integrity": "sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow="
     },
-    "stealthy-require": {
-      "version": "1.1.1",
-      "resolved": "https://registry.npmjs.org/stealthy-require/-/stealthy-require-1.1.1.tgz",
-      "integrity": "sha1-NbCYdbT/SfJqd35QmzCQoyJr8ks=",
-      "dev": true
-    },
     "stream-browserify": {
       "version": "2.0.2",
       "resolved": "https://registry.npmjs.org/stream-browserify/-/stream-browserify-2.0.2.tgz",

+ 1 - 1
server/db/mariadb-connector.js

@@ -88,7 +88,7 @@ export default class MariadbConnector {
   }
 
   async addNewGame(game) {
-    console.log('mariadb add game : ', game);
+    console.log('ICIMAMENE');
     let conn;
     try {
       conn = await this.pool.getConnection();

+ 0 - 5
server/package-lock.json

@@ -2687,11 +2687,6 @@
       "resolved": "https://registry.npmjs.org/denque/-/denque-1.4.1.tgz",
       "integrity": "sha512-OfzPuSZKGcgr96rf1oODnfjqBFmr1DVoc/TrItj3Ohe0Ah1C5WX5Baquw/9U9KovnQ88EqmJbD66rKYUQYN1tQ=="
     },
-    "dotenv": {
-      "version": "8.2.0",
-      "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-8.2.0.tgz",
-      "integrity": "sha512-8sJ78ElpbDJBHNeBzUbUVLsqKdccaa/BXF1uPTw3GrvQTBgrQrtObr2mUrE38vzYd8cEv+m/JBfDLioYcfXoaw=="
-    },
     "duplexer3": {
       "version": "0.1.4",
       "resolved": "https://registry.npmjs.org/duplexer3/-/duplexer3-0.1.4.tgz",

+ 18 - 0
server/server.js

@@ -119,6 +119,24 @@ function Server() {
       callback(response);
     });
 
+    socket.on('create-game', async (game, callback) => {
+      console.log('ICINORMALEMENT');
+      let response = {};
+      try {
+        let games = await addGameDb(game);
+        response = {
+          res: "ok",
+          message: games
+        };
+      } catch (error) {
+        response = {
+          res: "ko",
+          message: 'Error from server'
+        };
+      }
+      callback(response);
+    });
+
   });
 
   let updatePlayersFromDb = async function () {

+ 5 - 5
src/assets/html/main-menu.html

@@ -375,9 +375,9 @@ border: 2px solid #f10505;
     <div id="deck-mode-select">
       <select>
         <option value="0">Select Deck mode</option>
-        <option value="1">Faction</option>
-        <option value="2">Draft</option>
-        <option value="3">Tournament</option>
+        <option value="Faction">Faction</option>
+        <option value="Draft">Draft</option>
+        <option value="Tournament">Tournament</option>
       </select>
     </div>
     <hr>
@@ -385,11 +385,11 @@ border: 2px solid #f10505;
     <div class="checkbox-div">
 
       <label class="container">Popularity
-        <input type="checkbox" id="popularity">
+        <input type="checkbox" name="popularity" id="popularity">
         <span class="checkmark"></span>
       </label>
       <label class="container">Discard for an action
-        <input type="checkbox" id="discardForAction">
+        <input type="checkbox" name="discard" id="discardForAction">
         <span class="checkmark"></span>
       </label>
     </div>

+ 15 - 0
src/common/socket-service.js

@@ -91,4 +91,19 @@ export default class SocketService {
     },
     (error) => Promise.reject(error));
   }
+
+  createGame(game){
+    return this.checkConnection(game.player1).then( () => {
+      return new Promise( (resolve, reject) => {
+        this.ioClient.emit('create-game', game, function (response) {
+          if (response.res === "ok") {
+            resolve(response.message);
+          } else {
+            reject(response.message);
+          }
+        });
+      });
+    },
+    (error) => Promise.reject(error));
+  }
 }

+ 13 - 0
src/menu/control/menu-controller.js

@@ -37,6 +37,7 @@ export default class MenuController {
       onOnlineGamesListRequested: this.onOnlineGamesListRequested.bind(this),
       onTryConnect: this.tryConnect.bind(this),
       onRequestDisconnection: this.onRequestDisconnection.bind(this),
+      onGameCreationRequest: this.onGameCreationRequest.bind(this)
     };
   }
 
@@ -50,4 +51,16 @@ export default class MenuController {
   onOnlineGamesListRequested(playername) {
     return this.socketService.getGamesList(playername);
   }
+
+  onGameCreationRequest(playername, deckModeSelected, advancedOptions) {
+    let game = {
+      player1: playername,
+      player2: "",
+      deck: deckModeSelected,
+      advRules: advancedOptions,
+      status: 'CREATED',
+      data: "",
+    };
+    return this.socketService.createGame(game);
+  }
 }

+ 0 - 7
src/menu/control/server-login.js

@@ -1,7 +0,0 @@
-'use strict';
-
-export default class ServerLogin {
-  constructor() {
-
-  }
-}

+ 6 - 1
src/menu/views/main-menu-scene.js

@@ -85,7 +85,8 @@ export default class MainMenuScene extends Phaser.Scene {
   // Listener for game creation page events
   gameCreationPageListener() {
     return {
-      onGoPreviousPage: this.onGoPreviousPage.bind(this)
+      onGoPreviousPage: this.onGoPreviousPage.bind(this),
+      onValidGameCreation: this.onValidGameCreation.bind(this),
     };
   }
 
@@ -95,6 +96,10 @@ export default class MainMenuScene extends Phaser.Scene {
     this.previousPages.pop().show();
   }
 
+  onValidGameCreation(deckModeSelected, advancedOptions) {
+    return this.menuEventListener.onGameCreationRequest(this.username, deckModeSelected, advancedOptions);
+  }
+
   // Login page specific
   onGoOnlineRoom() {
 

+ 37 - 2
src/menu/views/menu-pages/game-creation-div-page.js

@@ -6,24 +6,59 @@ export default function GameCreationDivPage(element, listener) {
   const className=GameCreationDivPage.name;
 
   let div = element.getChildByID(id);
+  let divSelectDeckMode = element.getChildByID("deck-mode-select");
   let connectButton = element.getChildByName('loginButton');
   let username = element.getChildByName('username');
   let connectionStatus = element.getChildByID('connectionStatus');
   let onlineGame = element.getChildByName('onlineGame');
+  let createGameButton = element.getChildByName('validGameCreation');
 
-  let eventListener = function(event) {
+  let deckModeSelected = null;
+  let advancedOptions = [];
+
+  let clickEventListener = function(event) {
     let eventName = event.target.name;
     switch (eventName) {
         case "backToPrev":
           listener.onGoPreviousPage(gameCreationDivPage);
           break;
 
+        case "validGameCreation":
+          console.log(deckModeSelected);
+          console.log(advancedOptions);
+          listener.onValidGameCreation(deckModeSelected, advancedOptions);
+          break;
+        case "discard":
+        case "popularity":
+          if(event.target.checked){
+            advancedOptions.push(eventName);
+          } else {
+            let index = advancedOptions.indexOf(eventName);
+            if (index !== -1){
+              advancedOptions.splice(index, 1);
+            }
+          }
+        break;
+
       default:
         break;
     }
   };
 
-  div.addEventListener('click',eventListener);
+  let changeDeckEventListener = function(event) {
+    let eventValue = event.target.value;
+    if (eventValue !== 0) {
+      createGameButton.disabled = false;
+      deckModeSelected = event.target.value;
+    } else {
+      createGameButton.disabled = true;
+      deckModeSelected = event.target.value;
+    }
+  };
+
+  div.addEventListener('click',clickEventListener);
+
+  divSelectDeckMode.addEventListener('change',changeDeckEventListener);
 
   let onShow = function() {