From ed8b928ebc9d0cfc8182a9f5f12af81a9fe76ff3 Mon Sep 17 00:00:00 2001 From: Djalim Simaila Date: Fri, 31 Mar 2023 07:41:49 +0200 Subject: [PATCH] hide button on solo game + fixed player list updates in lobby + fixed joining a already started game --- truthinquiry/routes/routes_api.py | 4 ++++ truthinquiry/static/css/game_ui_game.css | 2 +- truthinquiry/static/js/game.js | 2 ++ truthinquiry/static/js/game_lobby.js | 11 ++++++----- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/truthinquiry/routes/routes_api.py b/truthinquiry/routes/routes_api.py index 779697f..b4cf098 100644 --- a/truthinquiry/routes/routes_api.py +++ b/truthinquiry/routes/routes_api.py @@ -85,6 +85,10 @@ def join_game(): if not game.add_member(username): return {"error": 1, "msg": f"Username '{username}' already used in game {game.game_id}"} + + if game.has_started: + return {"error": 1, "msg": f"Game {game.game_id} has already started"} + flask.session["game_id"] = game.game_id flask.session["is_owner"] = False diff --git a/truthinquiry/static/css/game_ui_game.css b/truthinquiry/static/css/game_ui_game.css index e3caaa7..657f08c 100644 --- a/truthinquiry/static/css/game_ui_game.css +++ b/truthinquiry/static/css/game_ui_game.css @@ -129,7 +129,7 @@ html { .question_answer{ border: var(--game-dark-gold) solid; border-radius: 1em; -height: 5em; +height: 6em; background-color: #000000d0; } diff --git a/truthinquiry/static/js/game.js b/truthinquiry/static/js/game.js index 35ef4c6..bca6fd3 100644 --- a/truthinquiry/static/js/game.js +++ b/truthinquiry/static/js/game.js @@ -317,6 +317,8 @@ function createCulpritSvgElement(buttonCssClass, pathAttributeValue, isHidden) { * Show the screen in which the player asks questions to the npcs. */ function renderInterrogation() { + if (gameData["solo"] === true) document.getElementById("open_chat_button").classList.add("hidden"); + document.getElementById("QA_0").textContent = gameData["questions"]["QA_0"]; document.getElementById("QA_1").textContent = gameData["questions"]["QA_1"]; diff --git a/truthinquiry/static/js/game_lobby.js b/truthinquiry/static/js/game_lobby.js index 5f67aac..949b4ae 100644 --- a/truthinquiry/static/js/game_lobby.js +++ b/truthinquiry/static/js/game_lobby.js @@ -137,7 +137,6 @@ function joinRoom() { response.then(() => { displayRoomView(); displayPlayerList(); - initSock(); hideFirstClassElement("join_room_view"); }) } @@ -356,13 +355,15 @@ function initSock() { console.log("Connected to the server!"); }) - socket.on("gamestart", () => { - window.location.href = "/multi"; + socket.on("gamestart", async () => { + if (await hasJoinedRoom()) window.location.href = "/multi"; }) socket.on("playersjoin", username => { console.log(username); - document.querySelector(".player_names").textContent += username + "\n"; + Array.from(document.getElementsByClassName("player_names")).forEach(playerList =>{ + playerList.textContent += username + "\n"; + }) }); } @@ -385,8 +386,8 @@ function initSock() { async function initLobby() { setGameBackground(LOBBY_IMAGE_PATH) getMembers() + initSock(); if (await hasJoinedRoom()) { - initSock(); displayRoomView(); if (await isRoomOwner()) {