From acdae93ac3cb9bd80dd9ac3a3725321144cbe11c Mon Sep 17 00:00:00 2001 From: SIMAILA Djalim Date: Fri, 13 Jan 2023 15:06:46 +0100 Subject: [PATCH 01/13] fix bug in image related requests --- truthseeker/logic/game_logic.py | 2 +- truthseeker/routes/routes_api.py | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/truthseeker/logic/game_logic.py b/truthseeker/logic/game_logic.py index 9e6f2f8..b1730ba 100644 --- a/truthseeker/logic/game_logic.py +++ b/truthseeker/logic/game_logic.py @@ -120,7 +120,7 @@ class Game: """ if npc_id not in self.reaction_table.keys(): return 0 - reaction_id = self.reaction_table[npc_id][int(reaction)] + reaction_id = self.reaction_table[npc_id] return read_image(f"./truthseeker/static/images/npc/{npc_id}/{reaction_id}.png") def get_player_results(self, responses: dict) -> None: diff --git a/truthseeker/routes/routes_api.py b/truthseeker/routes/routes_api.py index 96167a4..f054f75 100644 --- a/truthseeker/routes/routes_api.py +++ b/truthseeker/routes/routes_api.py @@ -120,8 +120,11 @@ def get_data(): @routes_api.route("/getNpcImage", methods=["GET", "POST"]) def getNpcImage(): npc_id = flask.request.values.get("npcid") + if npc_id is None: + return {"error": 1, "msg": "no npc was given"} image = game_logic.get_npc_image(npc_id) - + if image is None: + return {"error": 1, "msg": "npc not found"} response = flask.make_response(image) response.headers.set('Content-Type', 'image/png') response.headers.set( @@ -194,6 +197,7 @@ def checkAnwser(): if game.has_finished(): jsonGameResults = game.generate_game_results() APP.socketio_app.emit("gamefinshed",jsonGameResults,room="game."+game.game_id) + #TODO desctruct game response = {"error": 0} return response From 956daf20fbfbe915f5be8209fb9b0ff0a0d3f4ef Mon Sep 17 00:00:00 2001 From: SIMAILA Djalim Date: Fri, 13 Jan 2023 15:45:34 +0100 Subject: [PATCH 02/13] added reaction description into game_results --- truthseeker/logic/data_persistance/data_access.py | 4 ++++ truthseeker/logic/game_logic.py | 1 + 2 files changed, 5 insertions(+) diff --git a/truthseeker/logic/data_persistance/data_access.py b/truthseeker/logic/data_persistance/data_access.py index 4d76116..bffe2b6 100644 --- a/truthseeker/logic/data_persistance/data_access.py +++ b/truthseeker/logic/data_persistance/data_access.py @@ -47,6 +47,10 @@ def get_trait_from_trait_id(trait_id): trait = session.query(tables.Trait).filter_by(TRAIT_ID=trait_id).one() return trait +def get_reaction_description(lang,npc_id,trait_id): + desc_lid = session.query(tables.Reaction).filter_by(NPC_ID=npc_id,TRAIT_ID=trait_id).one().DESC_LID + return get_text_from_lid(lang,desc_lid) + def get_traits(lang): traits = [] for trait in session.query(tables.Trait).all(): diff --git a/truthseeker/logic/game_logic.py b/truthseeker/logic/game_logic.py index b1730ba..29f15cc 100644 --- a/truthseeker/logic/game_logic.py +++ b/truthseeker/logic/game_logic.py @@ -78,6 +78,7 @@ class Game: traitId = self.reaction_table[npc_id] trait = get_trait_from_trait_id(traitId) npcs[npc_id]["reaction"] = get_text_from_lid("FR",trait.NAME_LID) + npcs[npc_id]["description"] = get_reaction_description("FR",trait.TRAIT_ID) player_results = data["player"] = {} for member in self.members: player_results[member.username] = member.results From 61ea8164a634bca7e52d0ba7bbd37d2cc6db4fcb Mon Sep 17 00:00:00 2001 From: SIMAILA Djalim Date: Sat, 14 Jan 2023 10:38:58 +0100 Subject: [PATCH 03/13] added image placeholder generator in anwser view --- truthseeker/static/js/api.js | 11 +++++++ truthseeker/static/js/game.js | 55 +++++++++++++++++++++++++++++++++ truthseeker/templates/game.html | 22 ++----------- 3 files changed, 68 insertions(+), 20 deletions(-) create mode 100644 truthseeker/static/js/game.js diff --git a/truthseeker/static/js/api.js b/truthseeker/static/js/api.js index 803dd3f..3ea92c4 100644 --- a/truthseeker/static/js/api.js +++ b/truthseeker/static/js/api.js @@ -15,3 +15,14 @@ async function makeAPIRequest(endpoint, body){ }) }) } +async function makeAPIImageRequest(endpoint, body){ + return new Promise((resolve, reject)=>{ + const fetchOptions = { + method: "POST", + body: new URLSearchParams(body) + } + fetch("/api/v1/"+endpoint, fetchOptions).then(resp => { + resolve(resp) + }) + }) +} diff --git a/truthseeker/static/js/game.js b/truthseeker/static/js/game.js new file mode 100644 index 0000000..fd92431 --- /dev/null +++ b/truthseeker/static/js/game.js @@ -0,0 +1,55 @@ +var npcs_ids = [] +var gamedata = {} +async function showAnswerSelectionPanel() { + npcs_ids.forEach(async element => { + console.log(element); + let suspect = document.createElement("div"); + suspect.classList.add("suspect"); + + suspect_emotion_chooser = document.createElement("select"); + suspect_emotion_chooser.classList.add("suspect_emotion_chooser") + gamedata["traits"].forEach(trait =>{ + let option = document.createElement("option"); + option.value = trait; + option.text = trait; + suspect_emotion_chooser.appendChild(option); + }); + suspect.appendChild(suspect_emotion_chooser); + let data = {}; + data["npcid"] = element; + let img_binary = await makeAPIImageRequest("getNpcImage",data); + let img = document.createElement('img'); + img.classList.add("suspect_picture"); + img.src = img_binary; + //img.src = 'data:image/png;base64,' + btoa('your-binary-data'); + suspect.appendChild(img); + document.getElementById("123").appendChild(suspect); + }); +} + +function initSock(){ + socket = io({ + auth:{ + game_id: gameid + } + }); + + socket.on("connect", () => { + console.log("Connected !") + }) + + socket.on("gameprogress", (username) => { + console.log(username); + }); +} + +function setGameData(){ + data = {}; + response = makeAPIRequest("getGameData"); + response.then((value) => { + gamedata = value["gamedata"]; + npcs_ids = Object.keys(gamedata["npcs"]); + }) +} + +setGameData() \ No newline at end of file diff --git a/truthseeker/templates/game.html b/truthseeker/templates/game.html index 4b8b786..14d56d0 100644 --- a/truthseeker/templates/game.html +++ b/truthseeker/templates/game.html @@ -42,26 +42,6 @@
- -
- - Example - - - -
+ + From 370ca28ab5ed3d7ef1ef59872e092bee2b8f350d Mon Sep 17 00:00:00 2001 From: SIMAILA Djalim Date: Sat, 14 Jan 2023 11:58:52 +0100 Subject: [PATCH 04/13] finished npc generation on culprits and emotion --- truthseeker/static/js/game.js | 12 +++++++----- truthseeker/templates/game.html | 14 +++++++++++++- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/truthseeker/static/js/game.js b/truthseeker/static/js/game.js index fd92431..8ec1c0b 100644 --- a/truthseeker/static/js/game.js +++ b/truthseeker/static/js/game.js @@ -1,5 +1,6 @@ var npcs_ids = [] var gamedata = {} +var button = "" async function showAnswerSelectionPanel() { npcs_ids.forEach(async element => { console.log(element); @@ -16,14 +17,15 @@ async function showAnswerSelectionPanel() { }); suspect.appendChild(suspect_emotion_chooser); let data = {}; - data["npcid"] = element; - let img_binary = await makeAPIImageRequest("getNpcImage",data); let img = document.createElement('img'); img.classList.add("suspect_picture"); - img.src = img_binary; - //img.src = 'data:image/png;base64,' + btoa('your-binary-data'); + img.src = "/api/v1/getNpcImage?npcid="+element; suspect.appendChild(img); - document.getElementById("123").appendChild(suspect); + let button = document.getElementById("mainButton"); + let button_clone = button.cloneNode(true); + button_clone.classList.remove("hidden"); + suspect.appendChild(button_clone); + document.getElementById("culprits_choices").appendChild(suspect); }); } diff --git a/truthseeker/templates/game.html b/truthseeker/templates/game.html index 14d56d0..02fefd0 100644 --- a/truthseeker/templates/game.html +++ b/truthseeker/templates/game.html @@ -41,7 +41,7 @@ -
+
+ + + + From 71aedd3854c4c231168df110acabfbec721b17a8 Mon Sep 17 00:00:00 2001 From: SIMAILA Djalim Date: Sat, 14 Jan 2023 12:36:15 +0100 Subject: [PATCH 05/13] show npcs on interogation screen --- truthseeker/static/js/game.js | 58 +++++++++++++++++++++++++++------ truthseeker/templates/game.html | 13 +++----- 2 files changed, 53 insertions(+), 18 deletions(-) diff --git a/truthseeker/static/js/game.js b/truthseeker/static/js/game.js index 8ec1c0b..2de9b05 100644 --- a/truthseeker/static/js/game.js +++ b/truthseeker/static/js/game.js @@ -1,8 +1,23 @@ var npcs_ids = [] var gamedata = {} var button = "" -async function showAnswerSelectionPanel() { - npcs_ids.forEach(async element => { + +function showInterogation(){ + document.getElementsByClassName("interrogation")[0].classList.remove("hidden"); +} +function hideInterogation(){ + document.getElementsByClassName("interrogation")[0].classList.add("hidden"); +} + +function showEmotionAndCulpritChoices(){ + document.getElementsByClassName("emotion_and_culprit_choices")[0].classList.remove("hidden"); +} +function hideEmotionAndCulpritChoices(){ + document.getElementsByClassName("emotion_and_culprit_choices")[0].classList.add("hidden"); +} + +function renderAnswerSelectionPanel() { + npcs_ids.forEach(element => { console.log(element); let suspect = document.createElement("div"); suspect.classList.add("suspect"); @@ -21,7 +36,7 @@ async function showAnswerSelectionPanel() { img.classList.add("suspect_picture"); img.src = "/api/v1/getNpcImage?npcid="+element; suspect.appendChild(img); - let button = document.getElementById("mainButton"); + let button = document.getElementById("culpritButton"); let button_clone = button.cloneNode(true); button_clone.classList.remove("hidden"); suspect.appendChild(button_clone); @@ -29,6 +44,23 @@ async function showAnswerSelectionPanel() { }); } +function renderInterogation(){ + npcs_ids.forEach(element => { + let suspect = document.createElement("div"); + suspect.classList.add("suspect"); + + let img = document.createElement('img'); + img.classList.add("suspect_picture"); + img.src = "/api/v1/getNpcImage?npcid="+element; + suspect.appendChild(img); + let button = document.getElementById("interogationButton"); + let button_clone = button.cloneNode(true); + button_clone.classList.remove("hidden"); + suspect.appendChild(button_clone) + document.getElementById("interrogation_suspects").appendChild(suspect); + }); +} + function initSock(){ socket = io({ auth:{ @@ -45,13 +77,19 @@ function initSock(){ }); } -function setGameData(){ +async function setGameData(){ data = {}; - response = makeAPIRequest("getGameData"); - response.then((value) => { - gamedata = value["gamedata"]; - npcs_ids = Object.keys(gamedata["npcs"]); - }) + response = await makeAPIRequest("getGameData"); + gamedata = response["gamedata"]; + npcs_ids = Object.keys(gamedata["npcs"]); } -setGameData() \ No newline at end of file +async function initGame(){ + await setGameData(); + //initSock(); + renderAnswerSelectionPanel(); + renderInterogation(); + showInterogation(); +} + +initGame(); \ No newline at end of file diff --git a/truthseeker/templates/game.html b/truthseeker/templates/game.html index 02fefd0..9fa3444 100644 --- a/truthseeker/templates/game.html +++ b/truthseeker/templates/game.html @@ -26,12 +26,7 @@ -
- -
- Example - -
+
- + + - + From 03ce844c6aeb9aafc1680a78d1d253cc5e65113c Mon Sep 17 00:00:00 2001 From: SIMAILA Djalim Date: Sat, 14 Jan 2023 12:53:28 +0100 Subject: [PATCH 06/13] added listener to InterogationNextButton --- truthseeker/static/js/game.js | 10 ++++++++++ truthseeker/static/js/game_start_page.js | 17 +++++++---------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/truthseeker/static/js/game.js b/truthseeker/static/js/game.js index 2de9b05..611bae2 100644 --- a/truthseeker/static/js/game.js +++ b/truthseeker/static/js/game.js @@ -16,6 +16,15 @@ function hideEmotionAndCulpritChoices(){ document.getElementsByClassName("emotion_and_culprit_choices")[0].classList.add("hidden"); } +function setListenerToInterrogationNextBtn(){ + document.getElementById("interrogation_next_btn").addEventListener("click", showInterogationView) +} + +function showInterogationView(){ + hideInterogation(); + showEmotionAndCulpritChoices(); +} + function renderAnswerSelectionPanel() { npcs_ids.forEach(element => { console.log(element); @@ -89,6 +98,7 @@ async function initGame(){ //initSock(); renderAnswerSelectionPanel(); renderInterogation(); + setListenerToInterrogationNextBtn(); showInterogation(); } diff --git a/truthseeker/static/js/game_start_page.js b/truthseeker/static/js/game_start_page.js index a57470d..11d58a0 100644 --- a/truthseeker/static/js/game_start_page.js +++ b/truthseeker/static/js/game_start_page.js @@ -108,16 +108,6 @@ function areInputsValid(checkRoomCode) { return true; } -function startSoloGame() { - if (!areInputsValid(false)) { - return; - } - - hideInvalidInputErrorMessage(); - - //TODO: code to start solo game -} - function createMultiPlayerRoom() { if (!areInputsValid(false)) { return; @@ -209,6 +199,13 @@ function changeTheme() { } async function startSoloGame(){ + + if (!areInputsValid(false)) { + return; + } + + hideInvalidInputErrorMessage(); + username = document.getElementById("game_username").value; let data = {} data["username"] = username; From a7a428357d2116000cf96121153af9187a2e08b4 Mon Sep 17 00:00:00 2001 From: SIMAILA Djalim Date: Sat, 14 Jan 2023 14:57:58 +0100 Subject: [PATCH 07/13] show and hide introduction view --- truthseeker/static/js/game.js | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/truthseeker/static/js/game.js b/truthseeker/static/js/game.js index 611bae2..f152989 100644 --- a/truthseeker/static/js/game.js +++ b/truthseeker/static/js/game.js @@ -16,18 +16,32 @@ function hideEmotionAndCulpritChoices(){ document.getElementsByClassName("emotion_and_culprit_choices")[0].classList.add("hidden"); } +function showIntroduction(){ + document.getElementsByClassName("introduction")[0].classList.remove("hidden"); +} +function hideIntroduction(){ + document.getElementsByClassName("introduction")[0].classList.add("hidden"); +} +function setListenerToIntroductionNextBtn(){ + document.getElementById("introduction_next_btn").addEventListener("click", showInterogation) +} + function setListenerToInterrogationNextBtn(){ - document.getElementById("interrogation_next_btn").addEventListener("click", showInterogationView) + document.getElementById("interrogation_next_btn").addEventListener("click", showEmotionAndCulpritChoicesView) } function showInterogationView(){ + hideIntroduction(); + showInterogation(); +} + +function showEmotionAndCulpritChoicesView(){ hideInterogation(); showEmotionAndCulpritChoices(); } function renderAnswerSelectionPanel() { npcs_ids.forEach(element => { - console.log(element); let suspect = document.createElement("div"); suspect.classList.add("suspect"); @@ -98,8 +112,8 @@ async function initGame(){ //initSock(); renderAnswerSelectionPanel(); renderInterogation(); + setListenerToIntroductionNextBtn() setListenerToInterrogationNextBtn(); - showInterogation(); + showIntroduction(); } - initGame(); \ No newline at end of file From e763c71a593cb6b45a5d06bad710a2fa015368c3 Mon Sep 17 00:00:00 2001 From: SIMAILA Djalim Date: Sat, 14 Jan 2023 15:26:06 +0100 Subject: [PATCH 08/13] fixed intro not hiding and socket not allowed on prod --- truthseeker/__init__.py | 2 +- truthseeker/static/js/game.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/truthseeker/__init__.py b/truthseeker/__init__.py index 87a0a1d..910cba5 100644 --- a/truthseeker/__init__.py +++ b/truthseeker/__init__.py @@ -23,7 +23,7 @@ class TruthSeekerApp(flask.Flask): self.config["SECRET_KEY"] = os.getenv("FLASK_SECRET") - self.socketio_app = SocketIO(self) + self.socketio_app = SocketIO(self,cors_allowed_origins=["https://truthinquiry.simailadjalim.fr"]) self.discord_bot = discord_bot.DiscordBot() token = os.getenv("DISCORD_BOT_TOKEN") diff --git a/truthseeker/static/js/game.js b/truthseeker/static/js/game.js index f152989..fdbfedb 100644 --- a/truthseeker/static/js/game.js +++ b/truthseeker/static/js/game.js @@ -23,7 +23,7 @@ function hideIntroduction(){ document.getElementsByClassName("introduction")[0].classList.add("hidden"); } function setListenerToIntroductionNextBtn(){ - document.getElementById("introduction_next_btn").addEventListener("click", showInterogation) + document.getElementById("introduction_next_btn").addEventListener("click", showInterogationView) } function setListenerToInterrogationNextBtn(){ From 18fed88aa585d3a8246e2e608dd130eda57591b5 Mon Sep 17 00:00:00 2001 From: SIMAILA Djalim Date: Sat, 14 Jan 2023 16:24:19 +0100 Subject: [PATCH 09/13] 'fixed' cors not allowing localhost, incorect type comparaison in get_player_results, Finished sendAnswers in js --- truthseeker/__init__.py | 2 +- truthseeker/logic/game_logic.py | 5 +++-- truthseeker/static/js/game.js | 24 +++++++++++++++++++++--- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/truthseeker/__init__.py b/truthseeker/__init__.py index 910cba5..dca9bcb 100644 --- a/truthseeker/__init__.py +++ b/truthseeker/__init__.py @@ -23,7 +23,7 @@ class TruthSeekerApp(flask.Flask): self.config["SECRET_KEY"] = os.getenv("FLASK_SECRET") - self.socketio_app = SocketIO(self,cors_allowed_origins=["https://truthinquiry.simailadjalim.fr"]) + self.socketio_app = SocketIO(self,cors_allowed_origins=["https://truthinquiry.simailadjalim.fr","http://127.0.0.1:5000"]) self.discord_bot = discord_bot.DiscordBot() token = os.getenv("DISCORD_BOT_TOKEN") diff --git a/truthseeker/logic/game_logic.py b/truthseeker/logic/game_logic.py index 29f15cc..e3a7acd 100644 --- a/truthseeker/logic/game_logic.py +++ b/truthseeker/logic/game_logic.py @@ -78,7 +78,7 @@ class Game: traitId = self.reaction_table[npc_id] trait = get_trait_from_trait_id(traitId) npcs[npc_id]["reaction"] = get_text_from_lid("FR",trait.NAME_LID) - npcs[npc_id]["description"] = get_reaction_description("FR",trait.TRAIT_ID) + npcs[npc_id]["description"] = get_reaction_description("FR",npc_id,trait.TRAIT_ID) player_results = data["player"] = {} for member in self.members: player_results[member.username] = member.results @@ -90,6 +90,7 @@ class Game: """ #TODO Get language from player self.gamedata, self.reaction_table = generate_game_data("FR") + self.gamedata["game_id"] = self.game_id def get_member(self, username: str) -> Union[Member, None]: """ @@ -132,7 +133,7 @@ class Game: try: for npc_id in responses: trait_id = get_trait_id_from_string(responses[npc_id]) - results[npc_id] = trait_id == str(self.reaction_table[npc_id]) + results[npc_id] = trait_id == self.reaction_table[npc_id] return results except: return False diff --git a/truthseeker/static/js/game.js b/truthseeker/static/js/game.js index fdbfedb..510785f 100644 --- a/truthseeker/static/js/game.js +++ b/truthseeker/static/js/game.js @@ -1,6 +1,5 @@ var npcs_ids = [] var gamedata = {} -var button = "" function showInterogation(){ document.getElementsByClassName("interrogation")[0].classList.remove("hidden"); @@ -40,6 +39,19 @@ function showEmotionAndCulpritChoicesView(){ showEmotionAndCulpritChoices(); } + +async function sendAnswers(){ + selects = document.getElementsByClassName("suspect_emotion_chooser"); + let playerResponses = {} + for (let index = 0; index < selects.length; index++) { + select = selects[index]; + playerResponses[select.id] = select.value + } + data = {}; + data["responses"] = JSON.stringify(playerResponses); + return await makeAPIRequest("submitAnswers",data); +} + function renderAnswerSelectionPanel() { npcs_ids.forEach(element => { let suspect = document.createElement("div"); @@ -47,6 +59,7 @@ function renderAnswerSelectionPanel() { suspect_emotion_chooser = document.createElement("select"); suspect_emotion_chooser.classList.add("suspect_emotion_chooser") + suspect_emotion_chooser.setAttribute("id",element); gamedata["traits"].forEach(trait =>{ let option = document.createElement("option"); option.value = trait; @@ -61,6 +74,7 @@ function renderAnswerSelectionPanel() { suspect.appendChild(img); let button = document.getElementById("culpritButton"); let button_clone = button.cloneNode(true); + button_clone.removeAttribute("id"); button_clone.classList.remove("hidden"); suspect.appendChild(button_clone); document.getElementById("culprits_choices").appendChild(suspect); @@ -87,7 +101,7 @@ function renderInterogation(){ function initSock(){ socket = io({ auth:{ - game_id: gameid + game_id: gamedata["game_id"] } }); @@ -98,6 +112,10 @@ function initSock(){ socket.on("gameprogress", (username) => { console.log(username); }); + + socket.on("gamefinshed", (finalResults) => { + console.log(finalResults); + }); } async function setGameData(){ @@ -109,7 +127,7 @@ async function setGameData(){ async function initGame(){ await setGameData(); - //initSock(); + initSock(); renderAnswerSelectionPanel(); renderInterogation(); setListenerToIntroductionNextBtn() From d0dae92c21dae158d521bd39dfc50efbd03eb9e6 Mon Sep 17 00:00:00 2001 From: SIMAILA Djalim Date: Sat, 14 Jan 2023 20:40:54 +0100 Subject: [PATCH 10/13] added questions fontions and reactions display --- truthseeker/logic/game_logic.py | 2 +- truthseeker/routes/routes_api.py | 5 +- truthseeker/static/js/game.js | 103 ++++++++++++++++++++++++------- truthseeker/templates/game.html | 6 +- 4 files changed, 87 insertions(+), 29 deletions(-) diff --git a/truthseeker/logic/game_logic.py b/truthseeker/logic/game_logic.py index e3a7acd..350e557 100644 --- a/truthseeker/logic/game_logic.py +++ b/truthseeker/logic/game_logic.py @@ -116,7 +116,7 @@ class Game: self.members.append(member) return member - def get_npc_reaction(self, npc_id, reaction) -> None: + def get_npc_reaction(self, npc_id) -> None: """ TODO + TODO TYPES """ diff --git a/truthseeker/routes/routes_api.py b/truthseeker/routes/routes_api.py index f054f75..25ff771 100644 --- a/truthseeker/routes/routes_api.py +++ b/truthseeker/routes/routes_api.py @@ -140,9 +140,8 @@ def getNpcReaction(): if game == None: return {"error": 1, "msg": "this game doesn't exist"} npc_id = flask.request.values.get("npcid") - reactionid = flask.request.values.get("reactionid") - image = game.get_npc_reaction(npc_id,reactionid) + image = game.get_npc_reaction(npc_id) errors = ["npc not in game","error reading file"] if image in [0,1]: return {"error" :1, "msg": errors[image]} , 500 @@ -150,7 +149,7 @@ def getNpcReaction(): response = flask.make_response(image) response.headers.set('Content-Type', 'image/png') response.headers.set( - 'Content-Disposition', 'attachment', filename=f'{reactionid}.png') + 'Content-Disposition', 'attachment', filename=f'reaction.png') return response @routes_api.route("/gameProgress", methods=["GET", "POST"]) diff --git a/truthseeker/static/js/game.js b/truthseeker/static/js/game.js index 510785f..0902876 100644 --- a/truthseeker/static/js/game.js +++ b/truthseeker/static/js/game.js @@ -1,44 +1,92 @@ var npcs_ids = [] var gamedata = {} +var currentNpc = null -function showInterogation(){ - document.getElementsByClassName("interrogation")[0].classList.remove("hidden"); -} -function hideInterogation(){ - document.getElementsByClassName("interrogation")[0].classList.add("hidden"); + +function show(className){ + document.getElementsByClassName(className)[0].classList.remove("hidden"); } -function showEmotionAndCulpritChoices(){ - document.getElementsByClassName("emotion_and_culprit_choices")[0].classList.remove("hidden"); -} -function hideEmotionAndCulpritChoices(){ - document.getElementsByClassName("emotion_and_culprit_choices")[0].classList.add("hidden"); +function hide(className){ + document.getElementsByClassName(className)[0].classList.add("hidden"); } -function showIntroduction(){ - document.getElementsByClassName("introduction")[0].classList.remove("hidden"); -} -function hideIntroduction(){ - document.getElementsByClassName("introduction")[0].classList.add("hidden"); -} function setListenerToIntroductionNextBtn(){ - document.getElementById("introduction_next_btn").addEventListener("click", showInterogationView) + document.getElementById("introduction_next_btn").addEventListener("click", showInterogationViewFromIntroduction); +} + +function setListenerToInterrogationSuspectPreviousBtn(){ + document.getElementById("interrogation_suspect_previous_btn").addEventListener("click",goBackToInterogation) } function setListenerToInterrogationNextBtn(){ document.getElementById("interrogation_next_btn").addEventListener("click", showEmotionAndCulpritChoicesView) } -function showInterogationView(){ - hideIntroduction(); - showInterogation(); +function goBackToInterogation(){ + hide("interrogation_suspect"); + show("interrogation"); +} + + +function showInterogationViewFromIntroduction(){ + hide("introduction"); + show("interrogation"); } function showEmotionAndCulpritChoicesView(){ - hideInterogation(); - showEmotionAndCulpritChoices(); + hide("interrogation"); + show("emotion_and_culprit_choices"); } +function getNpcLocationAndPartner(npcid){ + data = {} + npcid = parseInt(npcid) + for(const room in gamedata["rooms"]){ + if(gamedata["rooms"][room]["npcs"].includes(npcid)){ + data["room"] = gamedata["rooms"][room]["name"]; + if(gamedata["rooms"][room]["npcs"].length === 1){ + do{ + const random = Math.floor(Math.random() * npcs_ids.length); + data["partner"] = npcs_ids[random] + }while(data["partner"] === npcid); + } + else{ + data["partner"] = gamedata["rooms"][room]["npcs"][gamedata["rooms"][room]["npcs"][1] === npcid ?0:1]; + } + } + } + return data; +} + +async function askTypeOneQuestion(){ + partnerId = getNpcLocationAndPartner(currentNpc)["partner"]; + anwser = gamedata["npcs"][currentNpc]["QA_1"]; + anwser = anwser.replace("{NPC}",gamedata["npcs"][partnerId]["name"]); + document.getElementsByClassName("suspect_answer")[0].textContent = anwser; + show("question_answer"); + document.getElementById("currentNpcPicure").src = "/api/v1//getNpcReaction?npcid="+currentNpc; + //sleep for 5 sec + await new Promise(r => setTimeout(r, 5000)); + document.getElementById("currentNpcPicure").src = "/api/v1/getNpcImage?npcid="+currentNpc; + hide("question_answer"); + document.getElementsByClassName("suspect_answer")[0].textContent = ""; +} + + +async function askTypeZeroQuestion(){ + room = getNpcLocationAndPartner(currentNpc)["room"]; + anwser = gamedata["npcs"][currentNpc]["QA_0"]; + anwser = anwser.replace("{SALLE}",room); + document.getElementsByClassName("suspect_answer")[0].textContent = anwser; + show("question_answer"); + document.getElementById("currentNpcPicure").src = "/api/v1//getNpcReaction?npcid="+currentNpc; + //sleep for 5 sec + await new Promise(r => setTimeout(r, 5000)); + document.getElementById("currentNpcPicure").src = "/api/v1/getNpcImage?npcid="+currentNpc; + hide("question_answer"); + document.getElementsByClassName("suspect_answer")[0].textContent = ""; +} async function sendAnswers(){ selects = document.getElementsByClassName("suspect_emotion_chooser"); @@ -82,6 +130,8 @@ function renderAnswerSelectionPanel() { } function renderInterogation(){ + document.getElementById("QA_0").textContent = gamedata["questions"]["QA_0"], + document.getElementById("QA_1").textContent = gamedata["questions"]["QA_1"], npcs_ids.forEach(element => { let suspect = document.createElement("div"); suspect.classList.add("suspect"); @@ -93,6 +143,12 @@ function renderInterogation(){ let button = document.getElementById("interogationButton"); let button_clone = button.cloneNode(true); button_clone.classList.remove("hidden"); + button_clone.addEventListener("click",()=>{ + currentNpc = element + document.getElementById("currentNpcPicure").src = "/api/v1/getNpcImage?npcid="+element; + hide("interrogation"); + show("interrogation_suspect"); + }) suspect.appendChild(button_clone) document.getElementById("interrogation_suspects").appendChild(suspect); }); @@ -130,8 +186,9 @@ async function initGame(){ initSock(); renderAnswerSelectionPanel(); renderInterogation(); + setListenerToInterrogationSuspectPreviousBtn() setListenerToIntroductionNextBtn() setListenerToInterrogationNextBtn(); - showIntroduction(); + show("introduction"); } initGame(); \ No newline at end of file diff --git a/truthseeker/templates/game.html b/truthseeker/templates/game.html index 9fa3444..70de15f 100644 --- a/truthseeker/templates/game.html +++ b/truthseeker/templates/game.html @@ -41,14 +41,15 @@ +
From dbd51e6bf82a39a296c9fc786c9dcab32f909a8b Mon Sep 17 00:00:00 2001 From: SIMAILA Djalim Date: Sat, 14 Jan 2023 20:47:28 +0100 Subject: [PATCH 11/13] added listeners to the questions buttons --- truthseeker/static/js/game.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/truthseeker/static/js/game.js b/truthseeker/static/js/game.js index 0902876..42d706a 100644 --- a/truthseeker/static/js/game.js +++ b/truthseeker/static/js/game.js @@ -23,6 +23,11 @@ function setListenerToInterrogationNextBtn(){ document.getElementById("interrogation_next_btn").addEventListener("click", showEmotionAndCulpritChoicesView) } +function setQuestionButtonsListeners(){ + document.getElementById("QA_0").addEventListener("click",askTypeZeroQuestion); + document.getElementById("QA_1").addEventListener("click",askTypeOneQuestion); +} + function goBackToInterogation(){ hide("interrogation_suspect"); show("interrogation"); From e6daa4775bcc7a929d05fa27a88d7b2f163647de Mon Sep 17 00:00:00 2001 From: SIMAILA Djalim Date: Sat, 14 Jan 2023 20:47:28 +0100 Subject: [PATCH 12/13] added listeners to the questions buttons --- truthseeker/static/js/game.js | 1 + 1 file changed, 1 insertion(+) diff --git a/truthseeker/static/js/game.js b/truthseeker/static/js/game.js index 42d706a..4d31bf6 100644 --- a/truthseeker/static/js/game.js +++ b/truthseeker/static/js/game.js @@ -191,6 +191,7 @@ async function initGame(){ initSock(); renderAnswerSelectionPanel(); renderInterogation(); + setQuestionButtonsListeners() setListenerToInterrogationSuspectPreviousBtn() setListenerToIntroductionNextBtn() setListenerToInterrogationNextBtn(); From da5533a57aa426193761610d414fd3eae3664afd Mon Sep 17 00:00:00 2001 From: SIMAILA Djalim Date: Sat, 14 Jan 2023 22:03:27 +0100 Subject: [PATCH 13/13] finished final results screen --- truthseeker/static/js/game.js | 48 ++++++++++++++++++++++++++++++++- truthseeker/templates/game.html | 28 +------------------ 2 files changed, 48 insertions(+), 28 deletions(-) diff --git a/truthseeker/static/js/game.js b/truthseeker/static/js/game.js index 4d31bf6..56691c5 100644 --- a/truthseeker/static/js/game.js +++ b/truthseeker/static/js/game.js @@ -1,7 +1,7 @@ var npcs_ids = [] var gamedata = {} var currentNpc = null - +var score = null function show(className){ document.getElementsByClassName(className)[0].classList.remove("hidden"); @@ -64,6 +64,18 @@ function getNpcLocationAndPartner(npcid){ return data; } + +function getCulprit(){ + culprit = null + Object.values(gamedata["rooms"]).forEach(element =>{ + if (element['npcs'].length === 1){ + culprit = element['npcs'][0]; + return; + } + }) + return culprit +} + async function askTypeOneQuestion(){ partnerId = getNpcLocationAndPartner(currentNpc)["partner"]; anwser = gamedata["npcs"][currentNpc]["QA_1"]; @@ -127,6 +139,9 @@ function renderAnswerSelectionPanel() { suspect.appendChild(img); let button = document.getElementById("culpritButton"); let button_clone = button.cloneNode(true); + button_clone.addEventListener("click",()=>{ + sendAnswers(); + }); button_clone.removeAttribute("id"); button_clone.classList.remove("hidden"); suspect.appendChild(button_clone); @@ -175,7 +190,38 @@ function initSock(){ }); socket.on("gamefinshed", (finalResults) => { + hide("emotion_and_culprit_choices"); console.log(finalResults); + for (const player in finalResults["player"]){ + let playerNode = document.createElement("h3") + playerNode.classList.add("player_name_and_score") + let playerResultArray = Object.values(finalResults["player"][player]) + playerNode.textContent = "" + player + " : " + playerResultArray.filter(x => x==true).length + document.getElementsByClassName("players_list")[0].appendChild(playerNode); + } + culprit = getCulprit(); + document.getElementsByClassName("reveal_culprit_title")[0].textContent += " " + gamedata["npcs"][culprit]["name"]; + document.getElementById("culprit").src = "/api/v1/getNpcImage?npcid="+culprit; + show("results_game"); + npcs_ids.filter(x => x!=culprit).forEach(npcid =>{ + let suspect = document.createElement("div"); + suspect.classList.add("summary_suspect"); + let img = document.createElement("img") + img.src = "/api/v1/getNpcImage?npcid=" + npcid; + suspect.appendChild(img) + + let emotionTitle = document.createElement("h2"); + emotionTitle.classList.add("explain_suspect_emotion_title"); + emotionTitle.textContent = "Ce suspect était " + finalResults["npcs"][npcid]["reaction"]; + suspect.appendChild(emotionTitle); + + let emotionDesc = document.createElement("p"); + emotionDesc.classList.add("explain_suspect_emotion_description"); + emotionDesc.textContent = "Qui se caractérise par un " + finalResults["npcs"][npcid]["description"]; + suspect.appendChild(emotionDesc) + + document.getElementsByClassName("suspects_list")[0].appendChild(suspect) + }) }); } diff --git a/truthseeker/templates/game.html b/truthseeker/templates/game.html index 70de15f..62241c0 100644 --- a/truthseeker/templates/game.html +++ b/truthseeker/templates/game.html @@ -66,43 +66,17 @@
- -

nom : score

-

nom : score

-

nom : score

-

nom : score

Le coupable était ...

- Example -

Ce suspect était le coupable car il ...

+ Example

Débrief

-
- Example -

Ce suspect était ...

-

En effet, la ... se caractérise par un ...

-
-
- Example -

Ce suspect était ...

-

En effet, la ... se caractérise par un ...

-
-
- Example -

Ce suspect était ...

-

En effet, la ... se caractérise par un ...

-
-
- Example -

Ce suspect était ...

-

En effet, la ... se caractérise par un ...

-