hide button on solo game + fixed player list updates in lobby + fixed joining a already started game

This commit is contained in:
Djalim Simaila 2023-03-31 07:41:49 +02:00 committed by Djalim Simaila
parent a66f8e61e6
commit ed8b928ebc
4 changed files with 13 additions and 6 deletions

View File

@ -86,6 +86,10 @@ def join_game():
if not game.add_member(username): if not game.add_member(username):
return {"error": 1, "msg": f"Username '{username}' already used in game {game.game_id}"} 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["game_id"] = game.game_id
flask.session["is_owner"] = False flask.session["is_owner"] = False
flask.session["username"] = username flask.session["username"] = username

View File

@ -129,7 +129,7 @@ html {
.question_answer{ .question_answer{
border: var(--game-dark-gold) solid; border: var(--game-dark-gold) solid;
border-radius: 1em; border-radius: 1em;
height: 5em; height: 6em;
background-color: #000000d0; background-color: #000000d0;
} }

View File

@ -317,6 +317,8 @@ function createCulpritSvgElement(buttonCssClass, pathAttributeValue, isHidden) {
* Show the screen in which the player asks questions to the npcs. * Show the screen in which the player asks questions to the npcs.
*/ */
function renderInterrogation() { 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_0").textContent = gameData["questions"]["QA_0"];
document.getElementById("QA_1").textContent = gameData["questions"]["QA_1"]; document.getElementById("QA_1").textContent = gameData["questions"]["QA_1"];

View File

@ -137,7 +137,6 @@ function joinRoom() {
response.then(() => { response.then(() => {
displayRoomView(); displayRoomView();
displayPlayerList(); displayPlayerList();
initSock();
hideFirstClassElement("join_room_view"); hideFirstClassElement("join_room_view");
}) })
} }
@ -356,13 +355,15 @@ function initSock() {
console.log("Connected to the server!"); console.log("Connected to the server!");
}) })
socket.on("gamestart", () => { socket.on("gamestart", async () => {
window.location.href = "/multi"; if (await hasJoinedRoom()) window.location.href = "/multi";
}) })
socket.on("playersjoin", username => { socket.on("playersjoin", username => {
console.log(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() { async function initLobby() {
setGameBackground(LOBBY_IMAGE_PATH) setGameBackground(LOBBY_IMAGE_PATH)
getMembers() getMembers()
if (await hasJoinedRoom()) {
initSock(); initSock();
if (await hasJoinedRoom()) {
displayRoomView(); displayRoomView();
if (await isRoomOwner()) { if (await isRoomOwner()) {