diff --git a/truthinquiry/ext/database/dbutils.py b/truthinquiry/ext/database/dbutils.py index b362ddc..913f630 100644 --- a/truthinquiry/ext/database/dbutils.py +++ b/truthinquiry/ext/database/dbutils.py @@ -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() 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 : """ 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 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: """ Returns the list of all possible reactions trait in the given language @@ -103,4 +125,15 @@ def get_traits(lang: str) -> list: traits = [] for trait in db.session.query(Trait).all(): traits.append(get_text_from_lid(lang,trait.NAME_LID)) - return traits \ No newline at end of file + 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() diff --git a/truthinquiry/ext/database/models.py b/truthinquiry/ext/database/models.py index be8b5cc..fca47e9 100644 --- a/truthinquiry/ext/database/models.py +++ b/truthinquiry/ext/database/models.py @@ -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") 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") + REACTION_UUID = Column(VARCHAR(255), unique=True, comment="ID of this reaction") NPC = relationship("Npc") TRAIT = relationship("Trait") - REACTION_UUID = Column(VARCHAR(255), unique=True, comment="ID of this reaction") def __init__(self, REACTION_ID, NPC_ID, TRAIT_ID): self.REACTION_ID = REACTION_ID diff --git a/truthinquiry/logic/game_logic.py b/truthinquiry/logic/game_logic.py index 30bc685..00a5d2f 100644 --- a/truthinquiry/logic/game_logic.py +++ b/truthinquiry/logic/game_logic.py @@ -3,8 +3,6 @@ import time import random from typing import Union -from sqlalchemy import select, and_ - from truthinquiry.ext.database.models import * from truthinquiry.ext.database.fsa import db from truthinquiry.ext.database import dbutils @@ -90,6 +88,7 @@ class Game: trait_id = self.reaction_table[npc_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]["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) player_results = data["player"] = {} for member in self.members: @@ -140,11 +139,7 @@ class Game: if npc_id not in self.reaction_table: return None trait_id = self.reaction_table[npc_id] - - reaction = db.session.execute( - select(Reaction) - .where(and_(Reaction.NPC_ID == int(npc_id), Reaction.TRAIT_ID == int(trait_id))) - ).one()[0] + reaction = dbutils.get_reaction_from_npc_and_trait(npc_id,trait_id) return reaction.IMG 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 :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 + +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 diff --git a/truthinquiry/routes/routes_api.py b/truthinquiry/routes/routes_api.py index b4cf098..f4b1ffd 100644 --- a/truthinquiry/routes/routes_api.py +++ b/truthinquiry/routes/routes_api.py @@ -203,14 +203,11 @@ def get_npc_reaction(): @routes_api.route("/getReaction", methods=["GET", "POST"]) def get_reaction(): input_uuid = flask.request.values.get("uuid") - results = db.session.execute(select(Reaction).where(Reaction.REACTION_UUID==input_uuid)) - - row = results.first() - if row == None: + image = game_logic.get_reactions_image_from_uuid(input_uuid) + if image is None: 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') diff --git a/truthinquiry/static/css/game_ui.css b/truthinquiry/static/css/game_ui.css index 9d50ffb..fc644fb 100644 --- a/truthinquiry/static/css/game_ui.css +++ b/truthinquiry/static/css/game_ui.css @@ -48,13 +48,13 @@ /* Colors */ color-scheme: dark; --alert-dialog-background-color: #000000DF; - --dark-theme-background-color: #213C40; + --dark-theme-background-color: #0c0b0c; --game-black: #000000; --game-blue: #7DDCFF; --game-green: #008000; --game-grey: #5A5656; --game-red: #BD1E1E; - --game-gold: #E5BA73; + --game-gold: rgb(214,168,81); --game-dark-gold: #B9935A; --game-white: #FFFFFF; --light-theme-background-color: #B1EDE8; diff --git a/truthinquiry/static/css/game_ui_game.css b/truthinquiry/static/css/game_ui_game.css index 657f08c..e6718ef 100644 --- a/truthinquiry/static/css/game_ui_game.css +++ b/truthinquiry/static/css/game_ui_game.css @@ -133,9 +133,10 @@ height: 6em; background-color: #000000d0; } -.suspect_picture:hover { +.suspect > .suspect_picture:hover { filter: grayscale(0); transition: all 0.5s ease; + background-color: #000000d0; } .suspect_picture[alt] { @@ -148,7 +149,7 @@ background-color: #000000d0; } .home_button, .next_btn { - fill: var(--game-red); + fill: var(--game-dark-gold); height: 5em; width: 5em; } diff --git a/truthinquiry/static/css/game_ui_lobby.css b/truthinquiry/static/css/game_ui_lobby.css index f53a8ba..8c7d4b3 100644 --- a/truthinquiry/static/css/game_ui_lobby.css +++ b/truthinquiry/static/css/game_ui_lobby.css @@ -25,7 +25,7 @@ html { } .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 { diff --git a/truthinquiry/static/css/game_ui_start.css b/truthinquiry/static/css/game_ui_start.css index 8f4e844..6d2802d 100644 --- a/truthinquiry/static/css/game_ui_start.css +++ b/truthinquiry/static/css/game_ui_start.css @@ -50,7 +50,7 @@ input::placeholder { } .back_btn { - fill: var(--game-red); + fill: var(--game-dark-gold); } .game_begin { @@ -58,6 +58,7 @@ input::placeholder { background-position: center; background-repeat: no-repeat; background-size: cover; + border: var(--game-gold) solid 1px; border-radius: 1.5em; flex-wrap: wrap; /* @@ -66,7 +67,6 @@ input::placeholder { */ height: calc(100vh - var(--body-margin) * 2 - var(--game-begin-margin) * 2 - - var(--header-actions-side) - var(--footer-links-height)); justify-content: center; margin: var(--game-begin-margin); diff --git a/truthinquiry/static/js/game.js b/truthinquiry/static/js/game.js index bca6fd3..4cdd50b 100644 --- a/truthinquiry/static/js/game.js +++ b/truthinquiry/static/js/game.js @@ -3,6 +3,7 @@ const INTERROGATION_IMAGE_PATH = "/static/images/salle-interrogation.png"; const RESULTS_IMAGE_PATH = "/static/images/salle-resultats.png"; const NPC_REACTION_PATH = "/api/v1/getNpcReaction?npcid="; const NPC_IMAGE_PATH = "/api/v1/getNpcImage?npcid="; +const NPC_FINAL_REACTION_PATH = "/api/v1/getReaction?uuid=" let npcsIds = []; let gameData = {}; @@ -408,6 +409,7 @@ function initSock() { }); socket.on("gamefinished", finalResults => { + console.log(finalResults); hideFirstClassElement("emotion_and_culprit_choices"); const revealScoreElement = document.createElement("h2"); revealScoreElement.classList.add("reveal_score"); @@ -458,7 +460,7 @@ function initSock() { const img = document.createElement("img"); 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); const explain = document.createElement("div") diff --git a/truthinquiry/static/js/game_start_page.js b/truthinquiry/static/js/game_start_page.js index 20e5e3f..e22eb10 100644 --- a/truthinquiry/static/js/game_start_page.js +++ b/truthinquiry/static/js/game_start_page.js @@ -281,4 +281,4 @@ document.getElementById("join_room_button").addEventListener("click", joinMultiP // Execution of functions -setCurrentTheme(); +//setCurrentTheme(); diff --git a/truthinquiry/templates/index.html b/truthinquiry/templates/index.html index 82243e4..5de9b8a 100644 --- a/truthinquiry/templates/index.html +++ b/truthinquiry/templates/index.html @@ -17,15 +17,6 @@