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 - - - -
+ +