Global
- remove useless file - remove some console.log/warn/error - add try/catch
This commit is contained in:
@ -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 };
|
|
@ -6,7 +6,7 @@
|
|||||||
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
|
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/08/22 17:08:46 by madegryc #+# #+# */
|
/* 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;
|
const code = document.getElementById('tournamentCode').value;
|
||||||
let nbBot = document.getElementById('nbBot').value;
|
let nbBot = document.getElementById('nbBot').value;
|
||||||
|
|
||||||
|
if (isMobile)
|
||||||
|
{
|
||||||
|
CN.new("Error", "Tournament not yet available on mobile");
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (code != '')
|
if (code != '')
|
||||||
sendRequest("tournament", {action: 0, code: code, skin: lastSelected ? lastSelected.id : 0, goal: goalSelector ? goalSelector.selected : 0});
|
sendRequest("tournament", {action: 0, code: code, skin: lastSelected ? lastSelected.id : 0, goal: goalSelector ? goalSelector.selected : 0});
|
||||||
else
|
else
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
|
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/08/20 14:52:55 by hubourge #+# #+# */
|
/* 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);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(path);
|
|
||||||
// Fill the videoList with the videos
|
// Fill the videoList with the videos
|
||||||
for (let i = startIndex; i < (nbVideos + startIndex); i++)
|
for (let i = startIndex; i < (nbVideos + startIndex); i++)
|
||||||
{
|
{
|
||||||
@ -594,7 +593,6 @@ class Map
|
|||||||
startIndex++;
|
startIndex++;
|
||||||
continue ;
|
continue ;
|
||||||
}
|
}
|
||||||
console.log(path[i].name);
|
|
||||||
let videoTmp = null;
|
let videoTmp = null;
|
||||||
videoTmp = new Video(path[i].src).video;
|
videoTmp = new Video(path[i].src).video;
|
||||||
videoTmp.addEventListener('loadeddata', () => {
|
videoTmp.addEventListener('loadeddata', () => {
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
|
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/10/01 13:42:29 by edbernar #+# #+# */
|
/* 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)
|
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}`);
|
newInfo(`The winner is : ${playerList['player' + playerNb[content.winnerId]].username}`);
|
||||||
timeout = setTimeout(() => {
|
timeout = setTimeout(() => {
|
||||||
pageRenderer.changePage("lobbyPage", false);
|
pageRenderer.changePage("lobbyPage", false);
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
|
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/08/02 01:56:15 by edbernar #+# #+# */
|
/* 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)
|
if (element.haveUnread)
|
||||||
userListUnread.push(element.id);
|
userListUnread.push(element.id);
|
||||||
});
|
});
|
||||||
console.log(userListUnread);
|
|
||||||
userListAvailable = true;
|
userListAvailable = true;
|
||||||
if (userListResolve)
|
if (userListResolve)
|
||||||
{
|
{
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
|
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/07/31 22:17:24 by edbernar #+# #+# */
|
/* 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)
|
if (response.code == 9101)
|
||||||
return ;
|
return ;
|
||||||
if (response.code >= 9014 && response.code <= 9025)
|
if (response.code >= 9014 && response.code <= 9025)
|
||||||
{
|
|
||||||
console.log(response);
|
|
||||||
CN.new("Error", response.content);
|
CN.new("Error", response.content);
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
errorFunction[errorCode.indexOf(response.code)]();
|
errorFunction[errorCode.indexOf(response.code)]();
|
||||||
} catch ( error )
|
} catch ( error )
|
||||||
{
|
{
|
||||||
console.warn(response);
|
// Do nothing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -87,8 +84,7 @@ function launchSocket()
|
|||||||
functionResponse[typeResponse.indexOf(response.type)](response.content);
|
functionResponse[typeResponse.indexOf(response.type)](response.content);
|
||||||
} catch (error)
|
} catch (error)
|
||||||
{
|
{
|
||||||
console.error(error);
|
// Do nothing
|
||||||
console.warn(response);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -107,7 +103,8 @@ function launchSocket()
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendRequest(type, content) {
|
function sendRequest(type, content)
|
||||||
|
{
|
||||||
let coc = null;
|
let coc = null;
|
||||||
|
|
||||||
if (status === 0)
|
if (status === 0)
|
||||||
@ -115,14 +112,20 @@ function sendRequest(type, content) {
|
|||||||
console.warn('Not connected');
|
console.warn('Not connected');
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
if (content instanceof Object)
|
try {
|
||||||
coc = JSON.stringify(content);
|
if (content instanceof Object)
|
||||||
else
|
coc = JSON.stringify(content);
|
||||||
coc = content;
|
else
|
||||||
socket.send(JSON.stringify({
|
coc = content;
|
||||||
type: type,
|
socket.send(JSON.stringify({
|
||||||
content: content
|
type: type,
|
||||||
}));
|
content: content
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
catch (error)
|
||||||
|
{
|
||||||
|
// Do nothing
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export { socket, sendRequest, launchSocket, status };
|
export { socket, sendRequest, launchSocket, status };
|
Reference in New Issue
Block a user