lobby advancement
This commit is contained in:
parent
3728b2986f
commit
2282a5b91a
@ -26,6 +26,19 @@ def create_game():
|
|||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
@routes_api.route("/getGameMembers", methods=["GET", "POST"])
|
||||||
|
def getMembers():
|
||||||
|
if not flask.session:
|
||||||
|
return {"error": 1, "msg": "No session"}
|
||||||
|
game = game_logic.get_game(flask.session["game_id"])
|
||||||
|
if game == None:
|
||||||
|
return {"error": 1, "msg": "this game doesn't exist"}
|
||||||
|
|
||||||
|
response = {"error" : 0}
|
||||||
|
player_list = [member.username for member in game.members]
|
||||||
|
response["members"] = player_list
|
||||||
|
return response
|
||||||
|
|
||||||
@routes_api.route("/joinGame", methods=["GET", "POST"])
|
@routes_api.route("/joinGame", methods=["GET", "POST"])
|
||||||
def join_game():
|
def join_game():
|
||||||
game_id = flask.request.values.get("game_id")
|
game_id = flask.request.values.get("game_id")
|
||||||
@ -50,6 +63,15 @@ def join_game():
|
|||||||
|
|
||||||
return {"error": 0}
|
return {"error": 0}
|
||||||
|
|
||||||
|
@routes_api.route("/hasJoined", methods=["GET", "POST"])
|
||||||
|
def has_joined():
|
||||||
|
if not flask.session:
|
||||||
|
return {"error": 0, "joined": False}
|
||||||
|
game = game_logic.get_game(flask.session["game_id"])
|
||||||
|
if game == None:
|
||||||
|
return {"error": 0, "joined": False}
|
||||||
|
return {"error": 0, "joined": True}
|
||||||
|
|
||||||
@routes_api.route("/startGame", methods=["GET", "POST"])
|
@routes_api.route("/startGame", methods=["GET", "POST"])
|
||||||
def start_game():
|
def start_game():
|
||||||
if not flask.session:
|
if not flask.session:
|
||||||
|
@ -23,6 +23,14 @@ function displayRoomCode() {
|
|||||||
* Display the players list element.
|
* Display the players list element.
|
||||||
*/
|
*/
|
||||||
function displayPlayerList() {
|
function displayPlayerList() {
|
||||||
|
response = makeAPIRequest("getGameMembers");
|
||||||
|
response.then((value) =>{
|
||||||
|
player_list = document.getElementsByClassName("player_names")[0];
|
||||||
|
value["members"].forEach(username => {
|
||||||
|
player_list.appendChild(document.createTextNode(username+"\n"));
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
document.getElementsByClassName("players_list")[0].classList.remove("hidden");
|
document.getElementsByClassName("players_list")[0].classList.remove("hidden");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,6 +57,10 @@ function displayJoinRoomView() {
|
|||||||
document.getElementsByClassName("join_room_view")[0].classList.remove("hidden");
|
document.getElementsByClassName("join_room_view")[0].classList.remove("hidden");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function addJoinRoomView() {
|
||||||
|
document.getElementsByClassName("join_room_view")[0].classList.add("hidden");
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Show an error message on the first game_start_failed CSS element.
|
* Show an error message on the first game_start_failed CSS element.
|
||||||
*
|
*
|
||||||
@ -111,9 +123,16 @@ function joinRoom() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
hideInvalidNickNameErrorMessage();
|
hideInvalidNickNameErrorMessage();
|
||||||
//TODO: join the game room and handle server errors + connection errors
|
data = {}
|
||||||
|
data["username"] = document.getElementById("game_username").value;
|
||||||
|
data["game_id"] = getRoomCode();
|
||||||
|
response = makeAPIRequest("joinGame",data);
|
||||||
|
response.then((value)=>{
|
||||||
|
displayRoomView();
|
||||||
|
displayPlayerList();
|
||||||
|
displayJoinRoomView();
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Room code functions
|
// Room code functions
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -216,9 +235,9 @@ function isRoomOwner() {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function hasJoinedRoom() {
|
async function hasJoinedRoom() {
|
||||||
//FIXME: check if player has joined the room
|
response = await makeAPIRequest("hasJoined");
|
||||||
return true;
|
return response["joined"];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -297,7 +316,6 @@ function getChallengeModeRoundsCount() {
|
|||||||
*/
|
*/
|
||||||
function getRoomCode() {
|
function getRoomCode() {
|
||||||
gameid = document.getElementById("game_id").value;
|
gameid = document.getElementById("game_id").value;
|
||||||
console.log(gameid);
|
|
||||||
return gameid;
|
return gameid;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -317,7 +335,7 @@ function getRoomCode() {
|
|||||||
* join room button will be set.
|
* join room button will be set.
|
||||||
* </p>
|
* </p>
|
||||||
*/
|
*/
|
||||||
function initLobby() {
|
async function initLobby() {
|
||||||
|
|
||||||
gameid = getRoomCode();
|
gameid = getRoomCode();
|
||||||
socket = io({
|
socket = io({
|
||||||
@ -330,12 +348,13 @@ function initLobby() {
|
|||||||
console.log("Connected !")
|
console.log("Connected !")
|
||||||
})
|
})
|
||||||
|
|
||||||
socket.on("playersjoin", (err) => {
|
socket.on("playersjoin", (username) => {
|
||||||
console.log(`Failed to connect to socket: ${err.message}`);
|
console.log(`${username} joined`);
|
||||||
|
player_list = document.getElementsByClassName("player_names")[0];
|
||||||
|
player_list.appendChild(document.createTextNode(username));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (await hasJoinedRoom()) {
|
||||||
if (hasJoinedRoom()) {
|
|
||||||
displayRoomView();
|
displayRoomView();
|
||||||
if (isRoomOwner()) {
|
if (isRoomOwner()) {
|
||||||
displayRoomCode();
|
displayRoomCode();
|
||||||
|
Loading…
Reference in New Issue
Block a user