Merge de l'intégration du jeu avec master + corrections et améliorations des messages d'erreurs, de retour en page de reset de variable...

This commit is contained in:
batche
2022-12-22 21:03:46 +01:00
parent 991bbce4af
commit 4c6f832252
4 changed files with 110 additions and 11 deletions

View File

@@ -26,13 +26,14 @@
let showGameOption = true;
let showError = false;
let hiddenGame = true;
let showMatchEnded = false;
let isThereAnyInvitation = false;
let invitations = [];
let waitingMessage = "Please wait..."
let errorMessageWhenAttemptingToGetATicket = "";
let idOfIntevalCheckTerminationOfTheMatch;
onMount( async() => {
user = await fetch('http://transcendance:8080/api/v2/user')
@@ -43,16 +44,30 @@
})
onDestroy( async() => {
options.playerOneUsername = user.username;
showError = false;
showMatchEnded = false;
optionsAreNotSet = true
options.playerTwoUsername = "";
options.isSomeoneIsInvited = false;
options.isInvitedPerson = false;
options.moving_walls = false;
options.multi_balls = false;
errorMessageWhenAttemptingToGetATicket = "";
hiddenGame = true;
isThereAnyInvitation = false;
invitations = [];
pong.destroy();
clearInterval(idOfIntevalCheckTerminationOfTheMatch);
})
const initGame = async() =>
{
optionsAreNotSet = false;
showWaitPage = true;
idOfIntevalCheckTerminationOfTheMatch = setInterval(matchTermitation, 1000);
const matchOptions = pong.computeMatchOptions(options);
const responseWhenGrantToken = fetch("http://transcendance:8080/api/v2/game/ticket", {
method : "POST",
headers : {'Content-Type': 'application/json'},
@@ -67,15 +82,24 @@
const responseInjson = await responseFromServer.json();
const token : string = responseInjson.token;
showWaitPage = false;
if (!responseFromServer.ok)
if (!responseFromServer.ok || (responseFromServer.status != 200 && responseFromServer.status != 201))
{
console.log(responseInjson)
console.log("On refuse le ticket");
clearInterval(idOfIntevalCheckTerminationOfTheMatch);
errorMessageWhenAttemptingToGetATicket = responseInjson.message;
showError = true;
options.playerTwoUsername = "";
options.playerOneUsername = user.username;
options.isSomeoneIsInvited = false;
options.isInvitedPerson = false;
options.moving_walls = false;
options.multi_balls = false;
setTimeout(() => {
showError = false;
showWaitPage = false
optionsAreNotSet = true
options.playerTwoUsername = "";
}, 5000);
}
else if (token)
@@ -89,6 +113,7 @@
// Pour Cherif: renommer en un truc du genre "initGameForInvitedPlayer" ?
const initGameForPrivateParty = async(invitation : any) =>
{
idOfIntevalCheckTerminationOfTheMatch = setInterval(matchTermitation, 1000);
optionsAreNotSet = false
showWaitPage = true
console.log("invitation : ")
@@ -105,6 +130,38 @@
}
}
const matchTermitation = () => {
console.log("Ping matchTermitation")
if (matchAbort || matchEnded)
{
clearInterval(idOfIntevalCheckTerminationOfTheMatch);
console.log("matchTermitation was called")
showWaitPage = false
matchAbort ? errorMessageWhenAttemptingToGetATicket = "The match has been aborted" : errorMessageWhenAttemptingToGetATicket = "The match is finished !"
matchAbort ? showError = true : showMatchEnded = true;
hiddenGame = true;
setTimeout(() => {
showError = false;
showMatchEnded = false;
optionsAreNotSet = true
options.playerTwoUsername = "";
options.playerOneUsername = user.username;
options.isSomeoneIsInvited = false;
options.isInvitedPerson = false;
options.moving_walls = false;
options.multi_balls = false;
errorMessageWhenAttemptingToGetATicket = "";
options.playerTwoUsername = "";
hiddenGame = true;
isThereAnyInvitation = false;
invitations = [];
pong.destroy();
console.log("matchTermitation : setTimeout")
}, 5000);
}
}
const showOptions = () => {
showGameOption = true
showInvitations = false
@@ -132,7 +189,7 @@
}
const acceptInvitation = async(invitation : any) => {
await fetch("http://transcendance:8080/api/v2/game/accept",{
const res = await fetch("http://transcendance:8080/api/v2/game/accept",{
method: "POST",
headers: { 'Content-Type': 'application/json'},
body: JSON.stringify({
@@ -142,9 +199,14 @@
.then(x => x.json())
.catch(error => {
console.log(error)
})
showInvitation() // maybe useless
if (res.status === 200)
{
showInvitation()
initGameForPrivateParty(invitation)
}
//Au final c'est utile !
initGameForPrivateParty(invitation)
}
</script>
@@ -168,6 +230,12 @@
</div>
{/if}
{#if showMatchEnded === true}
<div id="div_game" in:fly="{{ y: 10, duration: 1000 }}">
<p>{errorMessageWhenAttemptingToGetATicket}</p>
</div>
{/if}
{#if showWaitPage === true}
<div id="div_game" in:fly="{{ y: 10, duration: 1000 }}">
<fieldset>

View File

@@ -101,6 +101,9 @@ function preMatchListener(this: WebSocket, event: MessageEvent)
matchAbort = true;
socket.removeEventListener("message", preMatchListener);
msg.matchAbort();
setTimeout(() => {
matchAbort = false;
}, 1000);
break;
}
}
@@ -212,6 +215,9 @@ function matchEnd(data: ev.EventMatchEnd)
else {
msg.lose();
}
setTimeout(() => {
matchEnded = false;
}, 1000);
}
/* Spectator */
@@ -320,3 +326,4 @@ function matchEndSpectator(data: ev.EventMatchEnd)
msg.forfeit(clientInfo.side);
} */
}