'fixed' cors not allowing localhost, incorect type comparaison in get_player_results, Finished sendAnswers in js
This commit is contained in:
parent
e763c71a59
commit
18fed88aa5
@ -23,7 +23,7 @@ class TruthSeekerApp(flask.Flask):
|
|||||||
|
|
||||||
self.config["SECRET_KEY"] = os.getenv("FLASK_SECRET")
|
self.config["SECRET_KEY"] = os.getenv("FLASK_SECRET")
|
||||||
|
|
||||||
self.socketio_app = SocketIO(self,cors_allowed_origins=["https://truthinquiry.simailadjalim.fr"])
|
self.socketio_app = SocketIO(self,cors_allowed_origins=["https://truthinquiry.simailadjalim.fr","http://127.0.0.1:5000"])
|
||||||
|
|
||||||
self.discord_bot = discord_bot.DiscordBot()
|
self.discord_bot = discord_bot.DiscordBot()
|
||||||
token = os.getenv("DISCORD_BOT_TOKEN")
|
token = os.getenv("DISCORD_BOT_TOKEN")
|
||||||
|
@ -78,7 +78,7 @@ class Game:
|
|||||||
traitId = self.reaction_table[npc_id]
|
traitId = self.reaction_table[npc_id]
|
||||||
trait = get_trait_from_trait_id(traitId)
|
trait = get_trait_from_trait_id(traitId)
|
||||||
npcs[npc_id]["reaction"] = get_text_from_lid("FR",trait.NAME_LID)
|
npcs[npc_id]["reaction"] = get_text_from_lid("FR",trait.NAME_LID)
|
||||||
npcs[npc_id]["description"] = get_reaction_description("FR",trait.TRAIT_ID)
|
npcs[npc_id]["description"] = get_reaction_description("FR",npc_id,trait.TRAIT_ID)
|
||||||
player_results = data["player"] = {}
|
player_results = data["player"] = {}
|
||||||
for member in self.members:
|
for member in self.members:
|
||||||
player_results[member.username] = member.results
|
player_results[member.username] = member.results
|
||||||
@ -90,6 +90,7 @@ class Game:
|
|||||||
"""
|
"""
|
||||||
#TODO Get language from player
|
#TODO Get language from player
|
||||||
self.gamedata, self.reaction_table = generate_game_data("FR")
|
self.gamedata, self.reaction_table = generate_game_data("FR")
|
||||||
|
self.gamedata["game_id"] = self.game_id
|
||||||
|
|
||||||
def get_member(self, username: str) -> Union[Member, None]:
|
def get_member(self, username: str) -> Union[Member, None]:
|
||||||
"""
|
"""
|
||||||
@ -132,7 +133,7 @@ class Game:
|
|||||||
try:
|
try:
|
||||||
for npc_id in responses:
|
for npc_id in responses:
|
||||||
trait_id = get_trait_id_from_string(responses[npc_id])
|
trait_id = get_trait_id_from_string(responses[npc_id])
|
||||||
results[npc_id] = trait_id == str(self.reaction_table[npc_id])
|
results[npc_id] = trait_id == self.reaction_table[npc_id]
|
||||||
return results
|
return results
|
||||||
except:
|
except:
|
||||||
return False
|
return False
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
var npcs_ids = []
|
var npcs_ids = []
|
||||||
var gamedata = {}
|
var gamedata = {}
|
||||||
var button = ""
|
|
||||||
|
|
||||||
function showInterogation(){
|
function showInterogation(){
|
||||||
document.getElementsByClassName("interrogation")[0].classList.remove("hidden");
|
document.getElementsByClassName("interrogation")[0].classList.remove("hidden");
|
||||||
@ -40,6 +39,19 @@ function showEmotionAndCulpritChoicesView(){
|
|||||||
showEmotionAndCulpritChoices();
|
showEmotionAndCulpritChoices();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async function sendAnswers(){
|
||||||
|
selects = document.getElementsByClassName("suspect_emotion_chooser");
|
||||||
|
let playerResponses = {}
|
||||||
|
for (let index = 0; index < selects.length; index++) {
|
||||||
|
select = selects[index];
|
||||||
|
playerResponses[select.id] = select.value
|
||||||
|
}
|
||||||
|
data = {};
|
||||||
|
data["responses"] = JSON.stringify(playerResponses);
|
||||||
|
return await makeAPIRequest("submitAnswers",data);
|
||||||
|
}
|
||||||
|
|
||||||
function renderAnswerSelectionPanel() {
|
function renderAnswerSelectionPanel() {
|
||||||
npcs_ids.forEach(element => {
|
npcs_ids.forEach(element => {
|
||||||
let suspect = document.createElement("div");
|
let suspect = document.createElement("div");
|
||||||
@ -47,6 +59,7 @@ function renderAnswerSelectionPanel() {
|
|||||||
|
|
||||||
suspect_emotion_chooser = document.createElement("select");
|
suspect_emotion_chooser = document.createElement("select");
|
||||||
suspect_emotion_chooser.classList.add("suspect_emotion_chooser")
|
suspect_emotion_chooser.classList.add("suspect_emotion_chooser")
|
||||||
|
suspect_emotion_chooser.setAttribute("id",element);
|
||||||
gamedata["traits"].forEach(trait =>{
|
gamedata["traits"].forEach(trait =>{
|
||||||
let option = document.createElement("option");
|
let option = document.createElement("option");
|
||||||
option.value = trait;
|
option.value = trait;
|
||||||
@ -61,6 +74,7 @@ function renderAnswerSelectionPanel() {
|
|||||||
suspect.appendChild(img);
|
suspect.appendChild(img);
|
||||||
let button = document.getElementById("culpritButton");
|
let button = document.getElementById("culpritButton");
|
||||||
let button_clone = button.cloneNode(true);
|
let button_clone = button.cloneNode(true);
|
||||||
|
button_clone.removeAttribute("id");
|
||||||
button_clone.classList.remove("hidden");
|
button_clone.classList.remove("hidden");
|
||||||
suspect.appendChild(button_clone);
|
suspect.appendChild(button_clone);
|
||||||
document.getElementById("culprits_choices").appendChild(suspect);
|
document.getElementById("culprits_choices").appendChild(suspect);
|
||||||
@ -87,7 +101,7 @@ function renderInterogation(){
|
|||||||
function initSock(){
|
function initSock(){
|
||||||
socket = io({
|
socket = io({
|
||||||
auth:{
|
auth:{
|
||||||
game_id: gameid
|
game_id: gamedata["game_id"]
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -98,6 +112,10 @@ function initSock(){
|
|||||||
socket.on("gameprogress", (username) => {
|
socket.on("gameprogress", (username) => {
|
||||||
console.log(username);
|
console.log(username);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
socket.on("gamefinshed", (finalResults) => {
|
||||||
|
console.log(finalResults);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function setGameData(){
|
async function setGameData(){
|
||||||
@ -109,7 +127,7 @@ async function setGameData(){
|
|||||||
|
|
||||||
async function initGame(){
|
async function initGame(){
|
||||||
await setGameData();
|
await setGameData();
|
||||||
//initSock();
|
initSock();
|
||||||
renderAnswerSelectionPanel();
|
renderAnswerSelectionPanel();
|
||||||
renderInterogation();
|
renderInterogation();
|
||||||
setListenerToIntroductionNextBtn()
|
setListenerToIntroductionNextBtn()
|
||||||
|
Loading…
Reference in New Issue
Block a user