diff --git a/api-rest/index.php b/api-rest/index.php index a58696e..4db498e 100644 --- a/api-rest/index.php +++ b/api-rest/index.php @@ -230,15 +230,15 @@ //header("HTTP/1.0 400 Invalid number of arguments"); http_response_code(400); } - $id = !empty($url[4]) ? (int) $url[4] : null; - $username = !empty($url[5]) ? (string) $url[5] : null; - $password = !empty($url[6]) ? (string) $url[6] : null; - $sexe = !empty($url[7]) ? (string) $url[7] : null; - $nationality = !empty($url[8]) ? (string) $url[8] : null; - $nbCurrentCoins = (int) $url[9]; - $totalnbCoins = (int) $url[10]; - $nbGames = (int) $url[11]; - $currentSkin = !empty($url[12]) ? (int) $url[12] : null; + $id = !empty($url[3]) ? (int) $url[3] : null; + $username = !empty($url[4]) ? (string) $url[4] : null; + $password = !empty($url[5]) ? (string) $url[5] : null; + $sexe = !empty($url[6]) ? (string) $url[6] : null; + $nationality = !empty($url[7]) ? (string) $url[7] : null; + $nbCurrentCoins = (int) $url[8]; + $totalnbCoins = (int) $url[9]; + $nbGames = (int) $url[10]; + $currentSkin = !empty($url[11]) ? (int) $url[11] : null; $usergw->putUser($id,$username,$password,$sexe, $nationality, $nbCurrentCoins,$totalnbCoins,$nbGames,$currentSkin); http_response_code(200); } diff --git a/bob_party/server.js b/bob_party/server.js index 9be4546..de4c167 100644 --- a/bob_party/server.js +++ b/bob_party/server.js @@ -7,7 +7,7 @@ const { Server } = require("socket.io"); const io = new Server(server); io.on('connection', (socket) => { - console.log(socket.id) + console.log(socket.id); socket.on('signIn', (id) => { socket.join("U"+id); @@ -26,23 +26,28 @@ io.on('connection', (socket) => { console.log("Message envoyé"); }); - socket.on("createConversation", (tabId) =>{ + socket.on("createConversation", (tabId, conv) =>{ tabId.forEach(id => { - socket.to("U"+id).emit("messageReceived"); + socket.to("U"+id).emit("addedToConv", conv); }); }); socket.on('joinMatch', (match) => { - socket.join("M" + match); + socket.join("M" + match.code); + socket.to("M"+ match.code).emit("matchUsersChanged"); + }); + + socket.on('launchMatch', (match) => { + socket.to("M"+ match.code).emit("matchLaunched"); }); socket.on('quitMatch', (match) => { - socket.off("M" + match); + socket.to("M"+ match.code).emit("matchUsersChanged") }); socket.on("playTicTacToe", (match, rowIndex, columnIndex, turn) =>{ - socket.to("M"+match).emit("oppPlayTicTacToe", rowIndex, columnIndex, turn); + socket.to("M"+match.code).emit("oppPlayTicTacToe", rowIndex, columnIndex, turn); }); }); diff --git a/bob_party/src/Games/Tic-Tac-Toe/tic_tac_toe_online.tsx b/bob_party/src/Games/Tic-Tac-Toe/tic_tac_toe_online.tsx index 06d5996..df73a10 100644 --- a/bob_party/src/Games/Tic-Tac-Toe/tic_tac_toe_online.tsx +++ b/bob_party/src/Games/Tic-Tac-Toe/tic_tac_toe_online.tsx @@ -7,11 +7,15 @@ import { ScreenIndicator } from "../../components/ScreenIndicator"; import { TopBar } from "../../components/TopBar"; import { socket } from "../../../socketConfig"; import { MANAGER_MATCH, MANAGER_USER } from "../../../appManagers"; +import { useUserStore } from "../../context/userContext"; export default function TicTacToeOnline(props: { navigation: any }){ - const [init, setInit]=useState(0); + const [initTic, setInitTic]=useState(0); + + const setUser = useUserStore((state) => state.setUser); + setUpTicTacToeOnline(); @@ -29,7 +33,7 @@ export default function TicTacToeOnline(props: { navigation: any }){ const [currentTurn,setCurrentTurn] = useState("x"); - const onPressCell = (rowIndex:number,columnIndex:number) => { + const onPressCell = async (rowIndex:number,columnIndex:number) => { if (turnUser!==currentTurn){ Alert.alert("ce n'est pas à votre tour de jouer"); return; @@ -40,9 +44,9 @@ export default function TicTacToeOnline(props: { navigation: any }){ updateMap[rowIndex][columnIndex]=currentTurn; return updateMap; }); - socket.emit("playTicTacToe", 1, rowIndex, columnIndex, currentTurn); + socket.emit("playTicTacToe", MANAGER_MATCH.getCurrentMatch(), rowIndex, columnIndex, currentTurn); setCurrentTurn(currentTurn === "x"? "o" : "x"); - const retour=checkWinning(); + const retour= await checkWinning(); if(retour!=true){ checkComplete(); } @@ -54,9 +58,8 @@ export default function TicTacToeOnline(props: { navigation: any }){ }; function setUpTicTacToeOnline() { - if (init===0){ - setInit(1); - socket.emit("inMatch", 1); + if (initTic===0){ + setInitTic(1); socket.on("oppPlayTicTacToe", (rowIndex, columnIndex, turn) =>{ setMap((existingMap) =>{ @@ -80,36 +83,42 @@ export default function TicTacToeOnline(props: { navigation: any }){ } } - const checkWinning = () =>{ + async function endGame(win: number){ + socket.off("oppPlayTicTacToe"); + navigation.goBack(); + const tmp=MANAGER_USER.getCurrentUser(); + if (tmp!==null){ + await MANAGER_MATCH.getCurrentMatch()?.updatePostMatch(tmp, win); + MANAGER_USER.setCurrentUser(tmp); + setUser(tmp); + } + } + + const checkWinning = async () =>{ const tmp=MANAGER_USER.getCurrentUser() // Checks rows for (let i=0; i<3; i++){ const isRowXWinning = map[i].every((cell)=> cell==="x"); const isRowOWinning = map[i] .every((cell)=>cell==="o"); if(isRowXWinning==true){ - if (tmp!==null){ - if (turnUser==="x"){ - MANAGER_MATCH.getCurrentMatch()?.updatePostMatch(tmp, 2); - } - else{ - MANAGER_MATCH.getCurrentMatch()?.updatePostMatch(tmp, 0); - } - } Alert.alert("X won !"); - navigation.goBack(); + if (turnUser==="x"){ + await endGame(2); + } + else{ + await endGame(0); + } return true; } else if(isRowOWinning==true){ - if (tmp!==null){ - if (turnUser==="x"){ - MANAGER_MATCH.getCurrentMatch()?.updatePostMatch(tmp, 0); - } - else{ - MANAGER_MATCH.getCurrentMatch()?.updatePostMatch(tmp, 2); - } - } + Alert.alert("O won !"); - navigation.goBack(); + if (turnUser==="x"){ + await endGame(0); + } + else{ + await endGame(2); + } return true; } } @@ -127,29 +136,23 @@ export default function TicTacToeOnline(props: { navigation: any }){ } } if (isColumnXWinning == true){ - if (tmp!==null){ - if (turnUser==="x"){ - MANAGER_MATCH.getCurrentMatch()?.updatePostMatch(tmp, 2); - } - else{ - MANAGER_MATCH.getCurrentMatch()?.updatePostMatch(tmp, 0); - } - } Alert.alert("X won !"); - navigation.goBack(); + if (turnUser==="x"){ + await endGame(2); + } + else{ + await endGame(0); + } return true; } if(isColumnOWinning==true){ - if (tmp!==null){ - if (turnUser==="x"){ - MANAGER_MATCH.getCurrentMatch()?.updatePostMatch(tmp, 0); - } - else{ - MANAGER_MATCH.getCurrentMatch()?.updatePostMatch(tmp, 2); - } - } Alert.alert("O won !"); - navigation.goBack(); + if (turnUser==="x"){ + await endGame(0); + } + else{ + await endGame(2); + } return true; } @@ -174,44 +177,34 @@ export default function TicTacToeOnline(props: { navigation: any }){ } } if(isDiag1OWinning==true || isDiag2OWinning==true){ - if (tmp!==null){ - if (turnUser==="x"){ - MANAGER_MATCH.getCurrentMatch()?.updatePostMatch(tmp, 0); - } - else{ - MANAGER_MATCH.getCurrentMatch()?.updatePostMatch(tmp, 2); - } - } Alert.alert("O won !"); - navigation.goBack(); + if (turnUser==="x"){ + await endGame(0); + } + else{ + await endGame(2); + } return true; } if(isDiag1XWinning==true || isDiag2XWinning==true){ - if (tmp!==null){ - if (turnUser==="x"){ - MANAGER_MATCH.getCurrentMatch()?.updatePostMatch(tmp, 2); - } - else{ - MANAGER_MATCH.getCurrentMatch()?.updatePostMatch(tmp, 0); - } - } Alert.alert("X won !"); - navigation.goBack(); + if (turnUser==="x"){ + await endGame(2); + } + else{ + await endGame(0); + } return true; } }; - const checkComplete = () =>{ + const checkComplete = async () =>{ const isRow0Full = map[0].every((cell)=> cell!==""); const isRow1Full = map[1] .every((cell)=>cell!==""); const isRow2Full = map[2] .every((cell)=>cell!==""); if(isRow0Full==true && isRow1Full==true && isRow2Full==true){ - const tmp=MANAGER_USER.getCurrentUser(); - if (tmp!==null){ - MANAGER_MATCH.getCurrentMatch()?.updatePostMatch(tmp, 1); - } Alert.alert("Draw !"); - navigation.goBack(); + await endGame(1); return false; } }; diff --git a/bob_party/src/components/ConversationPreviewComponent.tsx b/bob_party/src/components/ConversationPreviewComponent.tsx index 45e2c7d..a6093dd 100644 --- a/bob_party/src/components/ConversationPreviewComponent.tsx +++ b/bob_party/src/components/ConversationPreviewComponent.tsx @@ -1,4 +1,4 @@ -import { FC, ReactNode } from "react" +import { FC, ReactNode, useState } from "react" import { Pressable, Image, ImageStyle, Text, View, Alert, ImageSourcePropType, TextStyle } from "react-native" import React from "react" import { Skin } from "../core/skin" @@ -22,24 +22,33 @@ FC<{conv: Conversation, navigation: any}> = { const setCurrentConv = useConversationStore((state) => state.setCurrentConv); + const [user,setUser]=useState(MANAGER_USER.getCurrentUser()); + const [initVar,setInitVar]=useState(0); - const user1 = MANAGER_USER.getCurrentUser(); - let tmp; - if (conv.getTabMessage().length<2){ - tmp=conv.getTabUser()[0]; - } - else if (user1?.isEqual(conv.getTabUser()[0])) tmp = conv.getTabUser()[1]; - else tmp = conv.getTabUser()[0]; - const user2 = tmp; + init(); + function init(){ + if (initVar===0){ + setInitVar(1); + if (conv.getTabUser().length<2){ + setUser(MANAGER_USER.getCurrentUser()); + } + else if (MANAGER_USER.getCurrentUser()?.isEqual(conv.getLastMessage().getMessageSender())){ + setUser(conv.getLastMessage().getMessageSender()); + } + else{ + setUser(conv.getTabUser()[1]); + } + } + } return( {MANAGER_CONVERSATION.setCurrentConv(conv); setCurrentConv(conv); navigation.navigate(Conversation)}}> - + {conv.getName()} diff --git a/bob_party/src/components/GameComponent.tsx b/bob_party/src/components/GameComponent.tsx index f181c13..d636554 100644 --- a/bob_party/src/components/GameComponent.tsx +++ b/bob_party/src/components/GameComponent.tsx @@ -41,6 +41,7 @@ FC<{game: Game, nav: any}> = nav.navigate("GameSolo"); } }, []); + return ( diff --git a/bob_party/src/components/LobbyComponent.tsx b/bob_party/src/components/LobbyComponent.tsx index e13b738..edf6e38 100644 --- a/bob_party/src/components/LobbyComponent.tsx +++ b/bob_party/src/components/LobbyComponent.tsx @@ -17,6 +17,7 @@ import { useMatchStore } from '../context/matchContext'; import { MANAGER_MATCH } from '../../appManagers'; import { ScreenIndicator } from '../components/ScreenIndicator'; import { UserPreview } from "./UserPreview" +import { socket } from "../../socketConfig" export const LobbyComponent : @@ -24,8 +25,12 @@ FC<{nav: any}> = ({nav}) => { const setTabUser = useMatchStore((state) => state.setTabUser); + const setMatch = useMatchStore((state) => state.setMatch); + const [initUsers, setInitUsers] = useState(0); + const [init, setInit] = useState(0); + function getUsers(){ if (initUsers===0){ @@ -45,6 +50,36 @@ FC<{nav: any}> = } + async function launchMatch(){ + + } + + + function initMatchSocket(){ + if (init===0){ + setInit(1); + socket.on("matchUsersChanged", async () =>{ + const match=MANAGER_MATCH.getCurrentMatch(); + if (match !==null){ + await MANAGER_MATCH.getLoaderMatch().loadByID(match.code).then((res) =>{ + MANAGER_MATCH.setCurrentMatch(res); + setMatch(res); + setInitUsers(0); + getUsers(); + }); + } + + }); + + socket.on("matchLaunched", async () =>{ + nav.navigate(MANAGER_MATCH.getCurrentMatch()?.getGame().getName().replace(/\s/g, '')); + }); + } + } + + initMatchSocket(); + + if(MANAGER_MATCH.getCurrentMatch()?.getGame().getNbPlayerMax()==1){ return ( @@ -75,7 +110,7 @@ FC<{nav: any}> = /> nav.navigate(MANAGER_MATCH.getCurrentMatch()?.getGame().getName().replace(/\s/g, ''))} + onPress={() => {socket.emit("launchMatch", MANAGER_MATCH.getCurrentMatch()); nav.navigate(MANAGER_MATCH.getCurrentMatch()?.getGame().getName().replace(/\s/g, ''))}} > Lancer la partie diff --git a/bob_party/src/components/TopBar.tsx b/bob_party/src/components/TopBar.tsx index f1277b4..48bf5b1 100644 --- a/bob_party/src/components/TopBar.tsx +++ b/bob_party/src/components/TopBar.tsx @@ -52,7 +52,7 @@ FC<{nav: any, state?: string}> = await MANAGER_CONVERSATION.getsaverConversation().deleteUserToConversation(tmpConv, tmp); const trouveIndex = (element: Conversation) => element.getId()===tmpConv.getId(); const index=MANAGER_CONVERSATION.getTabConv().findIndex(trouveIndex); - MANAGER_CONVERSATION.getTabConv().splice(index); + MANAGER_CONVERSATION.getTabConv().splice(index, 1); if (tmpConv.getTabUser().length===1){ await MANAGER_CONVERSATION.getsaverConversation().deleteConversation(tmpConv); } @@ -70,6 +70,7 @@ FC<{nav: any, state?: string}> = const m=new MatchModifier(); if (tmp!==null && tmpMatch!==null){ socket.emit("quitMatch", tmpMatch); + socket.off("M" + tmpMatch.code); await m.quitMatch(tmp, tmpMatch); resetMatch(); resetTabUserMatch(); @@ -111,7 +112,7 @@ FC<{nav: any, state?: string}> = case 'conversation': return ( - { resetCurrentConv; MANAGER_CONVERSATION.setCurrentConv(null); nav.goBack()}}> + { resetCurrentConv(); MANAGER_CONVERSATION.setCurrentConv(null); nav.goBack()}}> {useConversationStore().currentConv?.getName()} diff --git a/bob_party/src/core/Match/match.ts b/bob_party/src/core/Match/match.ts index 3265e5c..9fa0685 100644 --- a/bob_party/src/core/Match/match.ts +++ b/bob_party/src/core/Match/match.ts @@ -67,6 +67,6 @@ export abstract class Match{ } - abstract updatePostMatch(user:User, points:number):void; + abstract updatePostMatch(user:User, points:number):Promise; } \ No newline at end of file diff --git a/bob_party/src/core/Match/matchCasino.ts b/bob_party/src/core/Match/matchCasino.ts index b8dec35..20e9253 100644 --- a/bob_party/src/core/Match/matchCasino.ts +++ b/bob_party/src/core/Match/matchCasino.ts @@ -10,9 +10,9 @@ export default class MatchCasino extends Match{ super(code, inGame, tabUser, game); } - updatePostMatch(user:User, points: number): void { + async updatePostMatch(user:User, points: number): Promise { const manage= new UserCoinsModifier(); - manage.addCoins(user, this.getGame().coinsCalculator(points)); + await manage.addCoins(user, this.getGame().coinsCalculator(points)); } } \ No newline at end of file diff --git a/bob_party/src/core/Match/matchMulti.ts b/bob_party/src/core/Match/matchMulti.ts index b028777..e220b24 100644 --- a/bob_party/src/core/Match/matchMulti.ts +++ b/bob_party/src/core/Match/matchMulti.ts @@ -10,8 +10,8 @@ export default class MatchMulti extends Match{ super(code, inGame, tabUser, game); } - updatePostMatch(user:User, points: number): void { + async updatePostMatch(user:User, points: number): void { const manage= new UserCoinsModifier(); - manage.addCoins(user, this.getGame().coinsCalculator(points)); + await manage.addCoins(user, this.getGame().coinsCalculator(points)); } } \ No newline at end of file diff --git a/bob_party/src/core/Match/matchSolo.ts b/bob_party/src/core/Match/matchSolo.ts index b74b2c6..8545f27 100644 --- a/bob_party/src/core/Match/matchSolo.ts +++ b/bob_party/src/core/Match/matchSolo.ts @@ -10,8 +10,8 @@ export default class MatchSolo extends Match{ super(code, inGame, tabUser, game); } - updatePostMatch(user:User, points: number): void { + async updatePostMatch(user:User, points: number): void { const manage= new UserCoinsModifier(); - manage.addCoins(user, this.getGame().coinsCalculator(points)); + await manage.addCoins(user, this.getGame().coinsCalculator(points)); } } \ No newline at end of file diff --git a/bob_party/src/screens/AddConversation.tsx b/bob_party/src/screens/AddConversation.tsx index 5ce525a..d9920dc 100644 --- a/bob_party/src/screens/AddConversation.tsx +++ b/bob_party/src/screens/AddConversation.tsx @@ -66,7 +66,8 @@ export default function AddConversation(props: {navigation:any}){ (objA, objB) => objB.getLastMessage().getMessageDate().getTime() - objA.getLastMessage().getMessageDate().getTime(), ); setTabConv(MANAGER_CONVERSATION.getTabConv()); - socket.emit("createConversation", tabId); + socket.emit("createConversation", tabId, res); + socket.emit("inConv", res); navigation.goBack(); } }); diff --git a/bob_party/src/screens/ConversationScreen.tsx b/bob_party/src/screens/ConversationScreen.tsx index c2ec7cf..99e6100 100644 --- a/bob_party/src/screens/ConversationScreen.tsx +++ b/bob_party/src/screens/ConversationScreen.tsx @@ -26,7 +26,7 @@ function ConversationScreen(props: { navigation: any; }) { await MANAGER_CONVERSATION.getsaverConversation().addMessage(tmpConv.getId(), e.nativeEvent.text, new Date(), tmpUs).then((res) => { if (res!==null){ const trouveIndex = (element: Conversation) => element.getId()===tmpConv.getId(); - MANAGER_CONVERSATION.getCurrentConv()?.getTabMessage().push(res); + MANAGER_CONVERSATION.getCurrentConv()?.ajouterMessage(res); const index=MANAGER_CONVERSATION.getTabConv().findIndex(trouveIndex); const tmp=MANAGER_CONVERSATION.getCurrentConv(); if (tmp!==null){ diff --git a/bob_party/src/screens/GameChoice.tsx b/bob_party/src/screens/GameChoice.tsx index 4ceed55..46508bb 100644 --- a/bob_party/src/screens/GameChoice.tsx +++ b/bob_party/src/screens/GameChoice.tsx @@ -1,5 +1,5 @@ import { StatusBar } from 'expo-status-bar' -import {View, FlatList, Text, Alert} from 'react-native' +import {View, FlatList, Text, Alert, NativeSyntheticEvent, TextInputSubmitEditingEventData} from 'react-native' import React, { useState } from 'react'; import { TopBar } from '../components/TopBar'; import { BotBar } from '../components/BotBar'; @@ -10,23 +10,35 @@ import stylesScreen from './style/screens.style' import styles from './style/GameChoice.style' import { MANAGER_GAME, MANAGER_MATCH, MANAGER_USER } from '../../appManagers'; import { GameList } from '../components/GameList'; +import { useMatchStore } from '../context/matchContext'; +import { socket } from '../../socketConfig'; function GameChoice(props: { navigation: any}) { const { navigation} = props const [matchId, setMatchId] = useState(''); - async function joinMatch(id:string){ - const newId = parseInt(id); + const setMatch = useMatchStore((state) => state.setMatch); + + + async function joinMatch(id:NativeSyntheticEvent){ + const newId = parseInt(id.nativeEvent.text); const tmp=MANAGER_USER.getCurrentUser(); if (tmp !== null){ await MANAGER_MATCH.getsaverMatch().joinMatch(tmp, newId).then((res) =>{ if (res===null){ - Alert.alert() + Alert.alert("L'id du match n'existe pas ou un jeu est déjà lancé ou il y a trop de joueurs");//changer ça avec d'autre codes de retour + } + else{ + MANAGER_MATCH.setCurrentMatch(res); + setMatch(res); + socket.emit("joinMatch", res); + navigation.navigate("GameSolo"); } }); } } + if(MANAGER_GAME.currentGameType === "solo" ){ return ( diff --git a/bob_party/src/screens/SignIn.tsx b/bob_party/src/screens/SignIn.tsx index 45ce430..33f2fbc 100644 --- a/bob_party/src/screens/SignIn.tsx +++ b/bob_party/src/screens/SignIn.tsx @@ -32,6 +32,8 @@ function SignIn(props: { navigation: any; }) { const setTabSkin = useSkinStore((state) => state.setTabSkin); + const [waitConnect, setWaitConnect] = useState(0); + const errorList = useSelector((state: RootState) => state.credentialErrors.loginErrorList); @@ -44,12 +46,11 @@ function SignIn(props: { navigation: any; }) { dispatch(updateIncorrectCredentials(true)); } - let waitConnect=0; async function handleUserConnect(username: string, password: string){ if (waitConnect==0){ - waitConnect=1; + setWaitConnect(-1); await MANAGER_USER.getLoaderUser().loadByUsernamePassword(username, password).then(async (res) => { if (res!=null){ @@ -67,10 +68,10 @@ function SignIn(props: { navigation: any; }) { } else{ Alert.alert("Incorrect Username or Password"); + setWaitConnect(0); } }); - waitConnect=0; } return; } @@ -83,6 +84,10 @@ function SignIn(props: { navigation: any; }) { socket.on("messageReceived", async () =>{ await handleConversationLoad(); }); + socket.on("addedToConv", async (conv) =>{ + socket.emit("inConv", conv); + await handleConversationLoad(); + }); } async function handleConversationLoad(){ @@ -96,9 +101,6 @@ function SignIn(props: { navigation: any; }) { if (tmpConv!==null){ const trouveIndex = (element: Conversation) => element.getId()===tmpConv.getId(); const index=MANAGER_CONVERSATION.getTabConv().findIndex(trouveIndex); - MANAGER_CONVERSATION.getTabConv()?.sort( - (objA, objB) => objB.getLastMessage().getMessageDate().getTime() - objA.getLastMessage().getMessageDate().getTime(), - ); MANAGER_CONVERSATION.setCurrentConv(MANAGER_CONVERSATION.getTabConv()[index]); setCurrentConv(MANAGER_CONVERSATION.getCurrentConv()); } diff --git a/bob_party/src/services/conversationService/loaderConversationApi.ts b/bob_party/src/services/conversationService/loaderConversationApi.ts index 3290e8a..4781b5e 100644 --- a/bob_party/src/services/conversationService/loaderConversationApi.ts +++ b/bob_party/src/services/conversationService/loaderConversationApi.ts @@ -63,7 +63,10 @@ async function jsonToConversation(response:any) { const sender:User | null= await MANAGER_USER.getLoaderUser().loadByID(message.idSender); if (sender!=null){ - tabMessage.push(new Message(message.id, message.content, sender, new Date(message.dateEnvoie))); + const tab=message.dateEnvoie.split(' '); + const tabDate=tab[0].split('-'); + const tabPrecis=tab[1].split(":"); + tabMessage.push(new Message(message.id, message.content, sender, new Date(tabDate[0],parseInt(tabDate[1])-1,tabDate[2],tabPrecis[0], tabPrecis[1], tabPrecis[2]))); } if(conv.tabMessages.length===tabMessage.length){ resolve(); diff --git a/bob_party/src/services/gameService/loaderGameApi.ts b/bob_party/src/services/gameService/loaderGameApi.ts index 322d94e..2312091 100644 --- a/bob_party/src/services/gameService/loaderGameApi.ts +++ b/bob_party/src/services/gameService/loaderGameApi.ts @@ -21,7 +21,6 @@ export default class LoaderGameApi implements ILoaderGame{ .then(function (response: any) { if (response.data != null && response.data != undefined){ response.data.forEach(game => { - switch(game.type){ case "GameSolo": let mapSolo = new Map(); @@ -54,7 +53,7 @@ export default class LoaderGameApi implements ILoaderGame{ method: 'get', url: url, }).then(function (response: any){ - if (response.data!=undefined || response.data!==null){ + if (response.data!=undefined && response.data!==null){ switch(response.data.type){ case "GameSolo": let mapSolo = new Map(); @@ -62,14 +61,17 @@ export default class LoaderGameApi implements ILoaderGame{ mapSolo.set(new Number(response.data.keys[i]), new Number(response.data.values[i])) } game = new GameSolo(response.data.id, response.data.name, response.data.image, response.data.nbPlayerMin, response.data.nbPlayerMax, mapSolo); + break; case "GameMulti": const mapMulti = new Map(); for (let i=0; i { let us:User|null=null; const url=this.baseUrl + 'putUser/'+ u.getId() + "/" + u.getUsername() + "/" + u.getPassword() + "/" + u.getSexe() + "/" + u.getNationality() + "/" + u.getCurrentCoins() + "/" + u.getTotalCoins() + "/" + u.getGamesPlayed() + "/" + u.getCurrentSkin().getSkinId(); + console.log(url); await this.axios({ method: 'put', url: url,