diff --git a/.gitignore b/.gitignore index 6f92a01..91db368 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +# ---> VIM +*.swp + # ---> Node # Logs logs diff --git a/html/css/extra.css b/html/css/extra.css index 524b156..50e28b7 100644 --- a/html/css/extra.css +++ b/html/css/extra.css @@ -17,3 +17,8 @@ tr.clickable:hover{ color: #aaa; text-align: center; } + +label { + display: inline; + margin-left: 12px; +} diff --git a/html/index.html b/html/index.html index d95dc4a..cc5e75a 100644 --- a/html/index.html +++ b/html/index.html @@ -52,6 +52,11 @@ var socket = io(); // Init vars var username; var RANK_ICONS = ["🥇","🥈","🥉"]; +var config = { + categories: [], + answerPreview: true, + timer: 60, +}; // Init listeners @@ -72,6 +77,9 @@ socket.on("LOBBY", function(users){ page += "
  • "+users[i]+"
  • "; } page += ""; + + // Config area + page += "
    "; document.getElementById("main").innerHTML = page; @@ -88,6 +96,81 @@ socket.on("LOBBY", function(users){ if(users.length < 2){ document.getElementById("button_lobby_start").style.display = "none"; } + + reconstructConfig(); +}); + +// CONFIG +function updateConfig(){ + // Create new config from inputs + c = { + categories: [], + timer: 60, + answerPreview: true, + } + + // Get categories + for(var i=0; i"; + page += ""; + + page += "
    "; + + page += "
    "; + page += "
    Answer Preview
    "; + page += "

    Whether to display one of the possible answers to a question while writing false answers. This may help with formatting of the false answers.

    "; + page += ""; + page += ""; + page += ""; + page += ""; + page += "
    "; + + page += "
    "; + + page += "
    "; + page += "
    Categories
    "; + for(var i=0; i"; + page += ""; + page += ""; + page += "
    "; + } + page += "
    "; + + document.getElementById("config").innerHTML = page; +} + +socket.on("CONFIG", function(data){ + config = data.config; + reconstructConfig(); }); // LOBBY_CLOSED diff --git a/main.js b/main.js index b481d05..0a63433 100644 --- a/main.js +++ b/main.js @@ -25,8 +25,8 @@ const util = require("util"); const fetch = require("node-fetch"); // Vars -const hostname = "192.168.0.128"; // Enter your local IP address here -const port = 3000; // Enter a port number here +const hostname = "127.0.0.1"; // Enter your local IP address here +const port = 5000; // Enter a port number here const STATE_LOBBY = 0; const STATE_MANUAL = 10; @@ -45,13 +45,44 @@ var questionsTotal = 10; // Total nr of questions var questionData = {}; var questionCorrectAnswerIndex; var answers; -const QUESTION_CATEGORIES = [9,15,16,17,18,19,20,22,23,27,28,30]; +const QUESTION_CATEGORIES = [9,15,16,17,18,19,20,22,23,27,28,30]; // Default enabled categories var userWrite = []; var userPick = []; var userPoints = []; +var config = { + categories: [], // Filled in later + answerPreview: true, + timer: 60, +}; +// Get question categories +function isCategoryEnabledByDefault(id){ + return QUESTION_CATEGORIES.includes(id); +} +fetch("https://opentdb.com/api_category.php") + .then(res => res.json()) // Convert to JSON + .then(json => { + // Question loaded + console.log("Fetched question categories from OpenTDB"); + console.log(json); + + // TODO: check response code + + // Save data + var cats = []; + for(var i=0; i { @@ -120,12 +151,26 @@ io.on("connection", (socket) => { // Send lobby data userSockets.forEach(function(s){s.emit("LOBBY", userNames);}); + // Send config to new user + socket.emit("CONFIG", {config: config}); + }else{ // When can't enter socket.emit("LOBBY_CLOSED"); } }); + // CONFIG + socket.on("CONFIG", (data) => { + console.log("CONFIG request"); + + // Update server config + config = data.config; + + // Send new config to all users + userSockets.forEach(function(s){s.emit("CONFIG", {config: config});}); + }); + // START socket.on("START", () => { console.log("START request"); diff --git a/package-lock.json b/package-lock.json index cfd5679..0116f9f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,5 @@ { - "name": "Psych", + "name": "ReverseQuiz", "lockfileVersion": 2, "requires": true, "packages": {