Invitations changes.
Now require confirmation from both side to start game.
This commit is contained in:
@@ -24,7 +24,6 @@
|
||||
|
||||
//boolean for html page
|
||||
let hiddenGame = true;
|
||||
let optionsAreNotSet = true;
|
||||
let showGameOptions = true;
|
||||
let showInvitations = false;
|
||||
let showError = false;
|
||||
@@ -63,7 +62,6 @@
|
||||
|
||||
function resetPage() {
|
||||
hiddenGame = true;
|
||||
optionsAreNotSet = true;
|
||||
showGameOptions = true;
|
||||
showInvitations = false;
|
||||
showError = false;
|
||||
@@ -74,7 +72,6 @@
|
||||
|
||||
const initGame = async() =>
|
||||
{
|
||||
optionsAreNotSet = false;
|
||||
showWaitPage = true;
|
||||
const matchOptions = pong.computeMatchOptions(options);
|
||||
try {
|
||||
@@ -91,13 +88,18 @@
|
||||
console.log("status : " + response.status);
|
||||
const responseBody = await response.json();
|
||||
const token : string = responseBody.token;
|
||||
showWaitPage = false;
|
||||
if (response.ok && token)
|
||||
{
|
||||
watchMatchStartInterval = setInterval(watchMatchStart, watchMatchStartIntervalRate);
|
||||
watchGameStateInterval = setInterval(watchGameState, watchGameStateIntervalRate);
|
||||
pong.init(matchOptions, options, gameAreaId, token);
|
||||
hiddenGame = false;
|
||||
if (options.isSomeoneIsInvited) {
|
||||
options.reset(user.username);
|
||||
fetchInvitations();
|
||||
}
|
||||
else {
|
||||
watchMatchStartInterval = setInterval(watchMatchStart, watchMatchStartIntervalRate);
|
||||
watchGameStateInterval = setInterval(watchGameState, watchGameStateIntervalRate);
|
||||
pong.init(matchOptions, options, gameAreaId, token);
|
||||
hiddenGame = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -107,7 +109,6 @@
|
||||
showError = true;
|
||||
options.reset(user.username);
|
||||
setTimeout(() => {
|
||||
optionsAreNotSet = true;
|
||||
showError = false;
|
||||
errorMessage = "";
|
||||
}, 5000);
|
||||
@@ -115,11 +116,11 @@
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
showWaitPage = false;
|
||||
}
|
||||
|
||||
const initGameForInvitedPlayer = async(invitation : any) =>
|
||||
const initInvitationGame = async(invitation : any) =>
|
||||
{
|
||||
optionsAreNotSet = false;
|
||||
showWaitPage = true;
|
||||
console.log("invitation : ");
|
||||
console.log(invitation);
|
||||
@@ -130,7 +131,9 @@
|
||||
options.playerOneUsername = invitation.playerOneUsername;
|
||||
options.playerTwoUsername = invitation.playerTwoUsername;
|
||||
options.isSomeoneIsInvited = true;
|
||||
options.isInvitedPerson = true;
|
||||
if (user.username === invitation.playerTwoUsername) {
|
||||
options.isInvitedPerson = true;
|
||||
}
|
||||
pong.init(invitation.gameOptions, options, gameAreaId, invitation.token);
|
||||
showWaitPage = false;
|
||||
hiddenGame = false;
|
||||
@@ -169,10 +172,11 @@
|
||||
}
|
||||
|
||||
const fetchInvitations = async() => {
|
||||
showGameOptions = false;
|
||||
showInvitations = true;
|
||||
console.log("fetchInvitations");
|
||||
invitations = await fetch(`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/game/invitations`)
|
||||
.then(x => x.json());
|
||||
showGameOptions = false;
|
||||
showInvitations = true;
|
||||
}
|
||||
|
||||
const rejectInvitation = async(invitation) => {
|
||||
@@ -199,7 +203,7 @@
|
||||
}).catch(error => console.log(error));
|
||||
|
||||
if (res && res.ok) {
|
||||
initGameForInvitedPlayer(invitation);
|
||||
initInvitationGame(invitation);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -273,7 +277,7 @@
|
||||
|
||||
<!-- -->
|
||||
|
||||
{#if optionsAreNotSet}
|
||||
{#if hiddenGame}
|
||||
{#if showGameOptions}
|
||||
<div id="game_option">
|
||||
<div class="div_game">
|
||||
@@ -332,7 +336,7 @@
|
||||
{#if invitations.length !== 0}
|
||||
{#each invitations as invitation}
|
||||
<div>
|
||||
{invitation.playerOneUsername} has invited you to play a pong !
|
||||
{invitation.playerOneUsername} VS {invitation.playerTwoUsername}
|
||||
<button class="pong_button" on:click={() => acceptInvitation(invitation)}>V</button>
|
||||
<button class="pong_button" on:click={() => rejectInvitation(invitation)}>X</button>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user