From 9287a9f30af221670b844101e846840cfad3a966 Mon Sep 17 00:00:00 2001 From: SIMAILA Djalim Date: Mon, 16 Jan 2023 08:53:56 +0100 Subject: [PATCH 1/3] lobby redirect to / if no gameid was given --- truthseeker/routes/routes_ui.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/truthseeker/routes/routes_ui.py b/truthseeker/routes/routes_ui.py index 2e5d7d9..c32316d 100644 --- a/truthseeker/routes/routes_ui.py +++ b/truthseeker/routes/routes_ui.py @@ -22,10 +22,17 @@ def licenses(): def legal(): return flask.render_template("legal.html") +@routes_ui.route("/lobby") +def lobbyRedirect(): + return flask.redirect("/") + @routes_ui.route("/lobby/") def lobby(game_id): # rendered by the javascript client-side + print(game_id) + if game_id is None: + return flask.redirect("") return flask.render_template("lobby.html", gameid=game_id) From 2147dc7a9e0a6c05fbeffe4a9457c414e2789b2b Mon Sep 17 00:00:00 2001 From: SIMAILA Djalim Date: Mon, 16 Jan 2023 08:59:30 +0100 Subject: [PATCH 2/3] can no longer ask other questions while one is displayed --- truthseeker/static/js/game.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/truthseeker/static/js/game.js b/truthseeker/static/js/game.js index 4b353a6..c5b4b20 100644 --- a/truthseeker/static/js/game.js +++ b/truthseeker/static/js/game.js @@ -30,6 +30,11 @@ function setQuestionButtonsListeners(){ document.getElementById("QA_1").addEventListener("click",askTypeOneQuestion); } +function removeQuestionButtonsListeners(){ + document.getElementById("QA_0").removeEventListener("click",askTypeZeroQuestion); + document.getElementById("QA_1").removeEventListener("click",askTypeOneQuestion); +} + function goBackToInterogation(){ hide("interrogation_suspect"); show("interrogation"); @@ -79,6 +84,7 @@ function getCulprit(){ } async function askTypeOneQuestion(){ + removeQuestionButtonsListeners(); partnerId = getNpcLocationAndPartner(currentNpc)["partner"]; anwser = gamedata["npcs"][currentNpc]["QA_1"]; anwser = anwser.replace("{NPC}",gamedata["npcs"][partnerId]["name"]); @@ -90,10 +96,13 @@ async function askTypeOneQuestion(){ document.getElementById("currentNpcPicure").src = "/api/v1/getNpcImage?npcid="+currentNpc; hide("question_answer"); document.getElementsByClassName("suspect_answer")[0].textContent = ""; + setQuestionButtonsListeners(); } async function askTypeZeroQuestion(){ + removeQuestionButtonsListeners(); + document.getElementById("QA_0") room = getNpcLocationAndPartner(currentNpc)["room"]; anwser = gamedata["npcs"][currentNpc]["QA_0"]; anwser = anwser.replace("{SALLE}",room); @@ -105,6 +114,7 @@ async function askTypeZeroQuestion(){ document.getElementById("currentNpcPicure").src = "/api/v1/getNpcImage?npcid="+currentNpc; hide("question_answer"); document.getElementsByClassName("suspect_answer")[0].textContent = ""; + setQuestionButtonsListeners(); } async function sendAnswers(){ From 56aa031d516f7e207bc82e1109fea8518a299d34 Mon Sep 17 00:00:00 2001 From: SIMAILA Djalim Date: Mon, 16 Jan 2023 09:13:55 +0100 Subject: [PATCH 3/3] score is fixed --- truthseeker/routes/routes_api.py | 2 ++ truthseeker/static/js/game.js | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/truthseeker/routes/routes_api.py b/truthseeker/routes/routes_api.py index 5aa7001..27017f3 100644 --- a/truthseeker/routes/routes_api.py +++ b/truthseeker/routes/routes_api.py @@ -114,6 +114,8 @@ def get_data(): response = {} response["error"] = 0 response["gamedata"] = game.gamedata + response["username"] = flask.session["username"] + return response @routes_api.route("/getNpcImage", methods=["GET", "POST"]) diff --git a/truthseeker/static/js/game.js b/truthseeker/static/js/game.js index c5b4b20..fc27805 100644 --- a/truthseeker/static/js/game.js +++ b/truthseeker/static/js/game.js @@ -1,9 +1,7 @@ var npcs_ids = [] var gamedata = {} var currentNpc = null - -//TODO ask the server for the user's score or username -var score = null +var username = null function show(className){ document.getElementsByClassName(className)[0].classList.remove("hidden"); @@ -208,7 +206,9 @@ function initSock(){ socket.on("gamefinished", (finalResults) => { hide("emotion_and_culprit_choices"); console.log(finalResults); + document.getElementsByClassName("reveal_score")[0].textContent = Object.values(finalResults["player"][username]).filter(x => x==true).length +"/5" for (const player in finalResults["player"]){ + if(player === username){continue} let playerNode = document.createElement("h3") playerNode.classList.add("player_name_and_score") let playerResultArray = Object.values(finalResults["player"][player]) @@ -246,6 +246,7 @@ async function setGameData(){ data = {}; response = await makeAPIRequest("getGameData"); gamedata = response["gamedata"]; + username = response["username"] npcs_ids = Object.keys(gamedata["npcs"]).sort((a, b) => 0.5 - Math.random()) }