finished lobby
This commit is contained in:
parent
2282a5b91a
commit
18e2a3f30b
@ -63,6 +63,19 @@ def join_game():
|
|||||||
|
|
||||||
return {"error": 0}
|
return {"error": 0}
|
||||||
|
|
||||||
|
@routes_api.route("/isOwner", methods=["GET", "POST"])
|
||||||
|
def is_owner():
|
||||||
|
if not flask.session:
|
||||||
|
return {"error": 0, "owner": False}
|
||||||
|
game = game_logic.get_game(flask.session["game_id"])
|
||||||
|
if game == None:
|
||||||
|
return {"error": 0, "owner": False}
|
||||||
|
|
||||||
|
if not flask.session["is_owner"]:
|
||||||
|
return {"error": 0, "owner": False}
|
||||||
|
|
||||||
|
return {"error": 0, "owner": True}
|
||||||
|
|
||||||
@routes_api.route("/hasJoined", methods=["GET", "POST"])
|
@routes_api.route("/hasJoined", methods=["GET", "POST"])
|
||||||
def has_joined():
|
def has_joined():
|
||||||
if not flask.session:
|
if not flask.session:
|
||||||
|
@ -58,7 +58,7 @@ function displayJoinRoomView() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function addJoinRoomView() {
|
function hideJoinRoomView() {
|
||||||
document.getElementsByClassName("join_room_view")[0].classList.add("hidden");
|
document.getElementsByClassName("join_room_view")[0].classList.add("hidden");
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@ -115,10 +115,8 @@ function startChallengeGame() {
|
|||||||
// Join room functions
|
// Join room functions
|
||||||
|
|
||||||
function joinRoom() {
|
function joinRoom() {
|
||||||
unsetListenerToJoinRoomButton();
|
|
||||||
if (isNickNameInvalid()) {
|
if (isNickNameInvalid()) {
|
||||||
displayInvalidNickNameErrorMessage("Le nom saisi n'est pas valide.");
|
displayInvalidNickNameErrorMessage("Le nom saisi n'est pas valide.");
|
||||||
setListenerToJoinRoomButton();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,7 +128,8 @@ function joinRoom() {
|
|||||||
response.then((value)=>{
|
response.then((value)=>{
|
||||||
displayRoomView();
|
displayRoomView();
|
||||||
displayPlayerList();
|
displayPlayerList();
|
||||||
displayJoinRoomView();
|
initSock();
|
||||||
|
hideJoinRoomView();
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
// Room code functions
|
// Room code functions
|
||||||
@ -230,9 +229,9 @@ function unsetListenerToCopyCodeButton() {
|
|||||||
|
|
||||||
// Utility functions
|
// Utility functions
|
||||||
|
|
||||||
function isRoomOwner() {
|
async function isRoomOwner() {
|
||||||
//FIXME: check if player is room owner
|
response = await makeAPIRequest("isOwner");
|
||||||
return true;
|
return response["owner"];
|
||||||
}
|
}
|
||||||
|
|
||||||
async function hasJoinedRoom() {
|
async function hasJoinedRoom() {
|
||||||
@ -319,6 +318,24 @@ function getRoomCode() {
|
|||||||
return gameid;
|
return gameid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function initSock(){
|
||||||
|
socket = io({
|
||||||
|
auth:{
|
||||||
|
game_id: gameid
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
socket.on("connect", () => {
|
||||||
|
console.log("Connected !")
|
||||||
|
})
|
||||||
|
|
||||||
|
socket.on("playersjoin", (username) => {
|
||||||
|
console.log(`${username} joined`);
|
||||||
|
player_list = document.getElementsByClassName("player_names")[0];
|
||||||
|
player_list.appendChild(document.createTextNode(username)+"\n");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Lobby initialization
|
// Lobby initialization
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -338,25 +355,11 @@ function getRoomCode() {
|
|||||||
async function initLobby() {
|
async function initLobby() {
|
||||||
|
|
||||||
gameid = getRoomCode();
|
gameid = getRoomCode();
|
||||||
socket = io({
|
|
||||||
auth:{
|
|
||||||
game_id: gameid
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
socket.on("connect", () => {
|
|
||||||
console.log("Connected !")
|
|
||||||
})
|
|
||||||
|
|
||||||
socket.on("playersjoin", (username) => {
|
|
||||||
console.log(`${username} joined`);
|
|
||||||
player_list = document.getElementsByClassName("player_names")[0];
|
|
||||||
player_list.appendChild(document.createTextNode(username));
|
|
||||||
});
|
|
||||||
|
|
||||||
if (await hasJoinedRoom()) {
|
if (await hasJoinedRoom()) {
|
||||||
|
initSock();
|
||||||
displayRoomView();
|
displayRoomView();
|
||||||
if (isRoomOwner()) {
|
if (await isRoomOwner()) {
|
||||||
displayRoomCode();
|
displayRoomCode();
|
||||||
displayMultiPlayerModeChoices();
|
displayMultiPlayerModeChoices();
|
||||||
setListenersToGameButtons();
|
setListenersToGameButtons();
|
||||||
|
Loading…
Reference in New Issue
Block a user