showing reaction pictures in result page
This commit is contained in:
parent
ed8b928ebc
commit
d41df3e478
@ -52,6 +52,16 @@ def get_npc_random_answer(npc_id:int, qa_type:int) -> Answer :
|
|||||||
answers = db.session.query(Answer).filter_by(QUESTION_TYPE_ID=qa_type,NPC_ID=npc_id.NPC_ID).all()
|
answers = db.session.query(Answer).filter_by(QUESTION_TYPE_ID=qa_type,NPC_ID=npc_id.NPC_ID).all()
|
||||||
return random.choice(answers)
|
return random.choice(answers)
|
||||||
|
|
||||||
|
def get_npc_from_npc_id(npc_id: int) -> Npc:
|
||||||
|
"""
|
||||||
|
Gets a Npc object from a npc_id
|
||||||
|
|
||||||
|
:param npc_id: the id of the trait to search for
|
||||||
|
:return: a Npc object
|
||||||
|
"""
|
||||||
|
npc = db.session.query(Npc).filter_by(NPC_ID=npc_id).one()
|
||||||
|
return npc
|
||||||
|
|
||||||
def get_random_question(qa_type: int) -> QuestionType :
|
def get_random_question(qa_type: int) -> QuestionType :
|
||||||
"""
|
"""
|
||||||
Returns a random inspector question from a question type
|
Returns a random inspector question from a question type
|
||||||
@ -93,6 +103,18 @@ def get_reaction_description(lang, trait_id) -> str:
|
|||||||
desc_lid = db.session.query(Trait).filter_by(TRAIT_ID=trait_id).one().DESC_LID
|
desc_lid = db.session.query(Trait).filter_by(TRAIT_ID=trait_id).one().DESC_LID
|
||||||
return get_text_from_lid(lang, desc_lid)
|
return get_text_from_lid(lang, desc_lid)
|
||||||
|
|
||||||
|
def get_reaction_from_npc_and_trait(npc_id: int,trait_id:int )-> Reaction:
|
||||||
|
"""_summary_
|
||||||
|
|
||||||
|
Args:
|
||||||
|
npc_id (int): _description_
|
||||||
|
trait_id (int): _description_
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Reaction: _description_
|
||||||
|
"""
|
||||||
|
return db.session.query(Reaction).filter_by(NPC_ID=npc_id,TRAIT_ID=trait_id).one()
|
||||||
|
|
||||||
def get_traits(lang: str) -> list:
|
def get_traits(lang: str) -> list:
|
||||||
"""
|
"""
|
||||||
Returns the list of all possible reactions trait in the given language
|
Returns the list of all possible reactions trait in the given language
|
||||||
@ -104,3 +126,14 @@ def get_traits(lang: str) -> list:
|
|||||||
for trait in db.session.query(Trait).all():
|
for trait in db.session.query(Trait).all():
|
||||||
traits.append(get_text_from_lid(lang,trait.NAME_LID))
|
traits.append(get_text_from_lid(lang,trait.NAME_LID))
|
||||||
return traits
|
return traits
|
||||||
|
|
||||||
|
def get_reaction_from_uuid(input_uuid: str) -> Reaction :
|
||||||
|
"""_summary_ TODO
|
||||||
|
|
||||||
|
Args:
|
||||||
|
input_uuid (str): _description_
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Reaction: _description_
|
||||||
|
"""
|
||||||
|
return db.session.query(Reaction).filter_by(REACTION_UUID=input_uuid).one()
|
||||||
|
@ -198,9 +198,9 @@ class Reaction(Base):
|
|||||||
NPC_ID = Column(Integer, ForeignKey("T_NPC.NPC_ID"), primary_key=True, comment="Name of the NPC that will have this reaction")
|
NPC_ID = Column(Integer, ForeignKey("T_NPC.NPC_ID"), primary_key=True, comment="Name of the NPC that will have this reaction")
|
||||||
TRAIT_ID = Column(Integer, ForeignKey("T_TRAIT.TRAIT_ID"), primary_key=True, comment="ID of the trait of this reaction")
|
TRAIT_ID = Column(Integer, ForeignKey("T_TRAIT.TRAIT_ID"), primary_key=True, comment="ID of the trait of this reaction")
|
||||||
IMG = Column(LargeBinary(length=2**24), comment="Binary data of the image associated to this npc and trait")
|
IMG = Column(LargeBinary(length=2**24), comment="Binary data of the image associated to this npc and trait")
|
||||||
|
REACTION_UUID = Column(VARCHAR(255), unique=True, comment="ID of this reaction")
|
||||||
NPC = relationship("Npc")
|
NPC = relationship("Npc")
|
||||||
TRAIT = relationship("Trait")
|
TRAIT = relationship("Trait")
|
||||||
REACTION_UUID = Column(VARCHAR(255), unique=True, comment="ID of this reaction")
|
|
||||||
|
|
||||||
def __init__(self, REACTION_ID, NPC_ID, TRAIT_ID):
|
def __init__(self, REACTION_ID, NPC_ID, TRAIT_ID):
|
||||||
self.REACTION_ID = REACTION_ID
|
self.REACTION_ID = REACTION_ID
|
||||||
|
@ -3,8 +3,6 @@ import time
|
|||||||
import random
|
import random
|
||||||
from typing import Union
|
from typing import Union
|
||||||
|
|
||||||
from sqlalchemy import select, and_
|
|
||||||
|
|
||||||
from truthinquiry.ext.database.models import *
|
from truthinquiry.ext.database.models import *
|
||||||
from truthinquiry.ext.database.fsa import db
|
from truthinquiry.ext.database.fsa import db
|
||||||
from truthinquiry.ext.database import dbutils
|
from truthinquiry.ext.database import dbutils
|
||||||
@ -90,6 +88,7 @@ class Game:
|
|||||||
trait_id = self.reaction_table[npc_id]
|
trait_id = self.reaction_table[npc_id]
|
||||||
trait = dbutils.get_trait_from_trait_id(trait_id)
|
trait = dbutils.get_trait_from_trait_id(trait_id)
|
||||||
npcs[npc_id]["reaction"] = dbutils.get_text_from_lid("FR", trait.NAME_LID)
|
npcs[npc_id]["reaction"] = dbutils.get_text_from_lid("FR", trait.NAME_LID)
|
||||||
|
npcs[npc_id]["uuid"] = dbutils.get_reaction_from_npc_and_trait(npc_id,self.reaction_table[npc_id]).REACTION_UUID
|
||||||
npcs[npc_id]["description"] = dbutils.get_reaction_description("FR", trait.TRAIT_ID)
|
npcs[npc_id]["description"] = dbutils.get_reaction_description("FR", trait.TRAIT_ID)
|
||||||
player_results = data["player"] = {}
|
player_results = data["player"] = {}
|
||||||
for member in self.members:
|
for member in self.members:
|
||||||
@ -140,11 +139,7 @@ class Game:
|
|||||||
if npc_id not in self.reaction_table:
|
if npc_id not in self.reaction_table:
|
||||||
return None
|
return None
|
||||||
trait_id = self.reaction_table[npc_id]
|
trait_id = self.reaction_table[npc_id]
|
||||||
|
reaction = dbutils.get_reaction_from_npc_and_trait(npc_id,trait_id)
|
||||||
reaction = db.session.execute(
|
|
||||||
select(Reaction)
|
|
||||||
.where(and_(Reaction.NPC_ID == int(npc_id), Reaction.TRAIT_ID == int(trait_id)))
|
|
||||||
).one()[0]
|
|
||||||
return reaction.IMG
|
return reaction.IMG
|
||||||
|
|
||||||
def get_player_results(self, responses: dict) -> Union[dict, None]:
|
def get_player_results(self, responses: dict) -> Union[dict, None]:
|
||||||
@ -347,5 +342,15 @@ def get_npc_image(npc_id: int):
|
|||||||
:param npc_id: npc to get the neutral image from
|
:param npc_id: npc to get the neutral image from
|
||||||
:return: the byte representation of the image, none if its not found or not readable
|
:return: the byte representation of the image, none if its not found or not readable
|
||||||
"""
|
"""
|
||||||
npc = db.session.execute(select(Npc).where(Npc.NPC_ID==npc_id)).one()[0]
|
npc = dbutils.get_npc_from_npc_id(npc_id)
|
||||||
return npc.DEFAULT_IMG
|
return npc.DEFAULT_IMG
|
||||||
|
|
||||||
|
def get_reactions_image_from_uuid(uuid: str):
|
||||||
|
"""
|
||||||
|
Returns the byte representation of the neutral image for an npc
|
||||||
|
|
||||||
|
:param npc_id: npc to get the neutral image from
|
||||||
|
:return: the byte representation of the image, none if its not found or not readable
|
||||||
|
"""
|
||||||
|
reaction = dbutils.get_reaction_from_uuid(uuid)
|
||||||
|
return reaction.IMG
|
||||||
|
@ -203,14 +203,11 @@ def get_npc_reaction():
|
|||||||
@routes_api.route("/getReaction", methods=["GET", "POST"])
|
@routes_api.route("/getReaction", methods=["GET", "POST"])
|
||||||
def get_reaction():
|
def get_reaction():
|
||||||
input_uuid = flask.request.values.get("uuid")
|
input_uuid = flask.request.values.get("uuid")
|
||||||
results = db.session.execute(select(Reaction).where(Reaction.REACTION_UUID==input_uuid))
|
image = game_logic.get_reactions_image_from_uuid(input_uuid)
|
||||||
|
if image is None:
|
||||||
row = results.first()
|
|
||||||
if row == None:
|
|
||||||
return {"error": 1, "msg": "No such reaction"}
|
return {"error": 1, "msg": "No such reaction"}
|
||||||
reaction_obj = row[0]
|
|
||||||
|
|
||||||
return flask.send_file(io.BytesIO(reaction_obj.IMG), mimetype='image/png')
|
return flask.send_file(io.BytesIO(image), mimetype='image/png')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -48,13 +48,13 @@
|
|||||||
/* Colors */
|
/* Colors */
|
||||||
color-scheme: dark;
|
color-scheme: dark;
|
||||||
--alert-dialog-background-color: #000000DF;
|
--alert-dialog-background-color: #000000DF;
|
||||||
--dark-theme-background-color: #213C40;
|
--dark-theme-background-color: #0c0b0c;
|
||||||
--game-black: #000000;
|
--game-black: #000000;
|
||||||
--game-blue: #7DDCFF;
|
--game-blue: #7DDCFF;
|
||||||
--game-green: #008000;
|
--game-green: #008000;
|
||||||
--game-grey: #5A5656;
|
--game-grey: #5A5656;
|
||||||
--game-red: #BD1E1E;
|
--game-red: #BD1E1E;
|
||||||
--game-gold: #E5BA73;
|
--game-gold: rgb(214,168,81);
|
||||||
--game-dark-gold: #B9935A;
|
--game-dark-gold: #B9935A;
|
||||||
--game-white: #FFFFFF;
|
--game-white: #FFFFFF;
|
||||||
--light-theme-background-color: #B1EDE8;
|
--light-theme-background-color: #B1EDE8;
|
||||||
|
@ -133,9 +133,10 @@ height: 6em;
|
|||||||
background-color: #000000d0;
|
background-color: #000000d0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.suspect_picture:hover {
|
.suspect > .suspect_picture:hover {
|
||||||
filter: grayscale(0);
|
filter: grayscale(0);
|
||||||
transition: all 0.5s ease;
|
transition: all 0.5s ease;
|
||||||
|
background-color: #000000d0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.suspect_picture[alt] {
|
.suspect_picture[alt] {
|
||||||
@ -148,7 +149,7 @@ background-color: #000000d0;
|
|||||||
}
|
}
|
||||||
|
|
||||||
.home_button, .next_btn {
|
.home_button, .next_btn {
|
||||||
fill: var(--game-red);
|
fill: var(--game-dark-gold);
|
||||||
height: 5em;
|
height: 5em;
|
||||||
width: 5em;
|
width: 5em;
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ html {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.game_start_failed, .multi_player_challenge_mode_invalid_input, .room_code, .room_title {
|
.game_start_failed, .multi_player_challenge_mode_invalid_input, .room_code, .room_title {
|
||||||
color: var(--game-red);
|
color: var(--game-dark-gold);
|
||||||
}
|
}
|
||||||
|
|
||||||
.join_room_view, .multi_player_mode_choice, .multi_player_mode_choice_number, .players_title, .room_code_text, .room_view_container {
|
.join_room_view, .multi_player_mode_choice, .multi_player_mode_choice_number, .players_title, .room_code_text, .room_view_container {
|
||||||
|
@ -50,7 +50,7 @@ input::placeholder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.back_btn {
|
.back_btn {
|
||||||
fill: var(--game-red);
|
fill: var(--game-dark-gold);
|
||||||
}
|
}
|
||||||
|
|
||||||
.game_begin {
|
.game_begin {
|
||||||
@ -58,6 +58,7 @@ input::placeholder {
|
|||||||
background-position: center;
|
background-position: center;
|
||||||
background-repeat: no-repeat;
|
background-repeat: no-repeat;
|
||||||
background-size: cover;
|
background-size: cover;
|
||||||
|
border: var(--game-gold) solid 1px;
|
||||||
border-radius: 1.5em;
|
border-radius: 1.5em;
|
||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
/*
|
/*
|
||||||
@ -66,7 +67,6 @@ input::placeholder {
|
|||||||
*/
|
*/
|
||||||
height: calc(100vh - var(--body-margin) * 2
|
height: calc(100vh - var(--body-margin) * 2
|
||||||
- var(--game-begin-margin) * 2
|
- var(--game-begin-margin) * 2
|
||||||
- var(--header-actions-side)
|
|
||||||
- var(--footer-links-height));
|
- var(--footer-links-height));
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
margin: var(--game-begin-margin);
|
margin: var(--game-begin-margin);
|
||||||
|
@ -3,6 +3,7 @@ const INTERROGATION_IMAGE_PATH = "/static/images/salle-interrogation.png";
|
|||||||
const RESULTS_IMAGE_PATH = "/static/images/salle-resultats.png";
|
const RESULTS_IMAGE_PATH = "/static/images/salle-resultats.png";
|
||||||
const NPC_REACTION_PATH = "/api/v1/getNpcReaction?npcid=";
|
const NPC_REACTION_PATH = "/api/v1/getNpcReaction?npcid=";
|
||||||
const NPC_IMAGE_PATH = "/api/v1/getNpcImage?npcid=";
|
const NPC_IMAGE_PATH = "/api/v1/getNpcImage?npcid=";
|
||||||
|
const NPC_FINAL_REACTION_PATH = "/api/v1/getReaction?uuid="
|
||||||
|
|
||||||
let npcsIds = [];
|
let npcsIds = [];
|
||||||
let gameData = {};
|
let gameData = {};
|
||||||
@ -408,6 +409,7 @@ function initSock() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
socket.on("gamefinished", finalResults => {
|
socket.on("gamefinished", finalResults => {
|
||||||
|
console.log(finalResults);
|
||||||
hideFirstClassElement("emotion_and_culprit_choices");
|
hideFirstClassElement("emotion_and_culprit_choices");
|
||||||
const revealScoreElement = document.createElement("h2");
|
const revealScoreElement = document.createElement("h2");
|
||||||
revealScoreElement.classList.add("reveal_score");
|
revealScoreElement.classList.add("reveal_score");
|
||||||
@ -458,7 +460,7 @@ function initSock() {
|
|||||||
|
|
||||||
const img = document.createElement("img");
|
const img = document.createElement("img");
|
||||||
img.setAttribute("alt", "Image d'un suspect");
|
img.setAttribute("alt", "Image d'un suspect");
|
||||||
img.src = NPC_IMAGE_PATH + npcid;
|
img.src = NPC_FINAL_REACTION_PATH + finalResults["npcs"][npcid]["uuid"];
|
||||||
suspect.appendChild(img);
|
suspect.appendChild(img);
|
||||||
|
|
||||||
const explain = document.createElement("div")
|
const explain = document.createElement("div")
|
||||||
|
@ -281,4 +281,4 @@ document.getElementById("join_room_button").addEventListener("click", joinMultiP
|
|||||||
|
|
||||||
// Execution of functions
|
// Execution of functions
|
||||||
|
|
||||||
setCurrentTheme();
|
//setCurrentTheme();
|
||||||
|
@ -17,15 +17,6 @@
|
|||||||
</head>
|
</head>
|
||||||
<body class="game_app">
|
<body class="game_app">
|
||||||
<section class="game_start">
|
<section class="game_start">
|
||||||
<menu class="header_actions">
|
|
||||||
<li class="header_action">
|
|
||||||
<button class="theme_switcher" aria-label="Changer de thème">
|
|
||||||
<svg class="theme_switcher_btn" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 48">
|
|
||||||
<path d="M24 34q-4.15 0-7.075-2.925T14 24q0-4.15 2.925-7.075T24 14q4.15 0 7.075 2.925T34 24q0 4.15-2.925 7.075T24 34ZM2 25.5v-3h8v3Zm36 0v-3h8v3ZM22.5 10V2h3v8Zm0 36v-8h3v8Zm-9.45-30.85L8.1 10.2l2.1-2.1 4.95 4.95ZM37.8 39.9l-4.95-4.95 2.1-2.1 4.95 4.95Zm-2.85-24.75-2.1-2.1L37.8 8.1l2.1 2.1ZM10.2 39.9l-2.1-2.1 4.95-4.95 2.1 2.1Z"/>
|
|
||||||
</svg>
|
|
||||||
</button>
|
|
||||||
</li>
|
|
||||||
</menu>
|
|
||||||
<div class="game_begin">
|
<div class="game_begin">
|
||||||
<h1 class="game_title">Truth Inquiry</h1>
|
<h1 class="game_title">Truth Inquiry</h1>
|
||||||
<button class="action_button" id="play_button">Jouer</button>
|
<button class="action_button" id="play_button">Jouer</button>
|
||||||
|
Loading…
Reference in New Issue
Block a user