updated category selection logic
This commit is contained in:
parent
43186ddc9c
commit
99af47d017
13
main.js
13
main.js
|
@ -56,6 +56,7 @@ var config = {
|
|||
answerPreview: true,
|
||||
timer: 60,
|
||||
};
|
||||
var enabledCategories = [];
|
||||
|
||||
// Get question categories
|
||||
function isCategoryEnabledByDefault(id){
|
||||
|
@ -188,6 +189,14 @@ io.on("connection", (socket) => {
|
|||
userPoints.push(0);
|
||||
}
|
||||
|
||||
enabledCategories = [];
|
||||
for(var i=0; i<config.categories.length; i++){
|
||||
if(config.categories[i].enabled){
|
||||
enabledCategories.push(config.categories[i].id);
|
||||
}
|
||||
}
|
||||
enabledCategories.sort(() => rand(0, 100));
|
||||
|
||||
// Send game data
|
||||
var dataUser = {usernames:userNames, questionsTotal:questionsTotal};
|
||||
for(i=0; i<userSockets.length; i++){
|
||||
|
@ -325,7 +334,9 @@ function next(){
|
|||
}else{
|
||||
// Load new question
|
||||
console.log("Loading new question...");
|
||||
var category = QUESTION_CATEGORIES[rand(0, QUESTION_CATEGORIES.length)];
|
||||
|
||||
var category = enabledCategories[questionNr % enabledCategories.length];
|
||||
|
||||
fetch("https://opentdb.com/api.php?amount=1&type=multiple&category="+category)
|
||||
.then(res => res.json()) // Convert to JSON
|
||||
.then(json => {
|
||||
|
|
Loading…
Reference in New Issue