mirror of
https://github.com/AudebertAdrien/ft_transcendence.git
synced 2025-12-16 14:07:49 +01:00
deb history but still bug
This commit is contained in:
parent
9fe444c65d
commit
a60498a356
@ -46,6 +46,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
// Auto-focus and key handling for AUTH-FORM
|
||||
nicknameInput.focus();
|
||||
nicknameInput.addEventListener('keypress', function (event) {
|
||||
history.pushState({ view: 'auth-form' }, '', `#${'auth-form'}`);
|
||||
if (event.key === 'Enter') {
|
||||
event.preventDefault();
|
||||
checkNicknameButton.click();
|
||||
@ -127,6 +128,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
if (result) {
|
||||
registerForm.style.display = 'none';
|
||||
document.getElementById("post-form-buttons").style.display = 'block';
|
||||
history.pushState({ view: 'post-form-buttons' }, '', `#${'post-form-buttons'}`);
|
||||
} else {
|
||||
alert('Registration failed. Please try again.');
|
||||
}
|
||||
@ -161,6 +163,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
if (result) {
|
||||
loginForm.style.display = 'none';
|
||||
document.getElementById("post-form-buttons").style.display = 'block';
|
||||
history.pushState({ view: 'post-form-buttons' }, '', `#${'post-form-buttons'}`);
|
||||
} else {
|
||||
alert('Authentication failed. Please try again.');
|
||||
}
|
||||
@ -367,12 +370,18 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
if (players === 1) {
|
||||
console.log("Sending token for a quick match game");
|
||||
socket.send(JSON.stringify({ type: 'authenticate', token: token }));
|
||||
/* history.pushState({ view: 'game1' }, '', `#${'game1'}`);
|
||||
console.log("view quick"); */
|
||||
} else if (players === 2) {
|
||||
console.log("Sending tokens for a local game");
|
||||
socket.send(JSON.stringify({ type: 'authenticate2', token_1: token, token_2: token2 }));
|
||||
/* history.pushState({ view: 'game1' }, '', `#${'game1'}`);
|
||||
console.log("view local"); */
|
||||
} else {
|
||||
console.log("Sending token for a tournament game")
|
||||
socket.send(JSON.stringify({ type: 'authenticate3', token: token }));
|
||||
/* history.pushState({ view: 'game1' }, '', `#${'game1'}`);
|
||||
console.log("view tournament"); */
|
||||
}
|
||||
};
|
||||
|
||||
@ -510,15 +519,53 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
function checkForWinner() {
|
||||
if (gameState.player1_score === 3 || gameState.player2_score === 3) {
|
||||
if (saveData.type != "tournoi"){
|
||||
gameControls.style.display = 'flex';
|
||||
homeButton.style.display = 'block';
|
||||
replayButton.style.display = 'none';
|
||||
console.log(saveData.type);
|
||||
if (saveData.type === 'local'){
|
||||
replayButton.style.display = 'block';
|
||||
if (gameContainer.style.display != 'none'){
|
||||
gameControls.style.display = 'flex';
|
||||
homeButton.style.display = 'block';
|
||||
replayButton.style.display = 'none';
|
||||
console.log(saveData.type);
|
||||
if (saveData.type === 'local'){
|
||||
replayButton.style.display = 'block';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const initialView = window.location.hash ? window.location.hash.substring(1) : 'auth-form';
|
||||
|
||||
// Écouteur pour les boutons de retour et d'avance du navigateur
|
||||
window.addEventListener('popstate', (event) => {
|
||||
const view = event.state ? event.state.view : 'auth-form'; // Utilise l'état sauvegardé
|
||||
showSection(view);
|
||||
});
|
||||
|
||||
const sections = {
|
||||
'auth-form': authForm,
|
||||
'register-form': registerForm,
|
||||
'login-form': loginForm,
|
||||
'post-form-buttons': postFormButtons,
|
||||
'game1': gameContainer,
|
||||
'auth-form2': authForm2,
|
||||
'register-form2': registerForm2,
|
||||
'login-form2': loginForm2
|
||||
};
|
||||
|
||||
function showSection(viewId) {
|
||||
Object.values(sections).forEach(section => {
|
||||
section.style.display = 'none';
|
||||
});
|
||||
console.log(viewId);
|
||||
const sectionToShow = sections[viewId];
|
||||
console.log(sectionToShow);
|
||||
if (sectionToShow) {
|
||||
if (viewId == 'auth-form' || viewId == 'post-form-buttons')
|
||||
console.log("here");
|
||||
formBlock.style.display = 'block';
|
||||
sectionToShow.style.display = 'block';
|
||||
} else {
|
||||
console.error(`La section avec l'ID "${viewId}" n'a pas été trouvée.`);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
@ -51,45 +51,45 @@
|
||||
<div class="container" id="block-form">
|
||||
<h1 id="welcome">BIENVENUE DANS LE PONG 42</h1>
|
||||
<div class="input-container">
|
||||
<div id="auth-form">
|
||||
<section id="auth-form">
|
||||
<label for="nickname" id="label-nickname">Enter your nickname:</label>
|
||||
<input type="text" id="nickname" name="nickname">
|
||||
<button id="check-nickname">Check Nickname</button>
|
||||
</div>
|
||||
<div id="register-form" style="display: none;">
|
||||
</section>
|
||||
<section id="register-form" style="display: none;">
|
||||
<label for="password" id="label-password">Enter your password:</label>
|
||||
<input type="password" id="password" name="password">
|
||||
<label for="confirm-password" id="label-confirm-password">Confirm your password:</label>
|
||||
<input type="password" id="confirm-password" name="confirm-password">
|
||||
<button id="register">Register</button>
|
||||
</div>
|
||||
<div id="login-form" style="display: none;">
|
||||
</section>
|
||||
<section id="login-form" style="display: none;">
|
||||
<label for="login-password" id="label-login-password">Enter your password:</label>
|
||||
<input type="password" id="login-password" name="login-password">
|
||||
<button id="login">Login</button>
|
||||
</div>
|
||||
<div id="post-form-buttons" style="display: none;">
|
||||
</section>
|
||||
<section id="post-form-buttons" style="display: none;">
|
||||
<button id="local-game">Local Game</button>
|
||||
<button id="quick-match">Quick Match</button>
|
||||
<button id="tournament">Tournament</button>
|
||||
</div>
|
||||
<div id="auth-form2" style="display: none;">
|
||||
</section>
|
||||
<section id="auth-form2" style="display: none;">
|
||||
<label for="nickname" id="label-nickname2">Enter the second player's nickname:</label>
|
||||
<input type="text" id="nickname2" name="nickname">
|
||||
<button id="check-nickname2">Check Nickname</button>
|
||||
</div>
|
||||
<div id="register-form2" style="display: none;">
|
||||
</section>
|
||||
<section id="register-form2" style="display: none;">
|
||||
<label for="password" id="label-password2">Enter the second player's password:</label>
|
||||
<input type="password" id="password2" name="password">
|
||||
<label for="confirm-password" id="label-confirm-password2">Confirm the second player's password:</label>
|
||||
<input type="password" id="confirm-password2" name="confirm-password">
|
||||
<button id="register2">Register</button>
|
||||
</div>
|
||||
<div id="login-form2" style="display: none;">
|
||||
</section>
|
||||
<section id="login-form2" style="display: none;">
|
||||
<label for="login-password" id="label-login-password2">Enter the second player's password:</label>
|
||||
<input type="password" id="login-password2" name="login-password">
|
||||
<button id="login2">Login</button>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -110,7 +110,7 @@
|
||||
<button id="retry">Rejouer</button>
|
||||
</div>
|
||||
|
||||
<div id="game1" style="display: none;">
|
||||
<section id="game1" style="display: none;">
|
||||
<div id="player1-name" class="name"></div>
|
||||
<div id="player2-name" class="name"></div>
|
||||
<div id="game2">
|
||||
@ -121,7 +121,7 @@
|
||||
<div id="ball"></div>
|
||||
<div id="game-text" class="gameText"></div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<div id="match-list" class="content-list" style="display: none;">
|
||||
<h1>Matches</h1>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user