- remove useless file
    - remove some console.log/warn/error
    - add try/catch
This commit is contained in:
Kum1ta
2024-11-20 23:16:16 +01:00
parent cf324a7b0c
commit 745855d41c
6 changed files with 28 additions and 120 deletions

View File

@ -1,96 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* showActualGameMessage.js :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/04 19:21:55 by edbernar #+# #+# */
/* Updated: 2024/08/24 23:28:45 by edbernar ### ########.fr */
/* */
/* ************************************************************************** */
import { sendRequest } from "/static/javascript/websocket.js";
function showActualGameMessage()
{
const divMessageListChatHome = document.getElementById("messageListChatHome");
let newDiv = null;
let contentNode = null;
let dateNode = null;
let tmp = null;
let me = "Kumita";
let request = {
isInGame: true,
opponent: {
name: "Astropower",
id: "301547"
},
listMessage: [
{
from: "Astropower",
content: "Hello !",
date: "19:21 30/07/2024"
},
{
from: "Kumita",
content: "Hey",
date: "19:21 30/07/2024"
},
{
from: "Astropower",
content: "Do you want play ?",
date: "19:22 30/07/2024"
},
{
from: "Kumita",
content: "Yes, i'm ready !",
date: "19:22 30/07/2024"
},
{
from: "Kumita",
content: "The game was too hard but well played",
date: "19:27 30/07/2024"
},
{
from: "Astropower",
content: "Yeah but you still won. See you soon",
date: "19:27 30/07/2024"
},
]
}; //Remplace temporairement la requete qui devra être de la meme forme
divMessageListChatHome.style.height = "230px";
divMessageListChatHome.style.paddingBottom = "20px";
divMessageListChatHome.innerHTML = '';
if (request.isInGame === false)
{
divMessageListChatHome.innerHTML = "<p style='text-align: center; margin-top: 20px;'>You are currently not in a game.</p>";
return ;
}
request.listMessage.forEach(element => {
newDiv = document.createElement("div");
contentNode = document.createTextNode(element.content);
dateNode = document.createTextNode(element.date);
newDiv.classList.add(element.from == me ? "meMessage" : "opponentMessage");
tmp = document.createElement("p");
tmp.classList.add("content");
tmp.appendChild(contentNode);
newDiv.appendChild(tmp);
tmp = document.createElement("p");
tmp.classList.add("time");
tmp.appendChild(dateNode);
newDiv.appendChild(tmp);
divMessageListChatHome.appendChild(newDiv);
});
divMessageListChatHome.scrollTop = divMessageListChatHome.scrollHeight;
divMessageListChatHome.innerHTML += `
<div id="inputMessageDiv">
<textarea type="text" id="inputMessage" placeholder="Enter your message here"></textarea>
<p id="sendButton">\></p>
</div>
`;
}
export { showActualGameMessage };

View File

@ -6,7 +6,7 @@
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/22 17:08:46 by madegryc #+# #+# */
/* Updated: 2024/11/18 16:34:25 by edbernar ### ########.fr */
/* Updated: 2024/11/20 23:09:43 by edbernar ### ########.fr */
/* */
/* ************************************************************************** */
@ -196,6 +196,11 @@ function startTournmament()
const code = document.getElementById('tournamentCode').value;
let nbBot = document.getElementById('nbBot').value;
if (isMobile)
{
CN.new("Error", "Tournament not yet available on mobile");
return;
}
if (code != '')
sendRequest("tournament", {action: 0, code: code, skin: lastSelected ? lastSelected.id : 0, goal: goalSelector ? goalSelector.selected : 0});
else

View File

@ -6,7 +6,7 @@
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/20 14:52:55 by hubourge #+# #+# */
/* Updated: 2024/11/20 23:00:52 by edbernar ### ########.fr */
/* Updated: 2024/11/20 23:11:22 by edbernar ### ########.fr */
/* */
/* ************************************************************************** */
@ -585,7 +585,6 @@ class Map
return (0);
}
console.log(path);
// Fill the videoList with the videos
for (let i = startIndex; i < (nbVideos + startIndex); i++)
{
@ -594,7 +593,6 @@ class Map
startIndex++;
continue ;
}
console.log(path[i].name);
let videoTmp = null;
videoTmp = new Video(path[i].src).video;
videoTmp.addEventListener('loadeddata', () => {

View File

@ -6,7 +6,7 @@
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/01 13:42:29 by edbernar #+# #+# */
/* Updated: 2024/11/18 16:35:55 by edbernar ### ########.fr */
/* Updated: 2024/11/20 23:11:35 by edbernar ### ########.fr */
/* */
/* ************************************************************************** */
@ -194,7 +194,6 @@ class TournamentPage
static end(content)
{
console.log("Tournament is over. The winner is : ", playerList['player' + playerNb[content.winnerId]]);
newInfo(`The winner is : ${playerList['player' + playerNb[content.winnerId]].username}`);
timeout = setTimeout(() => {
pageRenderer.changePage("lobbyPage", false);

View File

@ -6,7 +6,7 @@
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/02 01:56:15 by edbernar #+# #+# */
/* Updated: 2024/09/29 03:36:44 by edbernar ### ########.fr */
/* Updated: 2024/11/20 23:11:44 by edbernar ### ########.fr */
/* */
/* ************************************************************************** */
@ -34,7 +34,6 @@ function typePrivateListUser(list) {
if (element.haveUnread)
userListUnread.push(element.id);
});
console.log(userListUnread);
userListAvailable = true;
if (userListResolve)
{

View File

@ -6,7 +6,7 @@
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/31 22:17:24 by edbernar #+# #+# */
/* Updated: 2024/11/18 16:44:34 by edbernar ### ########.fr */
/* Updated: 2024/11/20 23:13:54 by edbernar ### ########.fr */
/* */
/* ************************************************************************** */
@ -67,17 +67,14 @@ function launchSocket()
if (response.code == 9101)
return ;
if (response.code >= 9014 && response.code <= 9025)
{
console.log(response);
CN.new("Error", response.content);
}
else
{
try {
errorFunction[errorCode.indexOf(response.code)]();
} catch ( error )
{
console.warn(response);
// Do nothing
}
}
}
@ -87,8 +84,7 @@ function launchSocket()
functionResponse[typeResponse.indexOf(response.type)](response.content);
} catch (error)
{
console.error(error);
console.warn(response);
// Do nothing
}
}
};
@ -107,7 +103,8 @@ function launchSocket()
};
}
function sendRequest(type, content) {
function sendRequest(type, content)
{
let coc = null;
if (status === 0)
@ -115,14 +112,20 @@ function sendRequest(type, content) {
console.warn('Not connected');
return ;
}
if (content instanceof Object)
coc = JSON.stringify(content);
else
coc = content;
socket.send(JSON.stringify({
type: type,
content: content
}));
try {
if (content instanceof Object)
coc = JSON.stringify(content);
else
coc = content;
socket.send(JSON.stringify({
type: type,
content: content
}));
}
catch (error)
{
// Do nothing
}
}
export { socket, sendRequest, launchSocket, status };