From d29c58ae42f06e07c9e4aad286ad3f72872fb52e Mon Sep 17 00:00:00 2001 From: Kum1ta Date: Sat, 21 Sep 2024 23:14:27 +0200 Subject: [PATCH] Site - Add notif for new message - remove buttons "private" and "game" in chat - add function on button newConv in profilPage - fix camera who change position (2 to 1.5 in z axe) when a goal is scored - fix some bug in responses functions - add button chat in profil page and lobby page --- .../djangoserver/file/server/server/models.py | 1 - .../server/server/templates/homePage.html | 4 +- .../server/server/templates/lobbyPage.html | 15 +++++ .../server/server/templates/profilPage.html | 21 +++++- .../nginx/static/javascript/liveChat/main.js | 62 ++--------------- .../javascript/liveChat/showPrivateChat.js | 58 ++++++---------- .../javascript/liveChat/showUserList.js | 66 ++++++++----------- .../nginx/static/javascript/lobbyPage/main.js | 8 ++- .../javascript/multiOnlineGame/Player.js | 10 ++- .../multiOnlineGame/multiOnlineGamePage.js | 2 +- .../static/javascript/notification/main.js | 7 +- .../static/javascript/profilPage/main.js | 27 +++++--- .../javascript/typeResponse/typeGame.js | 4 +- .../typeResponse/typeNewPrivateMessage.js | 16 +++-- .../typeResponse/typePrivateListUser.js | 8 ++- .../javascript/typeResponse/typeUserInfo.js | 6 +- .../static/javascript/waitingGame/main.js | 13 +++- 17 files changed, 161 insertions(+), 167 deletions(-) diff --git a/docker-compose/requirements/djangoserver/file/server/server/models.py b/docker-compose/requirements/djangoserver/file/server/server/models.py index 8050b77..0de4e18 100644 --- a/docker-compose/requirements/djangoserver/file/server/server/models.py +++ b/docker-compose/requirements/djangoserver/file/server/server/models.py @@ -11,7 +11,6 @@ class User(models.Model): mail_verified = models.BooleanField(default=False) github_link = models.CharField(max_length=1024, null=True, blank=True, default=None) discord_username = models.CharField(max_length=1024, null=True, blank=True, default=None) - elo = models.DecimalField(max_digits=10, decimal_places=0, default=1000) class Message(models.Model): diff --git a/docker-compose/requirements/djangoserver/file/server/server/templates/homePage.html b/docker-compose/requirements/djangoserver/file/server/server/templates/homePage.html index 3e2f273..2fcb5c5 100644 --- a/docker-compose/requirements/djangoserver/file/server/server/templates/homePage.html +++ b/docker-compose/requirements/djangoserver/file/server/server/templates/homePage.html @@ -75,7 +75,9 @@

Chat

×
-

You are not connected to the chat

+
+

You are not connected to the chat

+
diff --git a/docker-compose/requirements/djangoserver/file/server/server/templates/lobbyPage.html b/docker-compose/requirements/djangoserver/file/server/server/templates/lobbyPage.html index b3cdf3f..45901f3 100644 --- a/docker-compose/requirements/djangoserver/file/server/server/templates/lobbyPage.html +++ b/docker-compose/requirements/djangoserver/file/server/server/templates/lobbyPage.html @@ -14,6 +14,19 @@

Logout

+
+ + +
+
+
+

Chat

+
×
+
+
+

You are not connected to the chat

+
+
- - - + + +
@@ -25,4 +25,19 @@ + +
+ + +
+
+
+

Chat

+
×
+
+
+

You are not connected to the chat

