added questions fontions and reactions display
This commit is contained in:
parent
18fed88aa5
commit
d0dae92c21
@ -116,7 +116,7 @@ class Game:
|
|||||||
self.members.append(member)
|
self.members.append(member)
|
||||||
return member
|
return member
|
||||||
|
|
||||||
def get_npc_reaction(self, npc_id, reaction) -> None:
|
def get_npc_reaction(self, npc_id) -> None:
|
||||||
"""
|
"""
|
||||||
TODO + TODO TYPES
|
TODO + TODO TYPES
|
||||||
"""
|
"""
|
||||||
|
@ -140,9 +140,8 @@ def getNpcReaction():
|
|||||||
if game == None:
|
if game == None:
|
||||||
return {"error": 1, "msg": "this game doesn't exist"}
|
return {"error": 1, "msg": "this game doesn't exist"}
|
||||||
npc_id = flask.request.values.get("npcid")
|
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"]
|
errors = ["npc not in game","error reading file"]
|
||||||
if image in [0,1]:
|
if image in [0,1]:
|
||||||
return {"error" :1, "msg": errors[image]} , 500
|
return {"error" :1, "msg": errors[image]} , 500
|
||||||
@ -150,7 +149,7 @@ def getNpcReaction():
|
|||||||
response = flask.make_response(image)
|
response = flask.make_response(image)
|
||||||
response.headers.set('Content-Type', 'image/png')
|
response.headers.set('Content-Type', 'image/png')
|
||||||
response.headers.set(
|
response.headers.set(
|
||||||
'Content-Disposition', 'attachment', filename=f'{reactionid}.png')
|
'Content-Disposition', 'attachment', filename=f'reaction.png')
|
||||||
return response
|
return response
|
||||||
|
|
||||||
@routes_api.route("/gameProgress", methods=["GET", "POST"])
|
@routes_api.route("/gameProgress", methods=["GET", "POST"])
|
||||||
|
@ -1,44 +1,92 @@
|
|||||||
var npcs_ids = []
|
var npcs_ids = []
|
||||||
var gamedata = {}
|
var gamedata = {}
|
||||||
|
var currentNpc = null
|
||||||
|
|
||||||
function showInterogation(){
|
|
||||||
document.getElementsByClassName("interrogation")[0].classList.remove("hidden");
|
function show(className){
|
||||||
}
|
document.getElementsByClassName(className)[0].classList.remove("hidden");
|
||||||
function hideInterogation(){
|
|
||||||
document.getElementsByClassName("interrogation")[0].classList.add("hidden");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function showEmotionAndCulpritChoices(){
|
function hide(className){
|
||||||
document.getElementsByClassName("emotion_and_culprit_choices")[0].classList.remove("hidden");
|
document.getElementsByClassName(className)[0].classList.add("hidden");
|
||||||
}
|
|
||||||
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(){
|
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(){
|
function setListenerToInterrogationNextBtn(){
|
||||||
document.getElementById("interrogation_next_btn").addEventListener("click", showEmotionAndCulpritChoicesView)
|
document.getElementById("interrogation_next_btn").addEventListener("click", showEmotionAndCulpritChoicesView)
|
||||||
}
|
}
|
||||||
|
|
||||||
function showInterogationView(){
|
function goBackToInterogation(){
|
||||||
hideIntroduction();
|
hide("interrogation_suspect");
|
||||||
showInterogation();
|
show("interrogation");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function showInterogationViewFromIntroduction(){
|
||||||
|
hide("introduction");
|
||||||
|
show("interrogation");
|
||||||
}
|
}
|
||||||
|
|
||||||
function showEmotionAndCulpritChoicesView(){
|
function showEmotionAndCulpritChoicesView(){
|
||||||
hideInterogation();
|
hide("interrogation");
|
||||||
showEmotionAndCulpritChoices();
|
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(){
|
async function sendAnswers(){
|
||||||
selects = document.getElementsByClassName("suspect_emotion_chooser");
|
selects = document.getElementsByClassName("suspect_emotion_chooser");
|
||||||
@ -82,6 +130,8 @@ function renderAnswerSelectionPanel() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function renderInterogation(){
|
function renderInterogation(){
|
||||||
|
document.getElementById("QA_0").textContent = gamedata["questions"]["QA_0"],
|
||||||
|
document.getElementById("QA_1").textContent = gamedata["questions"]["QA_1"],
|
||||||
npcs_ids.forEach(element => {
|
npcs_ids.forEach(element => {
|
||||||
let suspect = document.createElement("div");
|
let suspect = document.createElement("div");
|
||||||
suspect.classList.add("suspect");
|
suspect.classList.add("suspect");
|
||||||
@ -93,6 +143,12 @@ function renderInterogation(){
|
|||||||
let button = document.getElementById("interogationButton");
|
let button = document.getElementById("interogationButton");
|
||||||
let button_clone = button.cloneNode(true);
|
let button_clone = button.cloneNode(true);
|
||||||
button_clone.classList.remove("hidden");
|
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)
|
suspect.appendChild(button_clone)
|
||||||
document.getElementById("interrogation_suspects").appendChild(suspect);
|
document.getElementById("interrogation_suspects").appendChild(suspect);
|
||||||
});
|
});
|
||||||
@ -130,8 +186,9 @@ async function initGame(){
|
|||||||
initSock();
|
initSock();
|
||||||
renderAnswerSelectionPanel();
|
renderAnswerSelectionPanel();
|
||||||
renderInterogation();
|
renderInterogation();
|
||||||
|
setListenerToInterrogationSuspectPreviousBtn()
|
||||||
setListenerToIntroductionNextBtn()
|
setListenerToIntroductionNextBtn()
|
||||||
setListenerToInterrogationNextBtn();
|
setListenerToInterrogationNextBtn();
|
||||||
showIntroduction();
|
show("introduction");
|
||||||
}
|
}
|
||||||
initGame();
|
initGame();
|
@ -41,14 +41,15 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="interrogation_suspect hidden">
|
<div class="interrogation_suspect hidden">
|
||||||
<h1 class="interrogation_title">Poser une question au suspect</h1>
|
<h1 class="interrogation_title">Poser une question au suspect</h1>
|
||||||
|
<img class="suspect_picture" id="currentNpcPicure" src="">
|
||||||
<button id="interrogation_suspect_previous_btn" class="next_btn" aria-label="Revenir à la sélection du suspect">
|
<button id="interrogation_suspect_previous_btn" class="next_btn" aria-label="Revenir à la sélection du suspect">
|
||||||
<svg class="next_btn" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 48">
|
<svg class="next_btn" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 48">
|
||||||
<path d="m23.15 36.95-17.3-11.1Q4.7 25.25 4.7 24t1.15-1.9L23.15 11q1.15-.7 2.35-.075 1.2.625 1.2 2.025v8.75h15.8q.95 0 1.625.675T44.8 24q0 .95-.675 1.6-.675.65-1.625.65H26.7V35q0 1.45-1.2 2.075-1.2.625-2.35-.125Z"/>
|
<path d="m23.15 36.95-17.3-11.1Q4.7 25.25 4.7 24t1.15-1.9L23.15 11q1.15-.7 2.35-.075 1.2.625 1.2 2.025v8.75h15.8q.95 0 1.625.675T44.8 24q0 .95-.675 1.6-.675.65-1.625.65H26.7V35q0 1.45-1.2 2.075-1.2.625-2.35-.125Z"/>
|
||||||
</svg>
|
</svg>
|
||||||
</button>
|
</button>
|
||||||
<div class="questions_list">
|
<div class="questions_list">
|
||||||
<button class="action_button question_button">Où étiez vous hier soir ?</button>
|
<button class="action_button question_button" id="QA_0">Où étiez vous hier soir ?</button>
|
||||||
<button class="action_button question_button">Avec qui étiez vous ?</button>
|
<button class="action_button question_button" id="QA_1">Avec qui étiez vous ?</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="question_answer hidden">
|
<div class="question_answer hidden">
|
||||||
<h1 class="anwser_title">Réponse du suspect à la question</h1>
|
<h1 class="anwser_title">Réponse du suspect à la question</h1>
|
||||||
@ -104,6 +105,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
<div class="alert_dialog_background"></div>
|
<div class="alert_dialog_background"></div>
|
||||||
<div class="unsupported_browser">
|
<div class="unsupported_browser">
|
||||||
<div id="unsupported_browser_dialog" class="alert_dialog">
|
<div id="unsupported_browser_dialog" class="alert_dialog">
|
||||||
|
Loading…
Reference in New Issue
Block a user