Merge branch 'tmp_apommier' into apommier
This commit is contained in:
commit
44183cd1b5
@ -6,7 +6,7 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/06/17 01:00:00 by apommier #+# #+# */
|
||||
/* Updated: 2023/06/26 10:16:19 by apommier ### ########.fr */
|
||||
/* Updated: 2023/06/28 13:57:06 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -198,6 +198,24 @@ export class AppController {
|
||||
//========================================================================================================
|
||||
//========================================================================================================
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Post('/addGame')
|
||||
async addGame(@Request() req, @Body() data: any) {
|
||||
const user = await this.userService.findOne(req.user.username);
|
||||
user.gameSession += 1;
|
||||
await this.userService.save(user);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Post('/rmGame')
|
||||
async removeGame(@Request() req, @Body() data: any) {
|
||||
const user = await this.userService.findOne(req.user.username);
|
||||
user.gameSession -= 1;
|
||||
if (user.gameSession === 0)
|
||||
user.status = 1;
|
||||
await this.userService.save(user);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Post('/win')
|
||||
async addWin(@Request() req, @Body() data: any) {
|
||||
|
||||
@ -63,6 +63,7 @@ export class loginClass {
|
||||
blocked: null,
|
||||
photo: null,
|
||||
sessionNumber: 0,
|
||||
gameSession: 0,
|
||||
};
|
||||
await this.usersService.create(user);
|
||||
}
|
||||
|
||||
@ -50,6 +50,9 @@ export class User {
|
||||
@Column({ default: 0 })
|
||||
sessionNumber: number;
|
||||
|
||||
@Column({ default: 0 })
|
||||
gameSession: number;
|
||||
|
||||
@Column({ default: 0 })
|
||||
rank: number;
|
||||
|
||||
|
||||
@ -17,6 +17,7 @@ export interface User {
|
||||
friends: string[];
|
||||
blocked: string[];
|
||||
sessionNumber: number;
|
||||
gameSession : number;
|
||||
}
|
||||
|
||||
export interface Conv {
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import React, { useEffect } from "react";
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { Routes, Route, Navigate } from 'react-router-dom';
|
||||
import HomeLogin from "../pages/LoginButton.tsx";
|
||||
|
||||
@ -23,16 +23,17 @@ import api from "../script/axiosApi.tsx"
|
||||
|
||||
function AnimatedRoute() {
|
||||
useEffect(() => {
|
||||
const handleBeforeUnload = async (event: { preventDefault: () => void; returnValue: string; }) => {
|
||||
console.log("git ")
|
||||
if (!localStorage.getItem('token'))
|
||||
return;
|
||||
try {
|
||||
await api.post("/quit");
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
};
|
||||
// const handleBeforeUnload = async (event: { preventDefault: () => void; returnValue: string; }) => {
|
||||
// console.log("git ")
|
||||
// if (!localStorage.getItem('token'))
|
||||
// return;
|
||||
// try {
|
||||
// await api.post("/quit");
|
||||
// // navigator.sendBeacon("http://" + process.env.REACT_APP_BASE_URL + "/api/quit", {username: user.username})
|
||||
// } catch (err) {
|
||||
// console.log(err);
|
||||
// }
|
||||
// };
|
||||
|
||||
const handleLoad = async () => {
|
||||
if (!localStorage.getItem('token'))
|
||||
@ -45,9 +46,17 @@ function AnimatedRoute() {
|
||||
};
|
||||
|
||||
handleLoad();
|
||||
window.addEventListener('beforeunload', handleBeforeUnload);
|
||||
|
||||
window.addEventListener("beforeunload", async (event) => {
|
||||
await api.post("/quit");
|
||||
});
|
||||
window.addEventListener("unload", async (event) => {
|
||||
await api.post("/quit");
|
||||
});
|
||||
|
||||
|
||||
return () => {
|
||||
window.removeEventListener('beforeunload', handleBeforeUnload);
|
||||
// window.removeEventListener('beforeunload', handleBeforeUnload);
|
||||
};
|
||||
}, []);
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@ import DrawCanvas from './canvas.tsx';
|
||||
import queryString from 'query-string';
|
||||
import '../styles/field.css';
|
||||
import React from 'react';
|
||||
|
||||
import api from '../script/axiosApi.tsx';
|
||||
|
||||
interface GameProps {
|
||||
privateParty: boolean,
|
||||
@ -13,6 +13,34 @@ interface GameProps {
|
||||
|
||||
function Field()
|
||||
{
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
const addGameSession = async () => {
|
||||
try {
|
||||
await api.post("/addGame");
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
};
|
||||
|
||||
addGameSession();
|
||||
|
||||
const handleBeforeUnload = async () => {
|
||||
try {
|
||||
await api.post("/rmGame");
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
};
|
||||
|
||||
window.addEventListener('beforeunload', handleBeforeUnload);
|
||||
return () => {
|
||||
window.removeEventListener('beforeunload', handleBeforeUnload);
|
||||
};
|
||||
}, []);
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
const queryParams = queryString.parse(window.location.search);
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { useEffect } from 'react';
|
||||
// import { useEffect } from 'react';
|
||||
import api from '../script/axiosApi.tsx';
|
||||
import io from 'socket.io-client';
|
||||
|
||||
@ -10,30 +10,10 @@ interface GameProps {
|
||||
|
||||
function DrawCanvas(option: number, gameParam: GameProps) {
|
||||
|
||||
useEffect(() => {
|
||||
const handleBeforeUnload = async (event: { preventDefault: () => void; returnValue: string; }) => {
|
||||
try {
|
||||
await api.post("/status", {status: 1});
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
};
|
||||
window.addEventListener('beforeunload', handleBeforeUnload);
|
||||
return () => {
|
||||
window.removeEventListener('beforeunload', handleBeforeUnload);
|
||||
};
|
||||
}, []);
|
||||
|
||||
|
||||
console.log(`option= ${option}`);
|
||||
const superpowerModifier = option & 1; // Retrieves the superpower modifier
|
||||
const obstacleModifier = (option >> 1) & 1; // Retrieves the obstacle modifier
|
||||
const speedModifier = (option >> 2) & 1; // Retrieves the speed modifier
|
||||
|
||||
console.log(`superpowerModifier = ${superpowerModifier}`);
|
||||
console.log(`obstacleModifier = ${obstacleModifier}`);
|
||||
console.log(`speedModifier = ${speedModifier}`);
|
||||
|
||||
function launchGame()
|
||||
{
|
||||
if (!gameParam.privateParty)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user