From 71aedd3854c4c231168df110acabfbec721b17a8 Mon Sep 17 00:00:00 2001 From: SIMAILA Djalim Date: Sat, 14 Jan 2023 12:36:15 +0100 Subject: [PATCH] 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 - -
+
- + + - +