+
+
+
\ No newline at end of file diff --git a/docker-compose/requirements/nginx/static/javascript/liveChat/main.js b/docker-compose/requirements/nginx/static/javascript/liveChat/main.js index 2cd0082..86556c2 100644 --- a/docker-compose/requirements/nginx/static/javascript/liveChat/main.js +++ b/docker-compose/requirements/nginx/static/javascript/liveChat/main.js @@ -6,7 +6,7 @@ /* By: edbernar { - newGameButton.removeAttribute("id"); - newPrivateButton.setAttribute("id", "selected"); - await showListUser(); - }); - newGameButton.addEventListener("click", () => { - newPrivateButton.removeAttribute("id"); - newGameButton.setAttribute("id", "selected"); - showActualGameMessage(); - }); -} - -function removeButtonIfExist() -{ - const divButtonTypeChatHome = document.getElementById("buttonTypeChatHome"); - - if (divButtonTypeChatHome) - { - divButtonTypeChatHome.remove(); - document.getElementById("messageListChatHome").remove(); - } -} - -async function showChatMenu() +function showChatMenu() { const infoChat = document.getElementById("infoChat"); chatDiv.style.display = "flex"; if (userMeInfo.id !== -1) - { - if (infoChat) - infoChat.remove(); - removeButtonIfExist(); - addDefaultButton(); - await showListUser(); - } + showListUser(); } function hideChatMenu() { - console.log("hideChatMenu"); chatDiv.style.display = "none"; infoPanel.isOpen = false; } -export { LiveChat }; \ No newline at end of file +export { LiveChat, showChatMenu }; \ No newline at end of file diff --git a/docker-compose/requirements/nginx/static/javascript/liveChat/showPrivateChat.js b/docker-compose/requirements/nginx/static/javascript/liveChat/showPrivateChat.js index f113640..b090259 100644 --- a/docker-compose/requirements/nginx/static/javascript/liveChat/showPrivateChat.js +++ b/docker-compose/requirements/nginx/static/javascript/liveChat/showPrivateChat.js @@ -6,7 +6,7 @@ /* By: edbernar { + infoPanel.id = user.id; + infoPanel.isOpen = true; + infoPanel.divMessage = divMessageListChatHome; + changeButton(user); + displayAllMessage(divMessageListChatHome); + displayInputBar(divMessageListChatHome, user); + + }) } -async function restoreButton() +function changeButton(user) { - const divButtonTypeChatHome = document.getElementById("buttonTypeChatHome"); - - divButtonTypeChatHome.innerHTML = ''; - savedButtons.forEach(element => { - divButtonTypeChatHome.appendChild(element); - }); -} - -async function changeButton(user) -{ - const divButtonTypeChatHome = document.getElementById("buttonTypeChatHome"); + const divMessageListChatHome = document.getElementById("messageListChatHome"); const h2Username = document.createElement("h2"); const h2UsernameNode = document.createTextNode(user.name); + const div = document.createElement('div'); let returnButton = null; - let h2Button = null; - let lenh2Button = 0; - h2Button = divButtonTypeChatHome.getElementsByTagName("h2"); - lenh2Button = h2Button.length; - savedButtons.splice(0, savedButtons.length); - for (let i = 0; i < lenh2Button; i++) { - savedButtons.push(h2Button[0]); - h2Button[0].remove(); - } - h2Username.appendChild(h2UsernameNode); - divButtonTypeChatHome.appendChild(h2Username); - divButtonTypeChatHome .innerHTML += ` + divMessageListChatHome.before(div); + div.innerHTML += `

Return

`; - h2Button[0].style.cursor = "default"; + div.setAttribute('id', 'buttonTypeChatHome'); + h2Username.appendChild(h2UsernameNode); returnButton = document.getElementById("returnButton"); + returnButton.before(h2Username); returnButton.style.cursor = "pointer"; returnButton.addEventListener("click", () => { - restoreButton(); infoPanel.isOpen = false; showListUser(); }); } -async function displayAllMessage(divMessageListChatHome) +function displayAllMessage(divMessageListChatHome) { let newDiv = null; let contentNode = null; @@ -100,7 +84,7 @@ async function displayAllMessage(divMessageListChatHome) divMessageListChatHome.scrollTop = divMessageListChatHome.scrollHeight; } -async function displayInputBar(divMessageListChatHome, user) +function displayInputBar(divMessageListChatHome, user) { let sendButton; let inputMessage; diff --git a/docker-compose/requirements/nginx/static/javascript/liveChat/showUserList.js b/docker-compose/requirements/nginx/static/javascript/liveChat/showUserList.js index 5293e76..f82c2c0 100644 --- a/docker-compose/requirements/nginx/static/javascript/liveChat/showUserList.js +++ b/docker-compose/requirements/nginx/static/javascript/liveChat/showUserList.js @@ -6,7 +6,7 @@ /* By: edbernar { - let user = document.createElement("div"); - user.classList.add("user"); - user.innerHTML = ` -
- -
-

- ` - user.querySelector("img").src = element.pfp; - user.querySelector("h3").innerText = element.name; - divMessageListChatHome.appendChild(user); - }); - } - divMessageListChatHome.innerHTML += "

New conversation +

"; - divUser = document.getElementsByClassName("user"); - for (let i = 0; i < divUser.length; i++) { - divUser[i].addEventListener("click", async () => { - await showPrivateChat(userList[i]); - }); - } - document.getElementById('newConversation').addEventListener('mouseup', () => { - divMessageListChatHome.innerText = 'Loading...'; - sendRequest("get_all_list_user", {}); - waitForallListUser().then((listUser) => { - divMessageListChatHome.innerText = 'User list :\n'; - listUser.forEach(element => { + waitForUserList().then((userList) => { + if (!userList.length) + infoChat.innerText = "No conversation" + else + { + divMessageListChatHome.style.height = "100%"; + divMessageListChatHome.style.paddingBottom = "10px"; + divMessageListChatHome.innerHTML = ''; + divMessageListChatHome.scrollTop = 0; + if (infoChat) + infoChat.remove(); + if (buttons) + buttons.remove(); + userList.forEach(element => { let user = document.createElement("div"); user.classList.add("user"); user.innerHTML = ` @@ -63,12 +46,17 @@ async function showListUser() {

` - user.querySelector("img").src = element.pfp; user.querySelector("h3").innerText = element.name; divMessageListChatHome.appendChild(user); - }) - }) + }); + divUser = divMessageListChatHome.children; + for (let i = 0; i < divUser.length; i++) { + divUser[i].addEventListener("click", async () => { + showPrivateChat(userList[i]); + }); + } + } }); } diff --git a/docker-compose/requirements/nginx/static/javascript/lobbyPage/main.js b/docker-compose/requirements/nginx/static/javascript/lobbyPage/main.js index 6a11fdd..6905d14 100644 --- a/docker-compose/requirements/nginx/static/javascript/lobbyPage/main.js +++ b/docker-compose/requirements/nginx/static/javascript/lobbyPage/main.js @@ -6,12 +6,13 @@ /* By: edbernar usernameP.innerHTML = userMeInfo.username); else usernameP.innerHTML = userMeInfo.username; + LiveChat.create(); inputUser.addEventListener('input', searchUser); loginButton.addEventListener('click', showMenu); window.addEventListener('resize', movePopMenuLoginButton); window.addEventListener('resize', ajustSearchUserList); movePopMenuLoginButton(); initButtonPopMenuLogin(); - window.addEventListener('click', closePopUpWhenClickOutsite); listSelectCard = document.getElementsByClassName('select-card'); document.getElementsByClassName('game-mode')[0].addEventListener('click', showGameMode); @@ -79,7 +80,8 @@ class LobbyPage document.getElementsByClassName('game-mode')[0].removeEventListener('click', showGameMode); document.getElementById('closePopupBtn').removeEventListener('click', hideGameMode); window.removeEventListener('resize', ajustSearchUserList); - + LiveChat.dispose(); + listSelectCard[0].removeEventListener('click', selectGameModeOne); listSelectCard[1].removeEventListener('click', selectGameModeTwo); listSelectCard[2].removeEventListener('click', selectGameModeThree); diff --git a/docker-compose/requirements/nginx/static/javascript/multiOnlineGame/Player.js b/docker-compose/requirements/nginx/static/javascript/multiOnlineGame/Player.js index e1f340f..fc723d0 100644 --- a/docker-compose/requirements/nginx/static/javascript/multiOnlineGame/Player.js +++ b/docker-compose/requirements/nginx/static/javascript/multiOnlineGame/Player.js @@ -6,7 +6,7 @@ /* By: edbernar { + this.mapVar.putVideoOnCanvas(0, null); + }, 4000); if (isOpponent) { this.mapVar.reCreate("opponent"); @@ -166,7 +170,7 @@ class Player this.setCameraPosition( this.object.position.x, this.object.position.y - (this.object.position.y >= this.limits.up ? 0.7 : -0.7), - this.object.position.z + 2 + this.object.position.z + 1.5 ); } document.getElementsByTagName('canvas')[0].style.animation = 'fadeOut 0.199s'; @@ -217,7 +221,7 @@ class Player this.setCameraPosition( this.object.position.x, this.object.position.y - (this.object.position.y >= this.limits.up ? 0.7 : -0.7), - this.object.position.z + 2 + this.object.position.z + 1.5 ); } document.getElementsByTagName('canvas')[0].style.animation = 'fadeOut 0.199s'; diff --git a/docker-compose/requirements/nginx/static/javascript/multiOnlineGame/multiOnlineGamePage.js b/docker-compose/requirements/nginx/static/javascript/multiOnlineGame/multiOnlineGamePage.js index 67b631d..7d0321a 100644 --- a/docker-compose/requirements/nginx/static/javascript/multiOnlineGame/multiOnlineGamePage.js +++ b/docker-compose/requirements/nginx/static/javascript/multiOnlineGame/multiOnlineGamePage.js @@ -6,7 +6,7 @@ /* By: edbernar { + usernameText = userInfo.username; username.innerText = userInfo.username + ' (status not implemented)'; pfp.style.backgroundImage = `url("${userInfo.pfp}")` pfp.style.backgroundSize = "cover"; @@ -39,11 +46,15 @@ class ProfilPage banner.innerHTML = `` } }); + convButton.addEventListener('click', () => { + showChatMenu(); + showPrivateChat({id: userId, name: usernameText}); + }); } static dispose() { - + LiveChat.dispose(); } } diff --git a/docker-compose/requirements/nginx/static/javascript/typeResponse/typeGame.js b/docker-compose/requirements/nginx/static/javascript/typeResponse/typeGame.js index 15cc495..d8e58d9 100644 --- a/docker-compose/requirements/nginx/static/javascript/typeResponse/typeGame.js +++ b/docker-compose/requirements/nginx/static/javascript/typeResponse/typeGame.js @@ -6,11 +6,11 @@ /* By: edbernar

${content.content}

@@ -28,6 +29,13 @@ function typeNewPrivateMessage(content) `); infoPanel.divMessage.scrollTop = infoPanel.divMessage.scrollHeight; } + else if (content.from != userMeInfo.id) + { + sendRequest("get_user_info", {id: content.from}); + waitForUserInfo().then((userInfo) => { + CN.new("Message", "New message from " + userInfo.username); + }); + } } export { typeNewPrivateMessage }; \ No newline at end of file diff --git a/docker-compose/requirements/nginx/static/javascript/typeResponse/typePrivateListUser.js b/docker-compose/requirements/nginx/static/javascript/typeResponse/typePrivateListUser.js index 67cbe58..13da394 100644 --- a/docker-compose/requirements/nginx/static/javascript/typeResponse/typePrivateListUser.js +++ b/docker-compose/requirements/nginx/static/javascript/typeResponse/typePrivateListUser.js @@ -6,7 +6,7 @@ /* By: edbernar { if (userListAvailable) - resolve(); + { + userListAvailable = false; + resolve(userList); + } else userListResolve = resolve; }); @@ -30,6 +33,7 @@ function typePrivateListUser(list) { { userListResolve(userList); userListResolve = null; + userListAvailable = false; } } diff --git a/docker-compose/requirements/nginx/static/javascript/typeResponse/typeUserInfo.js b/docker-compose/requirements/nginx/static/javascript/typeResponse/typeUserInfo.js index 62a4015..698f4b8 100644 --- a/docker-compose/requirements/nginx/static/javascript/typeResponse/typeUserInfo.js +++ b/docker-compose/requirements/nginx/static/javascript/typeResponse/typeUserInfo.js @@ -6,7 +6,7 @@ /* By: edbernar { if (userInfoAvailable) + { + userInfoAvailable = false; resolve(userInfo); + } else userInfoResolve = resolve; }); @@ -31,6 +34,7 @@ function typeUserInfo(list) { userInfoResolve(userInfo); userInfoResolve = null; + userInfoAvailable = false; } } diff --git a/docker-compose/requirements/nginx/static/javascript/waitingGame/main.js b/docker-compose/requirements/nginx/static/javascript/waitingGame/main.js index abc2766..c583d1d 100644 --- a/docker-compose/requirements/nginx/static/javascript/waitingGame/main.js +++ b/docker-compose/requirements/nginx/static/javascript/waitingGame/main.js @@ -6,7 +6,7 @@ /* By: edbernar { - sendRequest("game", {action: 0}) + sendRequest("game", {action: 0}); + timeout = null; }, 1500); returnButton.addEventListener('click', returnToLobby); } @@ -83,7 +84,13 @@ class WaitingGamePage function returnToLobby() { - sendRequest("game", {action: 2}); + if (timeout) + { + clearTimeout(timeout); + timeout = null; + } + else + sendRequest("game", {action: 2}); for (let i = 0; i < document.body.children.length; i++) { document.body.children[i].style.animation = "anim3 0.6s";