commit
a6abf99f68
@ -114,6 +114,8 @@ def get_data():
|
|||||||
response = {}
|
response = {}
|
||||||
response["error"] = 0
|
response["error"] = 0
|
||||||
response["gamedata"] = game.gamedata
|
response["gamedata"] = game.gamedata
|
||||||
|
response["username"] = flask.session["username"]
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
@routes_api.route("/getNpcImage", methods=["GET", "POST"])
|
@routes_api.route("/getNpcImage", methods=["GET", "POST"])
|
||||||
|
@ -22,10 +22,17 @@ def licenses():
|
|||||||
def legal():
|
def legal():
|
||||||
return flask.render_template("legal.html")
|
return flask.render_template("legal.html")
|
||||||
|
|
||||||
|
@routes_ui.route("/lobby")
|
||||||
|
def lobbyRedirect():
|
||||||
|
return flask.redirect("/")
|
||||||
|
|
||||||
|
|
||||||
@routes_ui.route("/lobby/<game_id>")
|
@routes_ui.route("/lobby/<game_id>")
|
||||||
def lobby(game_id):
|
def lobby(game_id):
|
||||||
# rendered by the javascript client-side
|
# 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)
|
return flask.render_template("lobby.html", gameid=game_id)
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
var npcs_ids = []
|
var npcs_ids = []
|
||||||
var gamedata = {}
|
var gamedata = {}
|
||||||
var currentNpc = null
|
var currentNpc = null
|
||||||
|
var username = null
|
||||||
//TODO ask the server for the user's score or username
|
|
||||||
var score = null
|
|
||||||
|
|
||||||
function show(className){
|
function show(className){
|
||||||
document.getElementsByClassName(className)[0].classList.remove("hidden");
|
document.getElementsByClassName(className)[0].classList.remove("hidden");
|
||||||
@ -30,6 +28,11 @@ function setQuestionButtonsListeners(){
|
|||||||
document.getElementById("QA_1").addEventListener("click",askTypeOneQuestion);
|
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(){
|
function goBackToInterogation(){
|
||||||
hide("interrogation_suspect");
|
hide("interrogation_suspect");
|
||||||
show("interrogation");
|
show("interrogation");
|
||||||
@ -79,6 +82,7 @@ function getCulprit(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function askTypeOneQuestion(){
|
async function askTypeOneQuestion(){
|
||||||
|
removeQuestionButtonsListeners();
|
||||||
partnerId = getNpcLocationAndPartner(currentNpc)["partner"];
|
partnerId = getNpcLocationAndPartner(currentNpc)["partner"];
|
||||||
anwser = gamedata["npcs"][currentNpc]["QA_1"];
|
anwser = gamedata["npcs"][currentNpc]["QA_1"];
|
||||||
anwser = anwser.replace("{NPC}",gamedata["npcs"][partnerId]["name"]);
|
anwser = anwser.replace("{NPC}",gamedata["npcs"][partnerId]["name"]);
|
||||||
@ -90,10 +94,13 @@ async function askTypeOneQuestion(){
|
|||||||
document.getElementById("currentNpcPicure").src = "/api/v1/getNpcImage?npcid="+currentNpc;
|
document.getElementById("currentNpcPicure").src = "/api/v1/getNpcImage?npcid="+currentNpc;
|
||||||
hide("question_answer");
|
hide("question_answer");
|
||||||
document.getElementsByClassName("suspect_answer")[0].textContent = "";
|
document.getElementsByClassName("suspect_answer")[0].textContent = "";
|
||||||
|
setQuestionButtonsListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async function askTypeZeroQuestion(){
|
async function askTypeZeroQuestion(){
|
||||||
|
removeQuestionButtonsListeners();
|
||||||
|
document.getElementById("QA_0")
|
||||||
room = getNpcLocationAndPartner(currentNpc)["room"];
|
room = getNpcLocationAndPartner(currentNpc)["room"];
|
||||||
anwser = gamedata["npcs"][currentNpc]["QA_0"];
|
anwser = gamedata["npcs"][currentNpc]["QA_0"];
|
||||||
anwser = anwser.replace("{SALLE}",room);
|
anwser = anwser.replace("{SALLE}",room);
|
||||||
@ -105,6 +112,7 @@ async function askTypeZeroQuestion(){
|
|||||||
document.getElementById("currentNpcPicure").src = "/api/v1/getNpcImage?npcid="+currentNpc;
|
document.getElementById("currentNpcPicure").src = "/api/v1/getNpcImage?npcid="+currentNpc;
|
||||||
hide("question_answer");
|
hide("question_answer");
|
||||||
document.getElementsByClassName("suspect_answer")[0].textContent = "";
|
document.getElementsByClassName("suspect_answer")[0].textContent = "";
|
||||||
|
setQuestionButtonsListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function sendAnswers(){
|
async function sendAnswers(){
|
||||||
@ -198,7 +206,9 @@ function initSock(){
|
|||||||
socket.on("gamefinished", (finalResults) => {
|
socket.on("gamefinished", (finalResults) => {
|
||||||
hide("emotion_and_culprit_choices");
|
hide("emotion_and_culprit_choices");
|
||||||
console.log(finalResults);
|
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"]){
|
for (const player in finalResults["player"]){
|
||||||
|
if(player === username){continue}
|
||||||
let playerNode = document.createElement("h3")
|
let playerNode = document.createElement("h3")
|
||||||
playerNode.classList.add("player_name_and_score")
|
playerNode.classList.add("player_name_and_score")
|
||||||
let playerResultArray = Object.values(finalResults["player"][player])
|
let playerResultArray = Object.values(finalResults["player"][player])
|
||||||
@ -236,6 +246,7 @@ async function setGameData(){
|
|||||||
data = {};
|
data = {};
|
||||||
response = await makeAPIRequest("getGameData");
|
response = await makeAPIRequest("getGameData");
|
||||||
gamedata = response["gamedata"];
|
gamedata = response["gamedata"];
|
||||||
|
username = response["username"]
|
||||||
npcs_ids = Object.keys(gamedata["npcs"]).sort((a, b) => 0.5 - Math.random())
|
npcs_ids = Object.keys(gamedata["npcs"]).sort((a, b) => 0.5 - Math.random())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user