suppression de fonctions inutiles dans la partie svelte
This commit is contained in:
@@ -16,47 +16,51 @@
|
||||
import Header from '../../pieces/Header.svelte';
|
||||
import { push } from "svelte-spa-router";
|
||||
|
||||
//user's stuff
|
||||
let user;
|
||||
|
||||
let optionsAreNotSet = true
|
||||
let allUsers;
|
||||
|
||||
|
||||
//init function
|
||||
let isSecondPlayerAnsweredYes = false;
|
||||
let isSecondPlayerRefused = false;
|
||||
let isSomethingWentWrong = true;
|
||||
|
||||
|
||||
//Game's stuff nest side
|
||||
let optionsAreNotSet = true;
|
||||
let invite_someone = false;
|
||||
let playerTwoUsername = "";
|
||||
let token = "";
|
||||
|
||||
//Game's stuff gameserver side
|
||||
let sound = false;
|
||||
let multi_balls = false;
|
||||
let moving_walls = false;
|
||||
let matchOption : enumeration.MatchOptions = enumeration.MatchOptions.noOption;
|
||||
let invite_someone = false;
|
||||
let allUsers;
|
||||
let playerTwoUsername;
|
||||
|
||||
//html boolean for pages
|
||||
let showWaitPage = false;
|
||||
let showInvitations = false;
|
||||
let showGameOption = true;
|
||||
let isThereAnyInvitation = false;
|
||||
let invitations;
|
||||
let showError = false;
|
||||
|
||||
let showWaitPage = false;
|
||||
let isThereAnyInvitation = false;
|
||||
let invitations;
|
||||
|
||||
let waitingMessage = "Please wait..."
|
||||
let errorMessageWhenAttemptingToGetATicket = "";
|
||||
|
||||
let token = ""
|
||||
let responseToCheckIfOtherUserHasAnswered;
|
||||
|
||||
let isSecondPlayerAnsweredYes = false;
|
||||
|
||||
let isSecondPlayerRefused = false;
|
||||
|
||||
let isSomethingWentWrong = true;
|
||||
onMount( async() => {
|
||||
user = await fetch('http://transcendance:8080/api/v2/user')
|
||||
.then( (x) => x.json() );
|
||||
.then( x => x.json() );
|
||||
allUsers = await fetch('http://transcendance:8080/api/v2/user/all')
|
||||
.then( x => x.json() );
|
||||
})
|
||||
|
||||
const init = async() => {
|
||||
|
||||
optionsAreNotSet = false
|
||||
showWaitPage = true
|
||||
console.log("Player two username " + playerTwoUsername)
|
||||
@@ -92,59 +96,8 @@
|
||||
}, 5000)
|
||||
return ;
|
||||
}
|
||||
if (invite_someone === true)
|
||||
else if (res.status === 200)
|
||||
{
|
||||
token = res.token;
|
||||
waitingMessage = `Waiting for ${playerTwoUsername}'s answer !`
|
||||
let intervalId = setInterval(checkIfOtherUserIsReady , 1000 * 1);
|
||||
let timeOutId = setTimeout(()=> {
|
||||
console.log("FIN DU TIMEOUT")
|
||||
errorMessageWhenAttemptingToGetATicket = "The second player took too much time to answer"
|
||||
showWaitPage = false
|
||||
showError = true;
|
||||
isSecondPlayerAnsweredYes = false
|
||||
playerTwoUsername = "";
|
||||
matchOption = 0;
|
||||
token = ""
|
||||
clearInterval(intervalId)
|
||||
isSomethingWentWrong = true
|
||||
}, 1000 * 5)
|
||||
console.log("EN DESSOUS DE TIMEOUT")
|
||||
if (isSecondPlayerAnsweredYes === true)
|
||||
{
|
||||
clearTimeout(timeOutId)
|
||||
clearInterval(intervalId)
|
||||
isSomethingWentWrong = false;
|
||||
}
|
||||
if (isSecondPlayerRefused === true)
|
||||
{
|
||||
clearTimeout(timeOutId)
|
||||
clearInterval(intervalId)
|
||||
}
|
||||
}
|
||||
if (isSomethingWentWrong === false)
|
||||
{
|
||||
const res = await fetch("http://transcendance:8080/api/v2/game/gameServer/validate", {
|
||||
method : "POST",
|
||||
headers : {'Content-Type': 'application/json'},
|
||||
body : JSON.stringify({
|
||||
playerOneUsername : user.username,
|
||||
playerTwoUsername : playerTwoUsername,
|
||||
gameOptions : matchOption,
|
||||
isGameIsWithInvitation : invite_someone,
|
||||
token : token
|
||||
})
|
||||
})
|
||||
.then(x => x.json())
|
||||
.catch(error => {
|
||||
console.log(error)
|
||||
})
|
||||
if (res.status !== 200)
|
||||
{
|
||||
showError = true;
|
||||
errorMessageWhenAttemptingToGetATicket = "Your session is not valid. Please try again."
|
||||
return ;
|
||||
}
|
||||
initAudio(sound)
|
||||
initMatchOptions(matchOption)
|
||||
initPong(new GameArea())
|
||||
@@ -152,27 +105,27 @@
|
||||
initStartFunction(start)
|
||||
initWebSocket(matchOption)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async function checkIfOtherUserIsReady(token : string) {
|
||||
responseToCheckIfOtherUserHasAnswered = await fetch("http://transcendance:8080/api/v2/game/requested",{
|
||||
method : "POST",
|
||||
headers : { 'Content-Type': 'application/json'},
|
||||
body : JSON.stringify({
|
||||
token : token
|
||||
})
|
||||
})
|
||||
const data = await responseToCheckIfOtherUserHasAnswered.json();
|
||||
console.log(data)
|
||||
if (data.isSecondUserAcceptedRequest === true)
|
||||
isSecondPlayerAnsweredYes = true
|
||||
if (data.status === 404 || data.status === 403)
|
||||
{
|
||||
isSecondPlayerRefused = true
|
||||
errorMessageWhenAttemptingToGetATicket = data.message;
|
||||
}
|
||||
|
||||
// const fetch = await fetch("http://transcendance:8080/api/v2/game/gameServer/validate", {
|
||||
// method : "POST",
|
||||
// headers : {'Content-Type': 'application/json'},
|
||||
// body : JSON.stringify({
|
||||
// playerOneUsername : user.username,
|
||||
// playerTwoUsername : playerTwoUsername,
|
||||
// gameOptions : matchOption,
|
||||
// isGameIsWithInvitation : invite_someone,
|
||||
// token : token
|
||||
// })
|
||||
// })
|
||||
// .then(x => x.json())
|
||||
// .catch(error => {
|
||||
// console.log(error)
|
||||
// })
|
||||
// if (res.status !== 200)
|
||||
// {
|
||||
// showError = true;
|
||||
// errorMessageWhenAttemptingToGetATicket = "Your session is not valid. Please try again."
|
||||
// return ;
|
||||
// }
|
||||
}
|
||||
|
||||
function start() : void {
|
||||
@@ -245,14 +198,14 @@
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if showWaitPage === true}
|
||||
<div id="div_game">
|
||||
<fieldset>
|
||||
<legend>Connecting to the game...</legend>
|
||||
<p>{waitingMessage}</p>
|
||||
</fieldset>
|
||||
</div>
|
||||
{/if}
|
||||
{#if showWaitPage === true}
|
||||
<div id="div_game">
|
||||
<fieldset>
|
||||
<legend>Connecting to the game...</legend>
|
||||
<p>{waitingMessage}</p>
|
||||
</fieldset>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if optionsAreNotSet}
|
||||
{#if showGameOption === true}
|
||||
|
||||
Reference in New Issue
Block a user