From ec69e86a5ee2f66818ba34e89d1f0b70384d55d0 Mon Sep 17 00:00:00 2001 From: Thomas Chazot Date: Tue, 22 Nov 2022 16:58:16 +0100 Subject: [PATCH 01/15] Modif: Utilisation du store au lieu du currentUser --- bob_party/src/screens/Profile.tsx | 9 +++++---- bob_party/src/screens/Settings.tsx | 12 +++++------- bob_party/src/screens/Store.tsx | 3 ++- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/bob_party/src/screens/Profile.tsx b/bob_party/src/screens/Profile.tsx index 6372fed..334d443 100644 --- a/bob_party/src/screens/Profile.tsx +++ b/bob_party/src/screens/Profile.tsx @@ -9,6 +9,7 @@ import { SkinComponent } from '../components/Skin'; import { ButtonGreySmall } from '../components/ButtonGreySmall'; import { ScreenIndicator } from '../components/ScreenIndicator'; import { MANAGER_USER } from '../../App'; +import { useUserStore } from '../../userContext'; const coin = require('../../assets/Icons/Coin.png') @@ -24,22 +25,22 @@ function Profile(props: { navigation: any; }) { /> - {MANAGER_USER.getCurrentUser().getUsername()} + {useUserStore().user?.getUsername()} - {MANAGER_USER.getCurrentUser().getCurrentCoins()} + {useUserStore().user?.getCurrentCoins()} - + navigation.navigate('SkinList')} title='Changer de skin' state='Profile'/> - Total de BobCoin gagnés: {MANAGER_USER.getCurrentUser().getTotalCoins()} + Total de BobCoin gagnés: {useUserStore().user?.getTotalCoins()} Total de BobCoin gagnés: diff --git a/bob_party/src/screens/Settings.tsx b/bob_party/src/screens/Settings.tsx index d30374b..3724b3d 100644 --- a/bob_party/src/screens/Settings.tsx +++ b/bob_party/src/screens/Settings.tsx @@ -29,14 +29,12 @@ function Settings(props: { navigation: any; }) { function changeUsername(username:string){ MANAGER_USER.getCurrentUser()?.setUsername(username); - console.log(MANAGER_USER.getCurrentUser()?.getUsername()); setUser(MANAGER_USER.getCurrentUser()); MANAGER_USER.getsaverUser().updateUser(MANAGER_USER.getCurrentUser()); } function changePassword(password:string){ MANAGER_USER.getCurrentUser()?.setPassword(password); - console.log(MANAGER_USER.getCurrentUser()?.getPassword()); setUser(MANAGER_USER.getCurrentUser()); MANAGER_USER.getsaverUser().updateUser(MANAGER_USER.getCurrentUser()); } @@ -55,24 +53,24 @@ function Settings(props: { navigation: any; }) { - Pseudo: {MANAGER_USER.getCurrentUser().getUsername()} + Pseudo: {useUserStore().user?.getUsername()} {console.log(dialogPseudoVisible); ;setDialogPseudoVisible(true)}} title='Changer le pseudo'/> - Mot de passe: {MANAGER_USER.getCurrentUser().getPassword()} + Mot de passe: {useUserStore().user?.getPassword()} setDialogPasswordVisible(true) } title='Changer le mot de passe'/> - Nationalité: {MANAGER_USER.getCurrentUser().getNationality()} + Nationalité: {useUserStore().user?.getNationality()} setSelectedNationality(value)} donePress={() => dispatch(updateNationality(selectedNationality))} values={["Francais", "Anglais"]} /> - Sexe: {MANAGER_USER.getCurrentUser().getSexe()} + Sexe: {useUserStore().user?.getSexe()} setSelectedSex(value)} donePress={() => dispatch(updateSex(selectedSex))} values={["Homme", "Femme", "Autre"]} /> - ID: {MANAGER_USER.getCurrentUser().getId()} + ID: {useUserStore().user?.getId()} diff --git a/bob_party/src/screens/Store.tsx b/bob_party/src/screens/Store.tsx index 8f0ab85..6599321 100644 --- a/bob_party/src/screens/Store.tsx +++ b/bob_party/src/screens/Store.tsx @@ -8,6 +8,7 @@ import { FlatList } from 'react-native-gesture-handler'; import { SkinComponent } from '../components/Skin'; import { ScreenIndicator } from '../components/ScreenIndicator'; import { MANAGER_USER } from '../../App'; +import { useUserStore } from '../../userContext'; function Store(props: { navigation: any; }) { const { navigation } = props @@ -21,7 +22,7 @@ function Store(props: { navigation: any; }) { item.getSkinName()} From 560c33ee1b23aa18b7e547dcb12cdd8561b88750 Mon Sep 17 00:00:00 2001 From: Thomas Chazot Date: Tue, 22 Nov 2022 17:34:24 +0100 Subject: [PATCH 02/15] =?UTF-8?q?Probl=C3=A8me=20avec=20:=20la=20navigatio?= =?UTF-8?q?n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bob_party/src/components/Skin.tsx | 24 +++++++++++++++++++++--- bob_party/src/components/TopBar.tsx | 5 ++++- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/bob_party/src/components/Skin.tsx b/bob_party/src/components/Skin.tsx index 25f0af7..a0e8a5c 100644 --- a/bob_party/src/components/Skin.tsx +++ b/bob_party/src/components/Skin.tsx @@ -11,16 +11,34 @@ import { useDispatch, useSelector } from "react-redux" import { loginUser } from "../redux/features/currentUserSlice" import { RootState } from "../redux/store" import { MANAGER_USER } from "../../App" +import { useUserStore } from "../../userContext" + + + export const SkinComponent : + + + /* Parameters : * skin : Skin to be displayed * state : Indicates from wich screen the component has been called */ -FC<{skin: Skin, state: String}> = -({skin, state}) => +FC<{nav : any, skin: Skin, state: String}> = +({nav, skin, state}) => { + + console.log(nav); + const dispatch=useDispatch(); + + const setUser = useUserStore((state) => state.setUser); + + function changerSkin(skin:Skin) { + MANAGER_USER.getCurrentUser()?.setCurrentSkin(skin); + setUser(MANAGER_USER.getCurrentUser()); + MANAGER_USER.getsaverUser().updateUser(MANAGER_USER.getCurrentUser()); + } /* The display of this component depends of the screen from where it has been called: @@ -49,7 +67,7 @@ FC<{skin: Skin, state: String}> = ) case 'liste': return( - {MANAGER_USER.getCurrentUser().setCurrentSkin(skin)}} style={styles.imageWrapper}> + {changerSkin(skin); nav.navigate('ProfileTab', {screen: 'Profile'})}} style={styles.imageWrapper}> {skin.getSkinName()} = ({nav, state}) => { + /* The display of this component depends of the screen from where it has been called: * From the Settings (icon) : Name of the page + cross button * From other : skin + Title + parameters icon @@ -49,10 +51,11 @@ FC<{nav: any, state?: string}> = ) default: + return ( nav.navigate('ProfileTab', {screen: 'Profile'})}> - + BOB PARTY nav.navigate('Settings')}> From 82adcd6756316e489e7bac4d4cf892656d6f6a1b Mon Sep 17 00:00:00 2001 From: Thomas Chazot Date: Thu, 24 Nov 2022 19:58:49 +0100 Subject: [PATCH 03/15] =?UTF-8?q?Add:=20Possibilit=C3=A9=20de=20changer=20?= =?UTF-8?q?de=20skin=20avec=20uniqument=20les=20skins=20de=20l'utilisateur?= =?UTF-8?q?=20Possibilit=C3=A9=20d'acheter=20des=20skins=20Store:=20unique?= =?UTF-8?q?ment=20les=20skins=20que=20l'utilisateur=20n'a=20pas=20et=20se?= =?UTF-8?q?=20met=20=C3=A0=20jours?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bob_party/App.tsx | 6 +- bob_party/src/components/BotBar.tsx | 27 ++++++- bob_party/src/components/Skin.tsx | 73 ++++++++++++++++--- bob_party/src/components/TopBar.tsx | 3 +- bob_party/src/context/storeContext.tsx | 22 ++++++ bob_party/{ => src/context}/userContext.tsx | 2 +- bob_party/src/core/User/user.ts | 2 +- bob_party/src/core/User/userCoinsModifier.ts | 10 ++- bob_party/src/core/skin.ts | 4 + bob_party/src/screens/Profile.tsx | 6 +- bob_party/src/screens/Settings.tsx | 27 ++++--- bob_party/src/screens/SignIn.tsx | 4 +- bob_party/src/screens/SkinList.tsx | 5 +- bob_party/src/screens/Store.tsx | 17 +++-- .../services/userServices/loaderUserApi.ts | 3 +- 15 files changed, 164 insertions(+), 47 deletions(-) create mode 100644 bob_party/src/context/storeContext.tsx rename bob_party/{ => src/context}/userContext.tsx (90%) diff --git a/bob_party/App.tsx b/bob_party/App.tsx index d84f013..a15a665 100644 --- a/bob_party/App.tsx +++ b/bob_party/App.tsx @@ -5,7 +5,7 @@ import LoaderUserApi from './src/services/userServices/loaderUserApi' import ManagerUser from './src/services/userServices/ManagerUser' import FakeSaverUser from './src/services/userServices/fakeSaverUser' import React, { useCallback } from 'react'; -import { useUserStore } from './userContext'; +import { useUserStore } from './src/context/userContext'; export const MANAGER_USER = new ManagerUser(new LoaderUserApi, new FakeSaverUser); @@ -32,10 +32,6 @@ export const MANAGER_USER = new ManagerUser(new LoaderUserApi, new FakeSaverUser resetUser(); }, []); - const handleUserChange = useCallback(async () => { - MANAGER_USER.getCurrentUser()?.setCurrentCoins(MANAGER_USER.getCurrentUser()?.getCurrentCoins()+100); - setUser(MANAGER_USER.getCurrentUser()); - }, []); const test = useCallback(async () => { diff --git a/bob_party/src/components/BotBar.tsx b/bob_party/src/components/BotBar.tsx index 439906f..3c2cfe1 100644 --- a/bob_party/src/components/BotBar.tsx +++ b/bob_party/src/components/BotBar.tsx @@ -1,4 +1,4 @@ -import { FC, ReactNode } from "react" +import { FC, ReactNode, useCallback } from "react" import { Pressable, Image, View} from "react-native" import React from "react" @@ -6,6 +6,9 @@ import React from "react" Importing the correct stylesheet */ import styles from './style/BotBar.style'; +import { useStoreStore } from "../context/storeContext"; +import { MANAGER_USER } from "../../App"; +import tabSkinApp from "../constSkin"; /* Images that are required to create a bottom bar @@ -35,6 +38,26 @@ export const BotBar : FC<{nav: any, state?: String}> = ({nav, state}) => { + + const setTabSkin = useStoreStore((state) => state.setTabSkin); + + + const handleStoreChange = useCallback(async () => { + + let tabSkinStore=[...tabSkinApp]; + let tmp=MANAGER_USER.getCurrentUser()?.getTabSkin(); + if (tmp!=undefined){ + tmp.forEach(skin => { + for (let i=0; i = source={imgMid} /> - nav.navigate('StoreTab')}> + {handleStoreChange(); nav.navigate('StoreTab')}}> = ({nav, skin, state}) => { - console.log(nav); + const navigation = nav; const dispatch=useDispatch(); const setUser = useUserStore((state) => state.setUser); - function changerSkin(skin:Skin) { - MANAGER_USER.getCurrentUser()?.setCurrentSkin(skin); - setUser(MANAGER_USER.getCurrentUser()); - MANAGER_USER.getsaverUser().updateUser(MANAGER_USER.getCurrentUser()); + const setTabSkin = useStoreStore((state) => state.setTabSkin); + + + async function changerSkin(skin:Skin) { + const m=new UserSkinModifier(); + const tmp = MANAGER_USER.getCurrentUser(); + if (tmp!=null){ + await m.changeCurrentSkin(tmp, skin); + setUser(tmp); + MANAGER_USER.setCurrentUser(tmp); + } + } + + const handleStoreChange = useCallback(async () => { + + let tabSkinStore=[...tabSkinApp]; + let tmp=MANAGER_USER.getCurrentUser()?.getTabSkin(); + if (tmp!=undefined){ + tmp.forEach(skin => { + for (let i=0; i { + if(res==true){ + await mSkin.addSkin(tmp, skin); + setUser(tmp); + MANAGER_USER.setCurrentUser(tmp); + Alert.alert("Achat du skin"); + handleStoreChange(); + } + else{ + Alert.alert("Pas assez d'argent pour acheter le skin"); + } + }); + } + } + /* The display of this component depends of the screen from where it has been called: @@ -56,7 +109,7 @@ FC<{nav : any, skin: Skin, state: String}> = case 'shop': return( - Alert.alert("Achat du skin")} style={styles.imageWrapper}> + buySkin(skin)} style={styles.imageWrapper}> {skin.getSkinName()} = ) case 'liste': return( - {changerSkin(skin); nav.navigate('ProfileTab', {screen: 'Profile'})}} style={styles.imageWrapper}> + {changerSkin(skin); navigation.goBack()}} style={styles.imageWrapper}> {skin.getSkinName()} = ) case 'profile': return( - Alert.alert("Achat du skin")} style={styles.imageWrapperProfil}> + Alert.alert("cool")} style={styles.imageWrapperProfil}> {skin.getSkinName()} = ({nav, state}) => { - /* The display of this component depends of the screen from where it has been called: * From the Settings (icon) : Name of the page + cross button diff --git a/bob_party/src/context/storeContext.tsx b/bob_party/src/context/storeContext.tsx new file mode 100644 index 0000000..243111c --- /dev/null +++ b/bob_party/src/context/storeContext.tsx @@ -0,0 +1,22 @@ +import React from "react"; +import create from "zustand"; +import { MANAGER_USER } from "../../App"; +import tabSkinApp from "../constSkin"; +import { Skin } from "../core/Skin"; +import { User } from "../core/User/user"; + + +// Define store types +interface StoreState { + tabSkin: Skin[]; + setTabSkin: (tabSkin: Skin[]) => void; + resetTabSkin: () => void; + } + +// Define store data and methods +export const useStoreStore = create()((set, get) => ({ + tabSkin: tabSkinApp, + setTabSkin: (tabSkin) => set((state) => ({ tabSkin: tabSkin })), + resetTabSkin: () => set((state) => ({ tabSkin: tabSkinApp })), +})); + diff --git a/bob_party/userContext.tsx b/bob_party/src/context/userContext.tsx similarity index 90% rename from bob_party/userContext.tsx rename to bob_party/src/context/userContext.tsx index 8696bab..1f81bef 100644 --- a/bob_party/userContext.tsx +++ b/bob_party/src/context/userContext.tsx @@ -1,6 +1,6 @@ import React from "react"; import create from "zustand"; -import { User } from "./src/core/User/user"; +import { User } from "../core/User/user"; // Define store types diff --git a/bob_party/src/core/User/user.ts b/bob_party/src/core/User/user.ts index 085dbec..c337912 100644 --- a/bob_party/src/core/User/user.ts +++ b/bob_party/src/core/User/user.ts @@ -30,7 +30,7 @@ export class User{ this.currentCoins=currentCoins; this.totalCoins=totalCoins; this.currentSkin=currentSkin; - this.tabSkin=[]; + this.tabSkin=tabSkin; } diff --git a/bob_party/src/core/User/userCoinsModifier.ts b/bob_party/src/core/User/userCoinsModifier.ts index ee56c35..44974f1 100644 --- a/bob_party/src/core/User/userCoinsModifier.ts +++ b/bob_party/src/core/User/userCoinsModifier.ts @@ -11,9 +11,13 @@ export class ManagerCoinsUser{ await MANAGER_USER.getsaverUser().updateUser(u); } - async removeCoins(u:User, coins:number){ - u.setCurrentCoins(u.getCurrentCoins()-coins); - await MANAGER_USER.getsaverUser().updateUser(u); + async removeCoins(u:User, coins:number): Promise{ + if (u.getCurrentCoins()>=coins){ + u.setCurrentCoins(u.getCurrentCoins()-coins); + await MANAGER_USER.getsaverUser().updateUser(u); + return true; + } + return false; } async changeCurrentCoins(u:User, coins:number){ diff --git a/bob_party/src/core/skin.ts b/bob_party/src/core/skin.ts index 3ae712f..5351764 100644 --- a/bob_party/src/core/skin.ts +++ b/bob_party/src/core/skin.ts @@ -48,4 +48,8 @@ export class Skin{ setSkinCost(cost:number){ this.cost=cost; } + + isEqual(s:Skin){ + return this.id==s.id; + } } \ No newline at end of file diff --git a/bob_party/src/screens/Profile.tsx b/bob_party/src/screens/Profile.tsx index 334d443..45e0975 100644 --- a/bob_party/src/screens/Profile.tsx +++ b/bob_party/src/screens/Profile.tsx @@ -9,7 +9,7 @@ import { SkinComponent } from '../components/Skin'; import { ButtonGreySmall } from '../components/ButtonGreySmall'; import { ScreenIndicator } from '../components/ScreenIndicator'; import { MANAGER_USER } from '../../App'; -import { useUserStore } from '../../userContext'; +import { useUserStore } from '../context/userContext'; const coin = require('../../assets/Icons/Coin.png') @@ -35,8 +35,8 @@ function Profile(props: { navigation: any; }) { {useUserStore().user?.getCurrentCoins()} - - navigation.navigate('SkinList')} title='Changer de skin' state='Profile'/> + + {navigation.navigate('SkinList');}} title='Changer de skin' state='Profile'/> diff --git a/bob_party/src/screens/Settings.tsx b/bob_party/src/screens/Settings.tsx index 3724b3d..a86ef02 100644 --- a/bob_party/src/screens/Settings.tsx +++ b/bob_party/src/screens/Settings.tsx @@ -11,8 +11,9 @@ import Dialog from "react-native-dialog" import RNPickerSelect from "react-native-picker-select"; import { PickerGreySmall } from '../components/PickerGreySmall'; import { MANAGER_USER } from '../../App'; -import { useUserStore } from '../../userContext'; +import { useUserStore } from '../context/userContext'; import DialogInput from 'react-native-dialog-input'; +import UserModificationManager from '../core/User/userModificationManager'; function Settings(props: { navigation: any; }) { const { navigation } = props @@ -27,16 +28,24 @@ function Settings(props: { navigation: any; }) { const [selectedNationality, setSelectedNationality] = useState(""); - function changeUsername(username:string){ - MANAGER_USER.getCurrentUser()?.setUsername(username); - setUser(MANAGER_USER.getCurrentUser()); - MANAGER_USER.getsaverUser().updateUser(MANAGER_USER.getCurrentUser()); + async function changeUsername(username:string){ + const m = new UserModificationManager(); + let tmp=MANAGER_USER.getCurrentUser(); + if (tmp!=null){ + await m.changeUsername(tmp, username); + setUser(tmp); + MANAGER_USER.setCurrentUser(tmp); + } } - function changePassword(password:string){ - MANAGER_USER.getCurrentUser()?.setPassword(password); - setUser(MANAGER_USER.getCurrentUser()); - MANAGER_USER.getsaverUser().updateUser(MANAGER_USER.getCurrentUser()); + async function changePassword(password:string){ + const m = new UserModificationManager(); + let tmp=MANAGER_USER.getCurrentUser(); + if (tmp!=null){ + await m.changePassword(tmp, password); + setUser(tmp); + MANAGER_USER.setCurrentUser(tmp); + } } const dispatch=useDispatch(); diff --git a/bob_party/src/screens/SignIn.tsx b/bob_party/src/screens/SignIn.tsx index 0bc0db3..304b82a 100644 --- a/bob_party/src/screens/SignIn.tsx +++ b/bob_party/src/screens/SignIn.tsx @@ -10,7 +10,7 @@ import { RootState } from '../redux/store'; import { updateIncorrectCredentials } from '../redux/features/credentialErrorsSlice'; import Dialog from "react-native-dialog"; import { MANAGER_USER } from '../../App'; -import { useUserStore } from '../../userContext'; +import { useUserStore } from '../context/userContext'; @@ -35,8 +35,8 @@ function SignIn(props: { navigation: any; }) { const us =await MANAGER_USER.getLoaderUser().loadByUsernamePassword(pseudo, password).then((res) => { if (res!=null){ MANAGER_USER.setCurrentUser(res); - navigation.navigate('HomeTab'); setUser(MANAGER_USER.getCurrentUser()); + navigation.navigate('HomeTab'); } else{ console.log("wesh c'est null"); diff --git a/bob_party/src/screens/SkinList.tsx b/bob_party/src/screens/SkinList.tsx index de65d94..6b34a4f 100644 --- a/bob_party/src/screens/SkinList.tsx +++ b/bob_party/src/screens/SkinList.tsx @@ -8,6 +8,7 @@ import { FlatList } from 'react-native-gesture-handler'; import { SkinComponent } from '../components/Skin'; import tabSkinApp from '../constSkin'; import { ScreenIndicator } from '../components/ScreenIndicator'; +import { MANAGER_USER } from '../../App'; @@ -22,11 +23,11 @@ function SkinList(props: { navigation: any; }) { item.getSkinName()} - renderItem={({item}) => } /> + renderItem={({item}) => } /> item.getSkinName()} - renderItem={({item}) => } /> + renderItem={({item}) => } /> Date: Sat, 26 Nov 2022 14:13:35 +0100 Subject: [PATCH 04/15] ADD: Chat en fonction des conversations de l'utilisateur --- bob_party/App.tsx | 34 +++-------------- bob_party/src/components/BotBar.tsx | 18 +++++++-- .../src/components/ConversationComponent.tsx | 16 +++++--- bob_party/src/components/Skin.tsx | 4 +- bob_party/src/context/conversationContext.tsx | 20 ++++++++++ bob_party/src/core/User/userCoinsModifier.ts | 2 +- bob_party/src/core/User/userCreator.ts | 2 +- .../src/core/User/userModificationManager.ts | 2 +- bob_party/src/core/conversation.ts | 2 +- bob_party/src/screens/Chat.tsx | 12 +++--- bob_party/src/screens/SignIn.tsx | 6 +-- .../fakeSaverConversation.ts | 14 +++++++ .../loaderConversationApi.ts | 38 +++++++++++++++++++ .../managerConversation.ts | 34 +++++++++++++++++ 14 files changed, 151 insertions(+), 53 deletions(-) create mode 100644 bob_party/src/context/conversationContext.tsx create mode 100644 bob_party/src/services/conversationService/fakeSaverConversation.ts create mode 100644 bob_party/src/services/conversationService/loaderConversationApi.ts create mode 100644 bob_party/src/services/conversationService/managerConversation.ts diff --git a/bob_party/App.tsx b/bob_party/App.tsx index a15a665..8442ede 100644 --- a/bob_party/App.tsx +++ b/bob_party/App.tsx @@ -2,43 +2,19 @@ import MainTabNavigator from './src/navigation/AppNavigator' import store from './src/redux/store' import { Provider } from 'react-redux' import LoaderUserApi from './src/services/userServices/loaderUserApi' -import ManagerUser from './src/services/userServices/ManagerUser' +import ManagerUser from './src/services/userServices/managerUser' import FakeSaverUser from './src/services/userServices/fakeSaverUser' import React, { useCallback } from 'react'; import { useUserStore } from './src/context/userContext'; +import ManagerConversation from './src/services/conversationService/managerConversation' +import { LoaderConversationApi } from './src/services/conversationService/loaderConversationApi' +import { FakeSaverConversation } from './src/services/conversationService/fakeSaverConversation' export const MANAGER_USER = new ManagerUser(new LoaderUserApi, new FakeSaverUser); - +export const MANAGER_CONVERSATION = new ManagerConversation(new LoaderConversationApi, new FakeSaverConversation); export default function App() { - const setUser = useUserStore((state) => state.setUser); - const resetUser = useUserStore((state) => state.resetUser); - - const handleUserConnect = useCallback(async () => { - - await MANAGER_USER.getLoaderUser().loadByID("14").then((res) => { - MANAGER_USER.setCurrentUser(res); - console.log(res); - }); - setUser(MANAGER_USER.getCurrentUser()); - - - }, []); - - const handleUserLogout = useCallback(async () => { - // TODO: Call logout API - MANAGER_USER.setCurrentUser(null); - resetUser(); - }, []); - - - - const test = useCallback(async () => { - const tab = await MANAGER_USER.getLoaderUser().loadAllUser(); - MANAGER_USER.setCurrentUser(tab[0]); - setUser(MANAGER_USER.getCurrentUser()); - }, []); return ( diff --git a/bob_party/src/components/BotBar.tsx b/bob_party/src/components/BotBar.tsx index 3c2cfe1..c7c51ef 100644 --- a/bob_party/src/components/BotBar.tsx +++ b/bob_party/src/components/BotBar.tsx @@ -7,8 +7,9 @@ import React from "react" */ import styles from './style/BotBar.style'; import { useStoreStore } from "../context/storeContext"; -import { MANAGER_USER } from "../../App"; +import { MANAGER_CONVERSATION, MANAGER_USER } from "../../App"; import tabSkinApp from "../constSkin"; +import { useConversationStore } from "../context/conversationContext"; /* Images that are required to create a bottom bar @@ -40,7 +41,7 @@ FC<{nav: any, state?: String}> = { const setTabSkin = useStoreStore((state) => state.setTabSkin); - + const setTabConv = useConversationStore((state) => state.setTabConv); const handleStoreChange = useCallback(async () => { @@ -57,6 +58,17 @@ FC<{nav: any, state?: String}> = setTabSkin(tabSkinStore); } }, []); + + const handleConversationChange = useCallback(async () => { + let tmp=MANAGER_USER.getCurrentUser(); + if (tmp!=undefined){ + await MANAGER_CONVERSATION.getLoaderConversation().loadByUser(tmp).then((res) => { + MANAGER_CONVERSATION.setCurrentTabConv(res); + setTabConv(res); + }); + } + + }, []); /* By default, all the images are the white ones @@ -89,7 +101,7 @@ FC<{nav: any, state?: String}> = */ return ( - nav.navigate('ChatTab')}> + {handleConversationChange() ;nav.navigate('ChatTab')}}> = -({conv, state}) => -{ +FC<{conv: Conversation, state: String, navigation: any}> = +({conv, state, navigation}) => +{ /* The display of this component depends of the screen from where it has been called: * From the TopBar (icon) : Small image in a circle * From the shop (shop) : Image + Name + Price, Pressable => Buy the skin * From the profile (profile) : Name + Image, Pressable => Change the skin */ + + switch (state) { case 'Preview': return( - + - {conv.getTabUser()[1].getUsername()} - {conv.getLastMessage()} + {conv.getLastMessage().getMessageSender().getUsername()} + {conv.getLastMessage().getMessageContent()} ) diff --git a/bob_party/src/components/Skin.tsx b/bob_party/src/components/Skin.tsx index e6f587b..b4120ea 100644 --- a/bob_party/src/components/Skin.tsx +++ b/bob_party/src/components/Skin.tsx @@ -13,7 +13,7 @@ import { RootState } from "../redux/store" import { MANAGER_USER } from "../../App" import { useUserStore } from "../context/userContext" import { ManagerCoinsUser } from "../core/User/userCoinsModifier" -import ManagerUser from "../services/userServices/ManagerUser" +import ManagerUser from "../services/userServices/managerUser" import UserSkinModifier from "../core/User/userSkinModifier" import { useStoreStore } from "../context/storeContext" import tabSkinApp from "../constSkin" @@ -68,7 +68,7 @@ FC<{nav : any, skin: Skin, state: String}> = } - }, []); + }, []); async function buySkin(skin:Skin) { const mSkin=new UserSkinModifier(); diff --git a/bob_party/src/context/conversationContext.tsx b/bob_party/src/context/conversationContext.tsx new file mode 100644 index 0000000..215674e --- /dev/null +++ b/bob_party/src/context/conversationContext.tsx @@ -0,0 +1,20 @@ +import React from "react"; +import create from "zustand"; +import { MANAGER_USER } from "../../App"; +import { Conversation } from "../core/conversation"; + + +// Define store types +interface ConversationState { + tabConv: Conversation[] | undefined; + setTabConv: (tabConv: Conversation[]) => void; + resetTabConv: () => void; + } + +// Define store data and methods +export const useConversationStore = create()((set, get) => ({ + tabConv: undefined, + setTabConv: (tabConv) => set((state) => ({ tabConv: tabConv })), + resetTabConv: () => set((state) => ({tabConv: undefined})), +})); + diff --git a/bob_party/src/core/User/userCoinsModifier.ts b/bob_party/src/core/User/userCoinsModifier.ts index 44974f1..1bb0e1b 100644 --- a/bob_party/src/core/User/userCoinsModifier.ts +++ b/bob_party/src/core/User/userCoinsModifier.ts @@ -1,5 +1,5 @@ import { MANAGER_USER } from "../../../App"; -import ManagerUser from "../../services/userServices/ManagerUser"; +import ManagerUser from "../../services/userServices/managerUser"; import { User } from "./user"; export class ManagerCoinsUser{ diff --git a/bob_party/src/core/User/userCreator.ts b/bob_party/src/core/User/userCreator.ts index 142a72b..18be053 100644 --- a/bob_party/src/core/User/userCreator.ts +++ b/bob_party/src/core/User/userCreator.ts @@ -1,7 +1,7 @@ import { User } from "./user"; import tabSkinApp from "../../constSkin"; import { Conversation } from "../conversation"; -import ManagerUser from "../../services/userServices/ManagerUser"; +import ManagerUser from "../../services/userServices/managerUser"; import { MANAGER_USER } from "../../../App"; export class UserCreator{ diff --git a/bob_party/src/core/User/userModificationManager.ts b/bob_party/src/core/User/userModificationManager.ts index 808e0ac..26af738 100644 --- a/bob_party/src/core/User/userModificationManager.ts +++ b/bob_party/src/core/User/userModificationManager.ts @@ -9,7 +9,7 @@ export default class UserModificationManager{ } async changeUsername(user:User, username:string){ - user.setPassword(username); + user.setUsername(username); await MANAGER_USER.getsaverUser().updateUser(user); } diff --git a/bob_party/src/core/conversation.ts b/bob_party/src/core/conversation.ts index 5d4eed3..ac94d9a 100644 --- a/bob_party/src/core/conversation.ts +++ b/bob_party/src/core/conversation.ts @@ -56,7 +56,7 @@ export class Conversation{ /* Brief : function returning the last message of a conversation */ getLastMessage(){ this.sortMessageDesc(); - return this.tabMessage[0].getMessageContent(); + return this.tabMessage[0]; } /* Brief : function sorting the messages of a conversation to be in the discussion order */ diff --git a/bob_party/src/screens/Chat.tsx b/bob_party/src/screens/Chat.tsx index 2d243d1..b2cc9d1 100644 --- a/bob_party/src/screens/Chat.tsx +++ b/bob_party/src/screens/Chat.tsx @@ -1,15 +1,17 @@ import { StatusBar } from 'expo-status-bar' import {View} from 'react-native' -import React from 'react'; +import React, { useCallback } from 'react'; import stylesScreen from './style/screens.style'; import { TopBar } from '../components/TopBar'; import { BotBar } from '../components/BotBar'; import { FlatList } from 'react-native-gesture-handler'; import { ConversationComponent } from '../components/ConversationComponent'; +import { Conversation } from '../core/conversation'; +import { MANAGER_CONVERSATION, MANAGER_USER } from '../../App'; +import { useConversationStore } from '../context/conversationContext'; function Chat(props: { navigation: any; }) { const { navigation } = props - return ( @@ -18,12 +20,10 @@ function Chat(props: { navigation: any; }) { /> - {/* } + data={useConversationStore().tabConv} + renderItem={({item}) => } /> - */} { - const us =await MANAGER_USER.getLoaderUser().loadByUsernamePassword(pseudo, password).then((res) => { + await MANAGER_USER.getLoaderUser().loadByUsernamePassword(pseudo, password).then((res) => { if (res!=null){ MANAGER_USER.setCurrentUser(res); setUser(MANAGER_USER.getCurrentUser()); @@ -41,9 +41,9 @@ function SignIn(props: { navigation: any; }) { else{ console.log("wesh c'est null"); } - }); + }); - }, []); + }, []); return ( diff --git a/bob_party/src/services/conversationService/fakeSaverConversation.ts b/bob_party/src/services/conversationService/fakeSaverConversation.ts new file mode 100644 index 0000000..907cf07 --- /dev/null +++ b/bob_party/src/services/conversationService/fakeSaverConversation.ts @@ -0,0 +1,14 @@ +import { Conversation } from "../../core/conversation"; +import ISaverConversation from "./ISaverConversation"; + +export class FakeSaverConversation implements ISaverConversation{ + async saveConversation(c: Conversation): Promise { + return; + } + async deleteConversation(c: Conversation): Promise { + return; + } + async updateConversation(c: Conversation): Promise { + return; + } +} \ No newline at end of file diff --git a/bob_party/src/services/conversationService/loaderConversationApi.ts b/bob_party/src/services/conversationService/loaderConversationApi.ts new file mode 100644 index 0000000..ae78e87 --- /dev/null +++ b/bob_party/src/services/conversationService/loaderConversationApi.ts @@ -0,0 +1,38 @@ +import { Conversation } from "../../core/conversation"; +import { Message } from "../../core/message"; +import { Skin } from "../../core/skin"; +import { User } from "../../core/User/user"; +import ILoaderConversation from "./ILoaderConversation"; + +export class LoaderConversationApi implements ILoaderConversation{ + + private axios = require('axios').default; + + loadAllConversation(): Promise { + throw new Error("Method not implemented."); + } + loadByID(id: string): Promise { + throw new Error("Method not implemented."); + } + async loadByUser(u: User): Promise { + + let tabConv:Conversation[]=[]; + await this.axios({ + method: 'get', + url: 'https://jsonplaceholder.typicode.com/todos/1', + params: { + name: "getConversationByUser", + //Les params genre nom de la fonction en php + } + }) + .then(function (response: any) { + tabConv=[new Conversation("C0001", + [new User("U0001", "Alban", "oui", "ouioui", "homme", new Date(2022,12,12), 555, 667, 12, new Skin("S0001", "Bob",require('bob_party/assets/BobsSkins/BobClassic.png'), 0), [new Skin("S0001", "Bob",require('bob_party/assets/BobsSkins/BobClassic.png'), 0)]), + new User("U0002", "Fefe63", "jesuishm", "ouioui", "homme", new Date(2022,12,12), 12222, 123324, 12, new Skin("S0001", "Bob",require('bob_party/assets/BobsSkins/BobClassic.png'), 0), [new Skin("S0001", "Bob",require('bob_party/assets/BobsSkins/BobClassic.png'), 0)]),], + [new Message("M0001", "bonjour", new User("U0001", "Alban", "oui", "ouioui", "homme", new Date(2022,12,12), 555, 667, 12, new Skin("S0001", "Bob",require('bob_party/assets/BobsSkins/BobClassic.png'), 0), [new Skin("S0001", "Bob",require('bob_party/assets/BobsSkins/BobClassic.png'), 0)]), new Date(2022,12,12)), + new Message("M0002", "test", new User("U0002", "Fefe63", "oui", "ouioui", "homme", new Date(2022,12,12), 555, 667, 12, new Skin("S0002", "Bob Blue",require('bob_party/assets/BobsSkins/BobBlue.png'), 100), [new Skin("S0002", "Bob Blue",require('bob_party/assets/BobsSkins/BobBlue.png'), 100)]), new Date(2022,12,13))], "leNom")]; + }); + return tabConv; + } + +} \ No newline at end of file diff --git a/bob_party/src/services/conversationService/managerConversation.ts b/bob_party/src/services/conversationService/managerConversation.ts new file mode 100644 index 0000000..0e4758b --- /dev/null +++ b/bob_party/src/services/conversationService/managerConversation.ts @@ -0,0 +1,34 @@ +import { Conversation } from "../../core/conversation"; +import { User } from "../../core/User/user"; +import ILoaderConversation from "./ILoaderConversation"; +import ISaverConversation from "./ISaverConversation"; + +export default class ManagerConversation{ + + private currentTabConv:Conversation[]=[]; + + private loaderConversation: ILoaderConversation; + + private saverConversation: ISaverConversation; + + constructor(loaderConversation:ILoaderConversation, saverConversation:ISaverConversation){ + this.loaderConversation=loaderConversation; + this.saverConversation=saverConversation; + } + + getCurrentTabConv(){ + return this.currentTabConv; + } + + setCurrentTabConv(c:Conversation[]){ + this.currentTabConv=c; + } + + getLoaderConversation(){ + return this.loaderConversation; + } + + getsaverConversation(){ + return this.saverConversation; + } +} \ No newline at end of file From 570ade854aca82c457db59d78d28bda2930db714 Mon Sep 17 00:00:00 2001 From: Thomas Chazot Date: Mon, 5 Dec 2022 16:56:15 +0100 Subject: [PATCH 05/15] Ajout du cookie clicker, Alban relie au reste stp --- .../src/Games/CookieClicker/cookieClicker.tsx | 216 ++++++++++++++++++ bob_party/src/components/GameComponent.tsx | 2 +- bob_party/src/screens/GameChoice.tsx | 4 +- 3 files changed, 219 insertions(+), 3 deletions(-) create mode 100644 bob_party/src/Games/CookieClicker/cookieClicker.tsx diff --git a/bob_party/src/Games/CookieClicker/cookieClicker.tsx b/bob_party/src/Games/CookieClicker/cookieClicker.tsx new file mode 100644 index 0000000..74b92a9 --- /dev/null +++ b/bob_party/src/Games/CookieClicker/cookieClicker.tsx @@ -0,0 +1,216 @@ +import React, { Component, useEffect, useState } from 'react' +import { + StyleSheet, + TouchableOpacity, + Text, + View, + Pressable, + Image, + TouchableHighlight, + Alert, +} from 'react-native' +import { MANAGER_USER } from '../../../App'; +import { useUserStore } from '../../context/userContext'; +import { Match } from '../../core/match'; +import { User } from '../../core/User/user'; + + +function CookieClicker(props: { navigation: any, match:Match}){ + + const GAMING_TIME=15; + + const setUser = useUserStore((state) => state.setUser); + + const nav = props.navigation; + const match=props.match; + + const [count, setCount] = useState(0); + const [money, setMoney] = useState(0); + const [clickSpeed, setClickSpeed] = useState(1); + const [grandmaCost, setGrandmaCost] = useState(10); + const [farmCost, setFarmCost] = useState(250); + const [factoryCost, setFactoryCost] = useState(2000); + const [wizardCost, setWizardCost] = useState(25000); + const [portalCost, setPortalCost] = useState(200000); + + const [timer, setTimer] = useState(GAMING_TIME); + + + function onPressCookie(){ + setMoney(money+clickSpeed); + setCount(count+clickSpeed); + } + + function onPressGrandma(){ + if (money>=grandmaCost){ + setMoney(money-grandmaCost); + setClickSpeed(clickSpeed+1); + setGrandmaCost(grandmaCost+10); + } + } + + function onPressFarm(){ + if (money>=farmCost){ + setMoney(money-farmCost); + setClickSpeed(clickSpeed+25); + setFarmCost(farmCost+250); + } + } + + function onPressFactory(){ + if (money>=factoryCost){ + setMoney(money-factoryCost); + setClickSpeed(clickSpeed+200); + setFactoryCost(factoryCost+2000); + } + } + + function onPressWizard(){ + if (money>=wizardCost){ + setMoney(money-wizardCost); + setClickSpeed(clickSpeed+2500); + setWizardCost(wizardCost+25000); + } + } + + function onPressPortal(){ + if (money>=portalCost){ + setMoney(money-portalCost); + setClickSpeed(clickSpeed+20000); + setPortalCost(portalCost+200000); + } + } + + function endGame(){ + let tmp: User | null; + tmp=MANAGER_USER.getCurrentUser(); + if (tmp!=null){ + if (match.getTabUsers().includes(tmp)){ + match.updatePostMatch(tmp, count); + setUser(tmp); + nav.goBack(); + } + } + } + + useEffect(() => { + let counter=GAMING_TIME; + var oneSecInterval = setInterval(() => { + setTimer(timer => timer - 1); + counter --; + + if (counter == 0) { + clearInterval(oneSecInterval); + Alert.alert("fin du jeu"); + endGame(); + } + }, 1000); + },[]); + + + return ( + + + + Timer: {timer} + + + + + + Argent {money} + + + Points {count} + + + + + + + + + Cost {grandmaCost} + + + + + + + + + Cost {farmCost} + + + + + + + + + Cost {factoryCost} + + + + + + + + + Cost {wizardCost} + + + + + + + + + Cost {portalCost} + + + + + + ) + } + +const styles = StyleSheet.create({ + container: { + top: 5, + margin: 10, + flex: 1, + justifyContent: 'center', + alignItems: 'center', + }, + containerRight: { + flex: 1, + flexWrap: "wrap", + top: 100, + marginBottom: 20, + left: 100, + }, + + button: { + alignItems: 'center', + backgroundColor: '#DDDDDD', + padding: 10, + marginBottom: 10 + }, + button2: { + alignItems: 'center', + backgroundColor: '#FFDDFF', + padding: 10, + marginBottom: 10 + }, + photo: { + width: 50, + height: 50 + }, + cout: { + marginBottom: 20 + } + +}) + +export default CookieClicker; \ No newline at end of file diff --git a/bob_party/src/components/GameComponent.tsx b/bob_party/src/components/GameComponent.tsx index fdaa8b7..c778e09 100644 --- a/bob_party/src/components/GameComponent.tsx +++ b/bob_party/src/components/GameComponent.tsx @@ -19,7 +19,7 @@ FC<{game: Game, nav: any}> = { return ( - Alert.alert("Lancement du jeu")}> + nav.navigate('')}> ); +const cookieClicker= new GameSolo("1", "Cookie Clicker", require('../../assets/Icons/UnSelected/Gamepad.png'), "/Games/CookieClicker/cookieClicker.tsx", 1, 1, new Map); function GameChoice(props: { navigation: any; }) { const { navigation } = props return ( @@ -26,7 +26,7 @@ function GameChoice(props: { navigation: any; }) { /> From 8e1b296011e9790dddc2271173b1fedc5b9acdf2 Mon Sep 17 00:00:00 2001 From: Thomas Chazot Date: Tue, 6 Dec 2022 14:31:12 +0100 Subject: [PATCH 06/15] Add: Match Services --- bob_party/App.tsx | 5 +++ .../src/Games/CookieClicker/cookieClicker.tsx | 13 +++--- bob_party/src/components/GameComponent.tsx | 4 +- bob_party/src/components/Skin.tsx | 10 ++--- bob_party/src/constSkin.ts | 14 +++---- bob_party/src/core/Game.ts | 8 ++-- bob_party/src/core/{ => Match}/match.ts | 12 +++--- bob_party/src/core/{ => Match}/matchCasino.ts | 12 +++--- bob_party/src/core/Match/matchCreator.ts | 12 ++++++ bob_party/src/core/Match/matchMulti.ts | 17 ++++++++ bob_party/src/core/Match/matchSolo.ts | 17 ++++++++ bob_party/src/core/User/user.ts | 4 +- bob_party/src/core/User/userCreator.ts | 16 +------- bob_party/src/core/conversation.ts | 8 ++-- bob_party/src/core/gameCasino.ts | 2 +- bob_party/src/core/gameMulti.ts | 2 +- bob_party/src/core/gameSolo.ts | 2 +- bob_party/src/core/matchMulti.ts | 17 -------- bob_party/src/core/matchSolo.ts | 17 -------- bob_party/src/core/message.ts | 32 +++++++-------- bob_party/src/core/skin.ts | 8 ++-- bob_party/src/core/tests/conversation.test.ts | 16 ++++---- bob_party/src/core/tests/matchSolo.test.ts | 2 +- bob_party/src/navigation/AppNavigator.tsx | 4 +- bob_party/src/screens/GameChoice.tsx | 2 +- .../loaderConversationApi.ts | 11 ++--- .../services/matchServices/ILoaderMatch.ts | 2 +- .../src/services/matchServices/ISaverMatch.ts | 6 ++- .../services/matchServices/loaderMatchApi.ts | 13 ++++++ .../services/matchServices/managerMatch.ts | 41 +++++++++++++++++++ .../services/matchServices/saverMatchApi.ts | 32 +++++++++++++++ .../src/services/userServices/ILoaderUser.ts | 6 +-- .../src/services/userServices/ISaverUser.ts | 2 +- .../services/userServices/fakeSaverUser.ts | 4 +- .../services/userServices/loaderUserApi.ts | 17 ++++---- .../src/services/userServices/saverUserApi.ts | 13 ++++-- bob_party/src/services/userServices/stub.ts | 15 +++---- 37 files changed, 261 insertions(+), 157 deletions(-) rename bob_party/src/core/{ => Match}/match.ts (83%) rename bob_party/src/core/{ => Match}/matchCasino.ts (50%) create mode 100644 bob_party/src/core/Match/matchCreator.ts create mode 100644 bob_party/src/core/Match/matchMulti.ts create mode 100644 bob_party/src/core/Match/matchSolo.ts delete mode 100644 bob_party/src/core/matchMulti.ts delete mode 100644 bob_party/src/core/matchSolo.ts create mode 100644 bob_party/src/services/matchServices/loaderMatchApi.ts create mode 100644 bob_party/src/services/matchServices/managerMatch.ts create mode 100644 bob_party/src/services/matchServices/saverMatchApi.ts diff --git a/bob_party/App.tsx b/bob_party/App.tsx index 8442ede..87920dc 100644 --- a/bob_party/App.tsx +++ b/bob_party/App.tsx @@ -9,10 +9,15 @@ import { useUserStore } from './src/context/userContext'; import ManagerConversation from './src/services/conversationService/managerConversation' import { LoaderConversationApi } from './src/services/conversationService/loaderConversationApi' import { FakeSaverConversation } from './src/services/conversationService/fakeSaverConversation' +import ManagerMatch from './src/services/matchServices/managerMatch' +import LoaderMatchApi from './src/services/matchServices/loaderMatchApi' +import SaverMatchApi from './src/services/matchServices/saverMatchApi' export const MANAGER_USER = new ManagerUser(new LoaderUserApi, new FakeSaverUser); export const MANAGER_CONVERSATION = new ManagerConversation(new LoaderConversationApi, new FakeSaverConversation); +export const MANAGER_MATCH = new ManagerMatch(new LoaderMatchApi, new SaverMatchApi); + export default function App() { diff --git a/bob_party/src/Games/CookieClicker/cookieClicker.tsx b/bob_party/src/Games/CookieClicker/cookieClicker.tsx index 74b92a9..38c3c61 100644 --- a/bob_party/src/Games/CookieClicker/cookieClicker.tsx +++ b/bob_party/src/Games/CookieClicker/cookieClicker.tsx @@ -11,18 +11,18 @@ import { } from 'react-native' import { MANAGER_USER } from '../../../App'; import { useUserStore } from '../../context/userContext'; -import { Match } from '../../core/match'; +import { Match } from '../../core/Match/match'; import { User } from '../../core/User/user'; -function CookieClicker(props: { navigation: any, match:Match}){ +function CookieClicker(props: { navigation: any}){ + const { navigation } = props + const GAMING_TIME=15; const setUser = useUserStore((state) => state.setUser); - const nav = props.navigation; - const match=props.match; const [count, setCount] = useState(0); const [money, setMoney] = useState(0); @@ -85,11 +85,14 @@ function CookieClicker(props: { navigation: any, match:Match}){ let tmp: User | null; tmp=MANAGER_USER.getCurrentUser(); if (tmp!=null){ + /* if (match.getTabUsers().includes(tmp)){ match.updatePostMatch(tmp, count); setUser(tmp); - nav.goBack(); + } + */ + navigation.goBack(); } } diff --git a/bob_party/src/components/GameComponent.tsx b/bob_party/src/components/GameComponent.tsx index c778e09..7f74b07 100644 --- a/bob_party/src/components/GameComponent.tsx +++ b/bob_party/src/components/GameComponent.tsx @@ -19,10 +19,10 @@ FC<{game: Game, nav: any}> = { return ( - nav.navigate('')}> + nav.navigate("CookieClicker")}> {game.getName()} diff --git a/bob_party/src/components/Skin.tsx b/bob_party/src/components/Skin.tsx index b4120ea..a09101d 100644 --- a/bob_party/src/components/Skin.tsx +++ b/bob_party/src/components/Skin.tsx @@ -103,7 +103,7 @@ FC<{nav : any, skin: Skin, state: String}> = case 'icon': return ( - + ) @@ -113,7 +113,7 @@ FC<{nav : any, skin: Skin, state: String}> = {skin.getSkinName()} 100€ @@ -124,7 +124,7 @@ FC<{nav : any, skin: Skin, state: String}> = {skin.getSkinName()} ) @@ -134,7 +134,7 @@ FC<{nav : any, skin: Skin, state: String}> = {skin.getSkinName()} ) @@ -142,7 +142,7 @@ FC<{nav : any, skin: Skin, state: String}> = return( ) } diff --git a/bob_party/src/constSkin.ts b/bob_party/src/constSkin.ts index 473c83e..395c45e 100644 --- a/bob_party/src/constSkin.ts +++ b/bob_party/src/constSkin.ts @@ -1,13 +1,13 @@ import { Skin } from "./core/skin"; let tabSkinApp:Skin[]=[ - new Skin("S0001", "Bob",require('bob_party/assets/BobsSkins/BobClassic.png'), 0), - new Skin("S0002", "Bob Blue",require('bob_party/assets/BobsSkins/BobBlue.png'), 100), - new Skin("S0003", "Bob BW",require('bob_party/assets/BobsSkins/BobBW.png'), 100), - new Skin("S0004", "Bob Green",require('bob_party/assets/BobsSkins/BobGreen.png'), 100), - new Skin("S0005", "Bob P&T",require('bob_party/assets/BobsSkins/BobPinkTurquoise.png'), 100), - new Skin("S0006", "Bob Red",require('bob_party/assets/BobsSkins/BobRed.png'), 100), - new Skin("S0007", "Bob Cute",require('bob_party/assets/BobsSkins/BobYellowGreenBlueHeart.png'), 100), + new Skin(1, "Bob","https://codefirst.iut.uca.fr/git/BOB_PARTEAM/BOB_PARTY/raw/branch/typescript/bob_party/assets/BobsSkins/BobClassic.png", 0), + new Skin(2, "Bob Blue","https://codefirst.iut.uca.fr/git/BOB_PARTEAM/BOB_PARTY/raw/branch/typescript/bob_party/assets/BobsSkins/BobBlue.png", 100), + new Skin(3, "Bob BW","https://codefirst.iut.uca.fr/git/BOB_PARTEAM/BOB_PARTY/raw/branch/typescript/bob_party/assets/BobsSkins/BobBW.png", 100), + new Skin(4, "Bob Green","https://codefirst.iut.uca.fr/git/BOB_PARTEAM/BOB_PARTY/raw/branch/typescript/bob_party/assets/BobsSkins/BobGreen.png", 100), + new Skin(5, "Bob P&T", "https://codefirst.iut.uca.fr/git/BOB_PARTEAM/BOB_PARTY/raw/branch/typescript/bob_party/assets/BobsSkins/BobPinkTurquoise.png", 100), + new Skin(6, "Bob Red", "https://codefirst.iut.uca.fr/git/BOB_PARTEAM/BOB_PARTY/raw/branch/typescript/bob_party/assets/BobsSkins/BobRed.png", 100), + new Skin(7, "Bob Cute", "https://codefirst.iut.uca.fr/git/BOB_PARTEAM/BOB_PARTY/raw/branch/typescript/bob_party/assets/BobsSkins/BobYellowGreenBlueHeart.png", 100), ] diff --git a/bob_party/src/core/Game.ts b/bob_party/src/core/Game.ts index 2274d6c..337c734 100644 --- a/bob_party/src/core/Game.ts +++ b/bob_party/src/core/Game.ts @@ -3,15 +3,15 @@ import { ImageSourcePropType } from "react-native"; import internal from "stream"; export abstract class Game{ - readonly id:string; + readonly id:number; private name:string; - private imageSource:ImageSourcePropType; + private imageSource:string; private gameSource:string; private nbPlayerMin: number; private nbPlayerMax:number; /* Constructor of the class */ - constructor (id:string, name:string, imageSource:ImageSourcePropType, gameSource:string, nbPlayerMin:number, nbPlayerMax:number){ + constructor (id:number, name:string, imageSource:string, gameSource:string, nbPlayerMin:number, nbPlayerMax:number){ this.id=id; this.name=name; this.imageSource=imageSource; @@ -41,7 +41,7 @@ export abstract class Game{ } /* Brief : Function setting the image of a game */ - setImageSource(imageSource:ImageSourcePropType){ + setImageSource(imageSource:string){ this.imageSource=imageSource; } diff --git a/bob_party/src/core/match.ts b/bob_party/src/core/Match/match.ts similarity index 83% rename from bob_party/src/core/match.ts rename to bob_party/src/core/Match/match.ts index 4ecfacc..3265e5c 100644 --- a/bob_party/src/core/match.ts +++ b/bob_party/src/core/Match/match.ts @@ -1,17 +1,17 @@ import { ImageSourcePropType } from 'react-native'; -import { Game } from './game'; -import { User } from "./User/user"; +import { Game } from '../game'; +import { User } from "../User/user"; export abstract class Match{ - readonly code:string; - private inGame:Boolean; + readonly code:number; + private inGame:Boolean=false; private tabUsers:User[]; private theGame:Game; - constructor(code:string, inGame:Boolean, tabUser:User[], game:Game){ + constructor(code:number, inGame:Boolean, tabUser:User[], game:Game){ this.code=code; - this.inGame=false; + this.inGame=inGame; this.tabUsers=[...tabUser]; this.theGame=game; } diff --git a/bob_party/src/core/matchCasino.ts b/bob_party/src/core/Match/matchCasino.ts similarity index 50% rename from bob_party/src/core/matchCasino.ts rename to bob_party/src/core/Match/matchCasino.ts index f758b48..6376812 100644 --- a/bob_party/src/core/matchCasino.ts +++ b/bob_party/src/core/Match/matchCasino.ts @@ -1,12 +1,12 @@ import { Match } from "./match"; -import { User } from "./User/user"; -import { Game } from "./game"; -import { GameCasino } from "./gameCasino"; -import { ManagerCoinsUser } from "./User/userCoinsModifier"; +import { User } from "../User/user"; +import { Game } from "../game"; +import { GameCasino } from "../gameCasino"; +import { ManagerCoinsUser } from "../User/userCoinsModifier"; -export class MatchMulti extends Match{ +export default class MatchCasino extends Match{ - constructor(code:string, inGame:Boolean, tabUser:User[], game:GameCasino){ + constructor(code:number, inGame:Boolean, tabUser:User[], game:GameCasino){ super(code, inGame, tabUser, game); } diff --git a/bob_party/src/core/Match/matchCreator.ts b/bob_party/src/core/Match/matchCreator.ts new file mode 100644 index 0000000..22f5eb4 --- /dev/null +++ b/bob_party/src/core/Match/matchCreator.ts @@ -0,0 +1,12 @@ +import { MANAGER_MATCH } from "../../../App"; +import ManagerMatch from "../../services/matchServices/managerMatch"; +import { Game } from "../game"; +import { User } from "../User/user"; +import { Match } from "./match"; + +export default class MatchCreator{ + + async createMatchSolo(u:User, g:Game): Promise{ + return await MANAGER_MATCH.getsaverMatch().saveMatch(u, g); + } +} \ No newline at end of file diff --git a/bob_party/src/core/Match/matchMulti.ts b/bob_party/src/core/Match/matchMulti.ts new file mode 100644 index 0000000..c72ba66 --- /dev/null +++ b/bob_party/src/core/Match/matchMulti.ts @@ -0,0 +1,17 @@ +import { Match } from "./match"; +import { User } from "../User/user"; +import { Game } from "../game"; +import { GameMulti } from "../gameMulti"; +import { ManagerCoinsUser } from "../User/userCoinsModifier"; + +export default class MatchMulti extends Match{ + + constructor(code:number, inGame:Boolean, tabUser:User[], game:GameMulti){ + super(code, inGame, tabUser, game); + } + + updatePostMatch(user:User, points: number): void { + const manage= new ManagerCoinsUser(); + 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 new file mode 100644 index 0000000..fef2170 --- /dev/null +++ b/bob_party/src/core/Match/matchSolo.ts @@ -0,0 +1,17 @@ +import { Match } from "./match"; +import { GameSolo } from "../gameSolo"; +import { User } from "../User/user"; +import { Game } from "../game"; +import { ManagerCoinsUser } from "../User/userCoinsModifier"; + +export default class MatchSolo extends Match{ + + constructor(code:number, inGame:Boolean, tabUser:User[], game:GameSolo){ + super(code, inGame, tabUser, game); + } + + updatePostMatch(user:User, points: number): void { + const manage= new ManagerCoinsUser(); + manage.addCoins(user, this.getGame().coinsCalculator(points)); + } +} \ No newline at end of file diff --git a/bob_party/src/core/User/user.ts b/bob_party/src/core/User/user.ts index c337912..e49404f 100644 --- a/bob_party/src/core/User/user.ts +++ b/bob_party/src/core/User/user.ts @@ -5,7 +5,7 @@ import { TextBase } from 'react-native'; export class User{ - readonly id: string; + readonly id: number; private username: string; private password: string; private nationality: string; @@ -18,7 +18,7 @@ export class User{ private tabSkin: Skin[]; /* Consturctor of the class */ - constructor(id: string, username: string, password:string, nationality: string, sexe: string, dateOfBirth: Date, currentCoins: number, totalCoins: number, + constructor(id: number, username: string, password:string, nationality: string, sexe: string, dateOfBirth: Date, currentCoins: number, totalCoins: number, nbGamesPlayed:number, currentSkin: Skin, tabSkin: Skin[]){ this.id=id; this.username=username; diff --git a/bob_party/src/core/User/userCreator.ts b/bob_party/src/core/User/userCreator.ts index 18be053..4c5104d 100644 --- a/bob_party/src/core/User/userCreator.ts +++ b/bob_party/src/core/User/userCreator.ts @@ -8,21 +8,7 @@ export class UserCreator{ async createUser(username:string, password:string, nationality:string, sexe:string, date:Date){ //Récup l'ID d'après dans la bdd - let u:User; - let newId:string=""; - - let oldId = await MANAGER_USER.getLoaderUser().loadLastId(); - oldId=oldId.slice(1); - let leInt=parseInt(oldId); - newId+="U"; - for (let i = 0; i < 4-leInt.toString().length; i++) { - newId = newId + "0"; - } - leInt+=1; - newId=newId+leInt; - console.log(newId); - u = new User(newId, username, password, nationality, sexe, date, 0, 0, 0, tabSkinApp[0], [tabSkinApp[0]]); - await MANAGER_USER.getsaverUser().saveUser(u); + let u:null|User = await MANAGER_USER.getsaverUser().saveUser(username, password, nationality, sexe, date); MANAGER_USER.setCurrentUser(u); return u; } diff --git a/bob_party/src/core/conversation.ts b/bob_party/src/core/conversation.ts index ac94d9a..0ac989f 100644 --- a/bob_party/src/core/conversation.ts +++ b/bob_party/src/core/conversation.ts @@ -3,14 +3,14 @@ import { User } from "./User/user"; export class Conversation{ - private Id: string; + private id: number; private tabUser: User[]; private tabMessage: Message[]; private name: string; /* Constructor of the class */ - constructor(id: string, tabUser: User[], tabMessage:Message[], name:string){ - this.Id=id; + constructor(id: number, tabUser: User[], tabMessage:Message[], name:string){ + this.id=id; this.tabUser=[...tabUser]; this.tabMessage=[...tabMessage]; this.name=name; @@ -40,7 +40,7 @@ export class Conversation{ /* Brief : function returning the id of a conversation */ getId(){ - return this.Id; + return this.id; } /* Brief : function returning the name to a conversation */ diff --git a/bob_party/src/core/gameCasino.ts b/bob_party/src/core/gameCasino.ts index 6029a90..92d1ba8 100644 --- a/bob_party/src/core/gameCasino.ts +++ b/bob_party/src/core/gameCasino.ts @@ -3,7 +3,7 @@ import { Game } from './game' export class GameCasino extends Game{ - constructor(id:string, name:string, imageSource:ImageSourcePropType, gameSource:string, nbPlayerMin:number, nbPlayerMax:number){ + constructor(id:number, name:string, imageSource:string, gameSource:string, nbPlayerMin:number, nbPlayerMax:number){ super(id, name, imageSource, gameSource, nbPlayerMin, nbPlayerMax); } diff --git a/bob_party/src/core/gameMulti.ts b/bob_party/src/core/gameMulti.ts index e76862e..b897be5 100644 --- a/bob_party/src/core/gameMulti.ts +++ b/bob_party/src/core/gameMulti.ts @@ -4,7 +4,7 @@ import { Game } from './game' export class GameMulti extends Game{ readonly rankToCoins:Map - constructor(id:string, name:string, imageSource:ImageSourcePropType, gameSource:string, nbPlayerMin:number, nbPlayerMax:number, rankToCoins:Map){ + constructor(id:number, name:string, imageSource:string, gameSource:string, nbPlayerMin:number, nbPlayerMax:number, rankToCoins:Map){ super(id, name, imageSource, gameSource, nbPlayerMin, nbPlayerMax); this.rankToCoins=rankToCoins; } diff --git a/bob_party/src/core/gameSolo.ts b/bob_party/src/core/gameSolo.ts index e631b3b..5ebcf59 100644 --- a/bob_party/src/core/gameSolo.ts +++ b/bob_party/src/core/gameSolo.ts @@ -4,7 +4,7 @@ import { Game } from './game' export class GameSolo extends Game{ readonly ptsToCoins:Map - constructor(id:string, name:string, imageSource:ImageSourcePropType, gameSource:string, nbPlayerMin:number, nbPlayerMax:number, ptsToCoins:Map){ + constructor(id:number, name:string, imageSource:string, gameSource:string, nbPlayerMin:number, nbPlayerMax:number, ptsToCoins:Map){ super(id, name, imageSource, gameSource, nbPlayerMin,nbPlayerMax); this.ptsToCoins=ptsToCoins; } diff --git a/bob_party/src/core/matchMulti.ts b/bob_party/src/core/matchMulti.ts deleted file mode 100644 index 2003035..0000000 --- a/bob_party/src/core/matchMulti.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { Match } from "./match"; -import { User } from "./User/user"; -import { Game } from "./game"; -import { GameMulti } from "./gameMulti"; -import { ManagerCoinsUser } from "./User/userCoinsModifier"; - -export class MatchMulti extends Match{ - - constructor(code:string, inGame:Boolean, tabUser:User[], game:GameMulti){ - super(code, inGame, tabUser, game); - } - - updatePostMatch(user:User, points: number): void { - const manage= new ManagerCoinsUser(); - manage.addCoins(user, this.getGame().coinsCalculator(points)); - } -} \ No newline at end of file diff --git a/bob_party/src/core/matchSolo.ts b/bob_party/src/core/matchSolo.ts deleted file mode 100644 index 1fd2287..0000000 --- a/bob_party/src/core/matchSolo.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { Match } from "./match"; -import { GameSolo } from "./gameSolo"; -import { User } from "./User/user"; -import { Game } from "./game"; -import { ManagerCoinsUser } from "./User/userCoinsModifier"; - -export class MatchSolo extends Match{ - - constructor(code:string, inGame:Boolean, tabUser:User[], game:GameSolo){ - super(code, inGame, tabUser, game); - } - - updatePostMatch(user:User, points: number): void { - const manage= new ManagerCoinsUser(); - manage.addCoins(user, this.getGame().coinsCalculator(points)); - } -} \ No newline at end of file diff --git a/bob_party/src/core/message.ts b/bob_party/src/core/message.ts index 087833d..5f9aed5 100644 --- a/bob_party/src/core/message.ts +++ b/bob_party/src/core/message.ts @@ -2,52 +2,52 @@ import { User } from './User/user' export class Message{ - private Id: string; - private Content: string; - private Sender: User; - private DateEnvoie: Date; + private id: number; + private content: string; + private sender: User; + private dateEnvoie: Date; /* Constructor of the class */ - constructor(id: string, content: string, sender:User, dateEnvoie:Date){ - this.Id=id; - this.Content=content; - this.Sender=sender; - this.DateEnvoie=dateEnvoie; + constructor(id: number, content: string, sender:User, dateEnvoie:Date){ + this.id=id; + this.content=content; + this.sender=sender; + this.dateEnvoie=dateEnvoie; } /* Brief : Function setting the content of a message */ setMessageContent(content: string){ - this.Content=content; + this.content=content; } /* Brief : Function setting the sender of a message */ setMessageSender(sender: User){ - this.Sender=sender; + this.sender=sender; } /* Brief : Function setting the date of a message */ setMessageDate(dateEnvoie: Date){ - this.DateEnvoie=dateEnvoie; + this.dateEnvoie=dateEnvoie; } /* Brief : Function getting the id of a message */ getMessageId(){ - return this.Id; + return this.id; } /* Brief : Function getting the content of a message */ getMessageContent(){ - return this.Content; + return this.content; } /* Brief : Function getting the sender of a message */ getMessageSender(){ - return this.Sender; + return this.sender; } /* Brief : Function getting the date of a message */ getMessageDate(){ - return this.DateEnvoie; + return this.dateEnvoie; } diff --git a/bob_party/src/core/skin.ts b/bob_party/src/core/skin.ts index 5351764..fb8583c 100644 --- a/bob_party/src/core/skin.ts +++ b/bob_party/src/core/skin.ts @@ -1,13 +1,13 @@ import { ImageSourcePropType } from "react-native"; export class Skin{ - readonly id: string; + readonly id: number; private name: string; - private source: ImageSourcePropType; + private source: string; private cost:number; /* Constructor of the class */ - constructor(id:string, name: string, source:ImageSourcePropType, Cost:number){ + constructor(id:number, name: string, source:string, Cost:number){ this.id=id; this.name=name; this.source=source; @@ -20,7 +20,7 @@ export class Skin{ } /* Brief : Fuction setting the source of the image of a skin */ - setSkinSource(source: ImageSourcePropType){ + setSkinSource(source: string){ this.source=source; } diff --git a/bob_party/src/core/tests/conversation.test.ts b/bob_party/src/core/tests/conversation.test.ts index c7ea9be..d336118 100644 --- a/bob_party/src/core/tests/conversation.test.ts +++ b/bob_party/src/core/tests/conversation.test.ts @@ -8,20 +8,20 @@ import { User } from '../User/user'; // Instances let conv:Conversation[] = []; let tab:Skin[] = []; -let classique = new Skin("S0001", "Bob", require('bob_party/assets/BobsSkins/BobClassic.png'), 0); +new Skin(1, "Bob","https://codefirst.iut.uca.fr/git/BOB_PARTEAM/BOB_PARTY/raw/branch/typescript/bob_party/assets/BobsSkins/BobClassic.png", 0); let dateBirth = new Date(2010,0o3,0o7); -let usr = new User('00001', 'Killyan', 'password', 'France', 'M', dateBirth, 0, 0, 0, classique, tab); -let usr2 = new User('00002', 'Karina', '1234', 'France', 'F', dateBirth, 5, 6, 8, classique, tab); +let usr = new User(1, 'Killyan', 'password', 'France', 'M', dateBirth, 0, 0, 0, classique, tab); +let usr2 = new User(2, 'Karina', '1234', 'France', 'F', dateBirth, 5, 6, 8, classique, tab); let theDate = new Date(2022,10,14); let theDate2 = new Date(2022,10,13); let theDate3 = new Date(2022,10,15); -let mess = new Message('M0001', 'Bob Party est le meilleur projet', usr, theDate2); +let mess = new Message(1, 'Bob Party est le meilleur projet', usr, theDate2); let tabU:User[] = [usr, usr2]; -let mess2 = new Message('M0002', 'Oui tout à fait', usr2, theDate); -let mess3 = new Message('M0003', 'Mais oui trop de ouf', usr, theDate3); +let mess2 = new Message(2, 'Oui tout à fait', usr2, theDate); +let mess3 = new Message(3, 'Mais oui trop de ouf', usr, theDate3); let tabM:Message[] = [mess, mess2]; -let convo = new Conversation('C0001', tabU, tabM, 'the conv'); -let usr3 = new User('00003', 'wow', 'password', 'France', 'M', dateBirth, 0, 0, 0, classique, tab); +let convo = new Conversation(1, tabU, tabM, 'the conv'); +let usr3 = new User(4, 'wow', 'password', 'France', 'M', dateBirth, 0, 0, 0, classique, tab); // Get tests diff --git a/bob_party/src/core/tests/matchSolo.test.ts b/bob_party/src/core/tests/matchSolo.test.ts index 94f4d72..8ec9cb8 100644 --- a/bob_party/src/core/tests/matchSolo.test.ts +++ b/bob_party/src/core/tests/matchSolo.test.ts @@ -1,4 +1,4 @@ -import { MatchSolo } from '../MatchSolo'; +import { MatchSolo } from '../Match/matchSolo'; import { Conversation } from '../Conversation'; import { Skin } from '../Skin'; import { User } from '../User/user'; diff --git a/bob_party/src/navigation/AppNavigator.tsx b/bob_party/src/navigation/AppNavigator.tsx index 0a299bd..d58258a 100644 --- a/bob_party/src/navigation/AppNavigator.tsx +++ b/bob_party/src/navigation/AppNavigator.tsx @@ -12,7 +12,7 @@ import SkinList from '../screens/SkinList' import GameChoice from '../screens/GameChoice' import SignIn from '../screens/SignIn' import SignUp from '../screens/SignUp' - +import CookieClicker from '../Games/CookieClicker/CookieClicker' const HomeStack = createStackNavigator(); @@ -25,7 +25,7 @@ function HomeStackScreen() { - + ); } diff --git a/bob_party/src/screens/GameChoice.tsx b/bob_party/src/screens/GameChoice.tsx index 9fd8061..29f0c88 100644 --- a/bob_party/src/screens/GameChoice.tsx +++ b/bob_party/src/screens/GameChoice.tsx @@ -16,7 +16,7 @@ let tabConv:Conversation[]=[]; const msc = require('../../assets/Icons/FondGris.png'); //const UserActu=new User("14", "leBg", "MdpDeOuf", "ouioui", "grand", new Date(2022,12,12), 12222, 123324, 12, tabSkinApp[0], tabSkinApp, tabConv); -const cookieClicker= new GameSolo("1", "Cookie Clicker", require('../../assets/Icons/UnSelected/Gamepad.png'), "/Games/CookieClicker/cookieClicker.tsx", 1, 1, new Map); +const cookieClicker= new GameSolo(1, "Cookie Clicker", "https://codefirst.iut.uca.fr/git/BOB_PARTEAM/BOB_PARTY/raw/branch/typescript/bob_party/assets/BobsSkins/BobYellowGreenBlueHeart.png", "/Games/CookieClicker/cookieClicker.tsx", 1, 1, new Map); function GameChoice(props: { navigation: any; }) { const { navigation } = props return ( diff --git a/bob_party/src/services/conversationService/loaderConversationApi.ts b/bob_party/src/services/conversationService/loaderConversationApi.ts index ae78e87..8e0a5b8 100644 --- a/bob_party/src/services/conversationService/loaderConversationApi.ts +++ b/bob_party/src/services/conversationService/loaderConversationApi.ts @@ -26,11 +26,12 @@ export class LoaderConversationApi implements ILoaderConversation{ } }) .then(function (response: any) { - tabConv=[new Conversation("C0001", - [new User("U0001", "Alban", "oui", "ouioui", "homme", new Date(2022,12,12), 555, 667, 12, new Skin("S0001", "Bob",require('bob_party/assets/BobsSkins/BobClassic.png'), 0), [new Skin("S0001", "Bob",require('bob_party/assets/BobsSkins/BobClassic.png'), 0)]), - new User("U0002", "Fefe63", "jesuishm", "ouioui", "homme", new Date(2022,12,12), 12222, 123324, 12, new Skin("S0001", "Bob",require('bob_party/assets/BobsSkins/BobClassic.png'), 0), [new Skin("S0001", "Bob",require('bob_party/assets/BobsSkins/BobClassic.png'), 0)]),], - [new Message("M0001", "bonjour", new User("U0001", "Alban", "oui", "ouioui", "homme", new Date(2022,12,12), 555, 667, 12, new Skin("S0001", "Bob",require('bob_party/assets/BobsSkins/BobClassic.png'), 0), [new Skin("S0001", "Bob",require('bob_party/assets/BobsSkins/BobClassic.png'), 0)]), new Date(2022,12,12)), - new Message("M0002", "test", new User("U0002", "Fefe63", "oui", "ouioui", "homme", new Date(2022,12,12), 555, 667, 12, new Skin("S0002", "Bob Blue",require('bob_party/assets/BobsSkins/BobBlue.png'), 100), [new Skin("S0002", "Bob Blue",require('bob_party/assets/BobsSkins/BobBlue.png'), 100)]), new Date(2022,12,13))], "leNom")]; + let skin= new Skin(1, "Bob","https://codefirst.iut.uca.fr/git/BOB_PARTEAM/BOB_PARTY/raw/branch/typescript/bob_party/assets/BobsSkins/BobClassic.png", 0); + tabConv=[new Conversation(1, + [new User(1, "Alban", "oui", "ouioui", "homme", new Date(2022,12,12), 555, 667, 12, skin, [skin]), + new User(3, "Fefe63", "jesuishm", "ouioui", "homme", new Date(2022,12,12), 12222, 123324, 12, skin, [skin])], + [new Message(1, "bonjour", new User(1, "Alban", "oui", "ouioui", "homme", new Date(2022,12,12), 555, 667, 12, skin, [skin]), new Date(2022,12,12)), + new Message(2, "test", new User(2, "Fefe63", "oui", "ouioui", "homme", new Date(2022,12,12), 555, 667, 12, skin, [skin]), new Date(2022,12,13))], "leNom")]; }); return tabConv; } diff --git a/bob_party/src/services/matchServices/ILoaderMatch.ts b/bob_party/src/services/matchServices/ILoaderMatch.ts index 231ae1b..dc7f950 100644 --- a/bob_party/src/services/matchServices/ILoaderMatch.ts +++ b/bob_party/src/services/matchServices/ILoaderMatch.ts @@ -1,4 +1,4 @@ -import { Match } from "../../core/match"; +import { Match } from "../../core/Match/match"; export default interface ILoaderMatch{ diff --git a/bob_party/src/services/matchServices/ISaverMatch.ts b/bob_party/src/services/matchServices/ISaverMatch.ts index 4f261cd..2786262 100644 --- a/bob_party/src/services/matchServices/ISaverMatch.ts +++ b/bob_party/src/services/matchServices/ISaverMatch.ts @@ -1,4 +1,6 @@ -import { Match } from "../../core/match"; +import { Game } from "../../core/game"; +import { Match } from "../../core/Match/match"; +import { User } from "../../core/User/user"; export default interface ISaverMatch{ @@ -7,7 +9,7 @@ export default interface ISaverMatch{ * m the Match we want to save */ - saveMatch(m:Match): Promise; + saveMatch(u:User, g:Game): Promise; /** * deleteMatch methode that delete a Match in the data management system diff --git a/bob_party/src/services/matchServices/loaderMatchApi.ts b/bob_party/src/services/matchServices/loaderMatchApi.ts new file mode 100644 index 0000000..8e7a461 --- /dev/null +++ b/bob_party/src/services/matchServices/loaderMatchApi.ts @@ -0,0 +1,13 @@ +import { Match } from "../../core/Match/match"; +import ILoaderMatch from "./ILoaderMatch"; + +export default class LoaderMatchApi implements ILoaderMatch{ + + async loadAllMatch(): Promise { + throw new Error("Method not implemented."); + } + async loadByID(id: string): Promise { + throw new Error("Method not implemented."); + } + +} \ No newline at end of file diff --git a/bob_party/src/services/matchServices/managerMatch.ts b/bob_party/src/services/matchServices/managerMatch.ts new file mode 100644 index 0000000..83383b1 --- /dev/null +++ b/bob_party/src/services/matchServices/managerMatch.ts @@ -0,0 +1,41 @@ +import { Match } from "../../core/Match/Match"; +import ILoaderMatch from "./ILoaderMatch"; +import ISaverMatch from "./ISaverMatch"; + +export default class ManagerMatch{ + + private currentMatch: Match | null=null; + + private loaderMatch: ILoaderMatch; + + private saverMatch: ISaverMatch; + + constructor(loader:ILoaderMatch, saver:ISaverMatch){ + this.loaderMatch=loader; + this.saverMatch=saver; + } + + getCurrentMatch(){ + return this.currentMatch; + } + + setCurrentMatch(u:Match | null){ + this.currentMatch=u; + } + + getLoaderMatch(){ + return this.loaderMatch; + } + + setLoaderMatch(l:ILoaderMatch){ + this.loaderMatch=l; + } + + getsaverMatch(){ + return this.saverMatch; + } + + setsaverMatch(s:ISaverMatch){ + this.saverMatch=s; + } +} \ No newline at end of file diff --git a/bob_party/src/services/matchServices/saverMatchApi.ts b/bob_party/src/services/matchServices/saverMatchApi.ts new file mode 100644 index 0000000..2b12e60 --- /dev/null +++ b/bob_party/src/services/matchServices/saverMatchApi.ts @@ -0,0 +1,32 @@ +import { Game } from "../../core/game"; +import { Match } from "../../core/Match/match"; + +import { User } from "../../core/User/user"; +import ISaverMatch from "./ISaverMatch"; +import { GameSolo } from "../../core/gameSolo"; +import { GameMulti } from "../../core/gameMulti"; +import MatchSolo from "../../core/Match/matchSolo"; +import MatchMulti from "../../core/Match/matchMulti"; +import MatchCasino from "../../core/Match/matchCasino"; + +export default class SaverMatchApi implements ISaverMatch{ + + async saveMatch(u:User, g:Game): Promise { + //match = mettre dans bdd + if (g instanceof GameSolo){ + return new MatchSolo(12, false, [u], g); + } + else if(g instanceof GameMulti){ + return new MatchMulti(12, false, [u], g); + } + return new MatchCasino(12, false, [u], g); + + } + async deleteMatch(m: Match): Promise { + throw new Error("Method not implemented."); + } + async updateMatch(m: Match): Promise { + throw new Error("Method not implemented."); + } + +} \ No newline at end of file diff --git a/bob_party/src/services/userServices/ILoaderUser.ts b/bob_party/src/services/userServices/ILoaderUser.ts index aa700a4..46eafbf 100644 --- a/bob_party/src/services/userServices/ILoaderUser.ts +++ b/bob_party/src/services/userServices/ILoaderUser.ts @@ -1,5 +1,5 @@ import { Conversation } from "../../core/conversation"; -import { Match } from "../../core/match"; +import { Match } from "../../core/Match/match"; import { User } from "../../core/User/user"; export default interface ILoaderUser{ @@ -15,7 +15,7 @@ export default interface ILoaderUser{ * id the id we want to search * return a User if found, if not null */ - loadByID(id:string): Promise; + loadByID(id:number): Promise; /** * loadByUsername methode that load a user from the data management system by his username @@ -48,5 +48,5 @@ export default interface ILoaderUser{ * loadLastId methode that load the last id used to create a user * return a String */ - loadLastId(): Promise; + loadLastId(): Promise; } \ No newline at end of file diff --git a/bob_party/src/services/userServices/ISaverUser.ts b/bob_party/src/services/userServices/ISaverUser.ts index 54e9a41..c8938da 100644 --- a/bob_party/src/services/userServices/ISaverUser.ts +++ b/bob_party/src/services/userServices/ISaverUser.ts @@ -7,7 +7,7 @@ export default interface ISaverUser{ * u the user we want to save */ - saveUser(u:User | null): Promise; + saveUser(username:string, password:string, nationality:string, sexe:string, date:Date): Promise; /** * deleteUser methode that delete a User in the data management system diff --git a/bob_party/src/services/userServices/fakeSaverUser.ts b/bob_party/src/services/userServices/fakeSaverUser.ts index f85d8c4..79d2105 100644 --- a/bob_party/src/services/userServices/fakeSaverUser.ts +++ b/bob_party/src/services/userServices/fakeSaverUser.ts @@ -4,8 +4,8 @@ import ISaverUser from "./ISaverUser"; export default class FakeSaverUser implements ISaverUser{ - async saveUser(u: User): Promise { - return; + async saveUser(username:string, password:string, nationality:string, sexe:string, date:Date): Promise { + return null; } async deleteUser(u: User): Promise { return; diff --git a/bob_party/src/services/userServices/loaderUserApi.ts b/bob_party/src/services/userServices/loaderUserApi.ts index ae9b4fe..70a102e 100644 --- a/bob_party/src/services/userServices/loaderUserApi.ts +++ b/bob_party/src/services/userServices/loaderUserApi.ts @@ -1,6 +1,6 @@ import tabSkinApp from "../../constSkin"; import { Conversation } from "../../core/conversation"; -import { Match } from "../../core/match"; +import { Match } from "../../core/Match/match"; import { Skin } from "../../core/skin"; import { User } from "../../core/User/user"; import ILoaderUser from "./ILoaderUser"; @@ -37,14 +37,14 @@ export default class LoaderUserApi implements ILoaderUser{ .then(function (response: any) { if (response.data != null && response.data != undefined){ Object.assign(test, response.data); - us.push(new User("17", "Fefe63", "jesuishm", "ouioui", "homme", new Date(2022,12,12), 12222, 123324, 12, tabSkinApp[6], tabSkinApp)); + us.push(new User(1, "Fefe63", "jesuishm", "ouioui", "homme", new Date(2022,12,12), 12222, 123324, 12, tabSkinApp[6], tabSkinApp)); } }); return us; } - async loadByID(id: string): Promise { + async loadByID(id: number): Promise { let test = new Test(true, 0, "wesh", 0); try{ await this.axios({ @@ -64,7 +64,7 @@ export default class LoaderUserApi implements ILoaderUser{ }catch (error) { console.error(error); } - return new User("17", "Bite", "jesuishm", "ouioui", "homme", new Date(2022,12,12), 123, 123324, 12, tabSkinApp[6], tabSkinApp); + return new User(1, "Bite", "jesuishm", "ouioui", "homme", new Date(2022,12,12), 123, 123324, 12, tabSkinApp[6], tabSkinApp); } @@ -102,8 +102,9 @@ export default class LoaderUserApi implements ILoaderUser{ } }) .then(function (response: any) { - const tabTest=[new Skin("S0001", "Bob",require('bob_party/assets/BobsSkins/BobClassic.png'), 0), new Skin("S0002", "Bob Blue",require('bob_party/assets/BobsSkins/BobBlue.png'), 100)]; - user=new User("U0001", username, password, "ouioui", "homme", new Date(2022,12,12), 200, 123324, 12, new Skin("S0001", "Bob",require('bob_party/assets/BobsSkins/BobClassic.png'), 0), tabTest); + const tabTest=[new Skin(1, "Bob","https://codefirst.iut.uca.fr/git/BOB_PARTEAM/BOB_PARTY/raw/branch/typescript/bob_party/assets/BobsSkins/BobClassic.png", 0), + new Skin(2, "Bob Blue","https://codefirst.iut.uca.fr/git/BOB_PARTEAM/BOB_PARTY/raw/branch/typescript/bob_party/assets/BobsSkins/BobBlue.png", 100)]; + user=new User(1, username, password, "ouioui", "homme", new Date(2022,12,12), 200, 123324, 12, new Skin(1, "Bob","https://codefirst.iut.uca.fr/git/BOB_PARTEAM/BOB_PARTY/raw/branch/typescript/bob_party/assets/BobsSkins/BobClassic.png", 0), tabTest); }); return user; } @@ -118,7 +119,7 @@ export default class LoaderUserApi implements ILoaderUser{ } - async loadLastId(): Promise { + async loadLastId(): Promise { let test = new Test(true, 0, "wesh", 0); try { const response = await this.axios.get('https://jsonplaceholder.typicode.com/todos/1'); @@ -126,7 +127,7 @@ export default class LoaderUserApi implements ILoaderUser{ } catch (error) { console.error(error); } - return "U0001"; + return 1; } diff --git a/bob_party/src/services/userServices/saverUserApi.ts b/bob_party/src/services/userServices/saverUserApi.ts index cff04b7..5a16365 100644 --- a/bob_party/src/services/userServices/saverUserApi.ts +++ b/bob_party/src/services/userServices/saverUserApi.ts @@ -6,7 +6,8 @@ export default class SaverUserApi implements ISaverUser{ private axios = require('axios').default; - async saveUser(u: User): Promise { + async saveUser(username:string, password:string, nationality:string, sexe:string, date:Date): Promise { + let us:User|null=null; this.axios({ method: 'post', url: '/user/12345', @@ -14,8 +15,14 @@ export default class SaverUserApi implements ISaverUser{ firstName: 'Fred', lastName: 'Flintstone' } - }); - + }).then(function (response: any) { + if (response.data != null && response.data != undefined){ + let test:any; + Object.assign(test, response.data); + us=test; + } + }); + return us; } async deleteUser(u: User): Promise { throw new Error("Method not implemented."); diff --git a/bob_party/src/services/userServices/stub.ts b/bob_party/src/services/userServices/stub.ts index b654e81..6843696 100644 --- a/bob_party/src/services/userServices/stub.ts +++ b/bob_party/src/services/userServices/stub.ts @@ -1,22 +1,23 @@ import { Conversation } from "../../core/conversation"; -import { Match } from "../../core/match"; +import { Match } from "../../core/Match/match"; import { Skin } from "../../core/skin"; import { User } from "../../core/User/user"; import ILoaderUser from "./ILoaderUser"; export default class StubUser implements ILoaderUser{ + skin:Skin=new Skin(1, "Bob","https://codefirst.iut.uca.fr/git/BOB_PARTEAM/BOB_PARTY/raw/branch/typescript/bob_party/assets/BobsSkins/BobClassic.png", 0); + + tabUS:User[]=[ - new User("14", "leBg", "MdpDeOuf", "ouioui", "grand", new Date(2022,12,12), 12222, 123324, 12, new Skin("S0001", "Bob",require('bob_party/assets/BobsSkins/BobClassic.png'), 0), [new Skin("S0001", "Bob",require('bob_party/assets/BobsSkins/BobClassic.png'), 0)]), - new User("48", "WeshWesh", "MdpDeOuf", "ouioui", "grand", new Date(2022,12,12), 12222, 123324, 12, new Skin("S0001", "Bob",require('bob_party/assets/BobsSkins/BobClassic.png'), 0), [new Skin("S0001", "Bob",require('bob_party/assets/BobsSkins/BobClassic.png'), 0)]), - new User("17", "Alban", "oui", "ouioui", "homme", new Date(2022,12,12), 555, 667, 12, new Skin("S0001", "Bob",require('bob_party/assets/BobsSkins/BobClassic.png'), 0), [new Skin("S0001", "Bob",require('bob_party/assets/BobsSkins/BobClassic.png'), 0)],), - new User("17", "Fefe63", "jesuishm", "ouioui", "homme", new Date(2022,12,12), 12222, 123324, 12, new Skin("S0001", "Bob",require('bob_party/assets/BobsSkins/BobClassic.png'), 0), [new Skin("S0001", "Bob",require('bob_party/assets/BobsSkins/BobClassic.png'), 0)]), + new User(1, "leBg", "MdpDeOuf", "ouioui", "grand", new Date(2022,12,12), 12222, 123324, 12, this.skin, [this.skin]), + new User(2, "WeshWesh", "MdpDeOuf", "ouioui", "grand", new Date(2022,12,12), 12222, 123324, 12, this.skin, [this.skin]), ]; async loadAllUser(): Promise { return this.tabUS; } - async loadByID(id: string): Promise { + async loadByID(id: number): Promise { for(let u of this.tabUS){ if (u.getId()==id){ return u; @@ -57,7 +58,7 @@ export default class StubUser implements ILoaderUser{ return tabUser; } - async loadLastId(): Promise { + async loadLastId(): Promise { throw new Error("Method not implemented."); } From 2833fccaa263ce6ae5217b5fdf9d5d53cf5f4f1c Mon Sep 17 00:00:00 2001 From: aguilhot Date: Tue, 6 Dec 2022 14:48:07 +0100 Subject: [PATCH 07/15] ADD: LobbySolo --- bob_party/src/components/GameComponent.tsx | 10 ++++- bob_party/src/navigation/AppNavigator.tsx | 20 ++++++++- bob_party/src/screens/GameChoice.tsx | 7 ++-- bob_party/src/screens/Home.tsx | 47 ++++++++++------------ bob_party/src/screens/LobbySolo.tsx | 31 ++++++++++++++ 5 files changed, 84 insertions(+), 31 deletions(-) create mode 100644 bob_party/src/screens/LobbySolo.tsx diff --git a/bob_party/src/components/GameComponent.tsx b/bob_party/src/components/GameComponent.tsx index 7f74b07..3cd9ae4 100644 --- a/bob_party/src/components/GameComponent.tsx +++ b/bob_party/src/components/GameComponent.tsx @@ -8,6 +8,7 @@ import { Game } from "../core/game" Importing the correct stylesheet */ import styles from './style/Game.style'; +import LobbySolo from "../screens/LobbySolo" export const GameComponent : /* @@ -17,9 +18,10 @@ export const GameComponent : FC<{game: Game, nav: any}> = ({game, nav}) => { + return ( - nav.navigate("CookieClicker")}> + createNewMatchSolo(game, nav)}> = ) +} + +function createNewMatchSolo(game : Game, nav: any) { + + + nav.navigate("LobbySolo") } \ No newline at end of file diff --git a/bob_party/src/navigation/AppNavigator.tsx b/bob_party/src/navigation/AppNavigator.tsx index d58258a..1debeaa 100644 --- a/bob_party/src/navigation/AppNavigator.tsx +++ b/bob_party/src/navigation/AppNavigator.tsx @@ -12,7 +12,8 @@ import SkinList from '../screens/SkinList' import GameChoice from '../screens/GameChoice' import SignIn from '../screens/SignIn' import SignUp from '../screens/SignUp' -import CookieClicker from '../Games/CookieClicker/CookieClicker' +import LobbySolo from '../screens/LobbySolo' + const HomeStack = createStackNavigator(); @@ -25,7 +26,7 @@ function HomeStackScreen() { - + ); } @@ -70,6 +71,21 @@ function ProfileStackScreen() { ); } +const GameChoiceStack = createStackNavigator(); + +/* + Stack of screens for the profile and the changement of informations +*/ +function GameChoiceStackScreen() { + return ( + + + + + ); +} + + const Tab = createBottomTabNavigator() /* Tab navigator to navigate between the stacks diff --git a/bob_party/src/screens/GameChoice.tsx b/bob_party/src/screens/GameChoice.tsx index 29f0c88..be437be 100644 --- a/bob_party/src/screens/GameChoice.tsx +++ b/bob_party/src/screens/GameChoice.tsx @@ -13,12 +13,13 @@ import { GameSolo } from '../core/gameSolo'; let tabConv:Conversation[]=[]; -const msc = require('../../assets/Icons/FondGris.png'); +const cookieClicker= new GameSolo(1, "Cookie Clicker", require('../../assets/Icons/UnSelected/Gamepad.png'), "/Games/CookieClicker/cookieClicker.tsx", 1, 1, new Map); + -//const UserActu=new User("14", "leBg", "MdpDeOuf", "ouioui", "grand", new Date(2022,12,12), 12222, 123324, 12, tabSkinApp[0], tabSkinApp, tabConv); -const cookieClicker= new GameSolo(1, "Cookie Clicker", "https://codefirst.iut.uca.fr/git/BOB_PARTEAM/BOB_PARTY/raw/branch/typescript/bob_party/assets/BobsSkins/BobYellowGreenBlueHeart.png", "/Games/CookieClicker/cookieClicker.tsx", 1, 1, new Map); function GameChoice(props: { navigation: any; }) { const { navigation } = props + + return ( - - - navigation.navigate('GameChoice')} - /> - navigation.navigate('GameChoice')} - /> + + + + navigation.navigate('GameChoiceTab')} + /> + navigation.navigate('GameChoiceTab')} + /> + + - - - ); + ); } export default Home \ No newline at end of file diff --git a/bob_party/src/screens/LobbySolo.tsx b/bob_party/src/screens/LobbySolo.tsx new file mode 100644 index 0000000..2701b5e --- /dev/null +++ b/bob_party/src/screens/LobbySolo.tsx @@ -0,0 +1,31 @@ +import { StatusBar } from 'expo-status-bar' +import { View} from 'react-native' +import React from 'react'; +import stylesScreen from './style/screens.style' +import { TopBar } from '../components/TopBar'; +import { BotBar } from '../components/BotBar'; +import { Conversation } from '../core/conversation'; +import { ButtonGameTypeChoice } from '../components/ButtonGameTypeChoice'; + + + +let tabConv:Conversation[]=[]; + +function LobbySolo(props: { navigation: any; }) { + + const { navigation } = props + + + return ( + + + navigation.navigate('GameChoice')} + /> + + + ); +} + +export default LobbySolo \ No newline at end of file From 3b19f61e8e275e51a1ff539a050a72da09b050de Mon Sep 17 00:00:00 2001 From: Thomas Chazot Date: Tue, 6 Dec 2022 14:55:00 +0100 Subject: [PATCH 08/15] push pour alban --- bob_party/src/components/GameComponent.tsx | 12 +++++++++--- bob_party/src/core/Match/matchCreator.ts | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/bob_party/src/components/GameComponent.tsx b/bob_party/src/components/GameComponent.tsx index 3cd9ae4..a5134d9 100644 --- a/bob_party/src/components/GameComponent.tsx +++ b/bob_party/src/components/GameComponent.tsx @@ -9,6 +9,9 @@ import { Game } from "../core/game" */ import styles from './style/Game.style'; import LobbySolo from "../screens/LobbySolo" +import ManagerMatch from "../services/matchServices/managerMatch" +import MatchCreator from "../core/Match/matchCreator" +import { MANAGER_USER } from "../../App" export const GameComponent : /* @@ -33,7 +36,10 @@ FC<{game: Game, nav: any}> = } function createNewMatchSolo(game : Game, nav: any) { - - - nav.navigate("LobbySolo") + const m=new MatchCreator(); + let tmp=MANAGER_USER.getCurrentUser(); + if (tmp!=null){ + let match=m.createMatch(tmp, game); + nav.navigate("LobbySolo"); + } } \ No newline at end of file diff --git a/bob_party/src/core/Match/matchCreator.ts b/bob_party/src/core/Match/matchCreator.ts index 22f5eb4..5803af0 100644 --- a/bob_party/src/core/Match/matchCreator.ts +++ b/bob_party/src/core/Match/matchCreator.ts @@ -6,7 +6,7 @@ import { Match } from "./match"; export default class MatchCreator{ - async createMatchSolo(u:User, g:Game): Promise{ + async createMatch(u:User, g:Game): Promise{ return await MANAGER_MATCH.getsaverMatch().saveMatch(u, g); } } \ No newline at end of file From 14f75a042975cffd948ed9b5305d4d14545a5c9d Mon Sep 17 00:00:00 2001 From: Thomas Chazot Date: Tue, 6 Dec 2022 15:06:12 +0100 Subject: [PATCH 09/15] =?UTF-8?q?2=C3=A8me=20push=20pour=20alban?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bob_party/src/components/GameComponent.tsx | 32 ++++++++++++++-------- bob_party/src/context/matchContext.tsx | 18 ++++++++++++ bob_party/src/context/userContext.tsx | 2 +- 3 files changed, 40 insertions(+), 12 deletions(-) create mode 100644 bob_party/src/context/matchContext.tsx diff --git a/bob_party/src/components/GameComponent.tsx b/bob_party/src/components/GameComponent.tsx index a5134d9..c26d778 100644 --- a/bob_party/src/components/GameComponent.tsx +++ b/bob_party/src/components/GameComponent.tsx @@ -11,9 +11,11 @@ import styles from './style/Game.style'; import LobbySolo from "../screens/LobbySolo" import ManagerMatch from "../services/matchServices/managerMatch" import MatchCreator from "../core/Match/matchCreator" -import { MANAGER_USER } from "../../App" +import { MANAGER_MATCH, MANAGER_USER } from "../../App" +import { useMatchStore } from "../context/matchContext" export const GameComponent : + /* * game : Game that must be displayed * nav : tool needed to allow the navigation between the screens @@ -21,25 +23,33 @@ export const GameComponent : FC<{game: Game, nav: any}> = ({game, nav}) => { + + const setMatch = useMatchStore((state) => state.setMatch); + + async function createNewMatchSolo(game : Game, nav: any) { + const m=new MatchCreator(); + let tmp=MANAGER_USER.getCurrentUser(); + if (tmp!=null){ + let match=await m.createMatch(tmp, game); + MANAGER_MATCH.setCurrentMatch(match); + setMatch(match); + nav.navigate("LobbySolo"); + } + } + return ( createNewMatchSolo(game, nav)}> {game.getName()} - ) + ) + + } -function createNewMatchSolo(game : Game, nav: any) { - const m=new MatchCreator(); - let tmp=MANAGER_USER.getCurrentUser(); - if (tmp!=null){ - let match=m.createMatch(tmp, game); - nav.navigate("LobbySolo"); - } -} \ No newline at end of file diff --git a/bob_party/src/context/matchContext.tsx b/bob_party/src/context/matchContext.tsx new file mode 100644 index 0000000..32a4f45 --- /dev/null +++ b/bob_party/src/context/matchContext.tsx @@ -0,0 +1,18 @@ +import React from "react"; +import create from "zustand"; +import { Match } from "../core/Match/match"; + + +// Define store types +interface MatchState { + match: Match | null; + setMatch: (match: Match|null) => void; + resetMatch: () => void; + } + +// Define store data and methods +export const useMatchStore = create()((set, get) => ({ + match: null, + setMatch: (match) => set((state) => ({ match: match })), + resetMatch: () => set((state) => ({ match: null })), +})); diff --git a/bob_party/src/context/userContext.tsx b/bob_party/src/context/userContext.tsx index 1f81bef..ccf307d 100644 --- a/bob_party/src/context/userContext.tsx +++ b/bob_party/src/context/userContext.tsx @@ -14,5 +14,5 @@ interface UserState { export const useUserStore = create()((set, get) => ({ user: null, setUser: (user) => set((state) => ({ user: user })), - resetUser: () => set((state) => ({ user: undefined })), + resetUser: () => set((state) => ({ user: null })), })); From 2065fd11b5b59ce132a1836c1a22dcf33fab3295 Mon Sep 17 00:00:00 2001 From: Thomas Chazot Date: Tue, 6 Dec 2022 15:11:03 +0100 Subject: [PATCH 10/15] =?UTF-8?q?et=20hop=20un=20troisi=C3=A8me?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bob_party/src/components/GameComponent.tsx | 2 +- bob_party/src/screens/GameChoice.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bob_party/src/components/GameComponent.tsx b/bob_party/src/components/GameComponent.tsx index c26d778..1cb3990 100644 --- a/bob_party/src/components/GameComponent.tsx +++ b/bob_party/src/components/GameComponent.tsx @@ -43,7 +43,7 @@ FC<{game: Game, nav: any}> = createNewMatchSolo(game, nav)}> {game.getName()} diff --git a/bob_party/src/screens/GameChoice.tsx b/bob_party/src/screens/GameChoice.tsx index be437be..7f15669 100644 --- a/bob_party/src/screens/GameChoice.tsx +++ b/bob_party/src/screens/GameChoice.tsx @@ -13,7 +13,7 @@ import { GameSolo } from '../core/gameSolo'; let tabConv:Conversation[]=[]; -const cookieClicker= new GameSolo(1, "Cookie Clicker", require('../../assets/Icons/UnSelected/Gamepad.png'), "/Games/CookieClicker/cookieClicker.tsx", 1, 1, new Map); +const cookieClicker= new GameSolo(1, "Cookie Clicker", "https://codefirst.iut.uca.fr/git/BOB_PARTEAM/BOB_PARTY/raw/branch/typescript/bob_party/assets/ImagesJeux/Pong.png", "/Games/CookieClicker/cookieClicker.tsx", 1, 1, new Map); function GameChoice(props: { navigation: any; }) { From e89d09b95bfa6babb3341f085ed6789243b7dfe1 Mon Sep 17 00:00:00 2001 From: aguilhot Date: Tue, 6 Dec 2022 15:18:24 +0100 Subject: [PATCH 11/15] push pour toto --- bob_party/src/screens/LobbySolo.tsx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/bob_party/src/screens/LobbySolo.tsx b/bob_party/src/screens/LobbySolo.tsx index 2701b5e..ad51edc 100644 --- a/bob_party/src/screens/LobbySolo.tsx +++ b/bob_party/src/screens/LobbySolo.tsx @@ -6,6 +6,8 @@ import { TopBar } from '../components/TopBar'; import { BotBar } from '../components/BotBar'; import { Conversation } from '../core/conversation'; import { ButtonGameTypeChoice } from '../components/ButtonGameTypeChoice'; +import { MANAGER_MATCH } from '../../App'; +import { useMatchStore } from '../context/matchContext'; @@ -15,6 +17,7 @@ function LobbySolo(props: { navigation: any; }) { const { navigation } = props + const match = useMatchStore().match; return ( @@ -24,6 +27,10 @@ function LobbySolo(props: { navigation: any; }) { onPress={() => navigation.navigate('GameChoice')} /> + + ); } From 2782dd04569c9523a5dd610e7c7bd34a47f50ed0 Mon Sep 17 00:00:00 2001 From: Thomas Chazot Date: Tue, 6 Dec 2022 15:32:16 +0100 Subject: [PATCH 12/15] push pour alban --- .../src/Games/CookieClicker/cookieClicker.tsx | 14 +++++++------ bob_party/src/components/TopBar.tsx | 17 +++++++++++++++ bob_party/src/screens/LobbySolo.tsx | 21 ++++++++++--------- 3 files changed, 36 insertions(+), 16 deletions(-) diff --git a/bob_party/src/Games/CookieClicker/cookieClicker.tsx b/bob_party/src/Games/CookieClicker/cookieClicker.tsx index 38c3c61..d2a0bd1 100644 --- a/bob_party/src/Games/CookieClicker/cookieClicker.tsx +++ b/bob_party/src/Games/CookieClicker/cookieClicker.tsx @@ -10,6 +10,7 @@ import { Alert, } from 'react-native' import { MANAGER_USER } from '../../../App'; +import { useMatchStore } from '../../context/matchContext'; import { useUserStore } from '../../context/userContext'; import { Match } from '../../core/Match/match'; import { User } from '../../core/User/user'; @@ -19,10 +20,13 @@ function CookieClicker(props: { navigation: any}){ const { navigation } = props + const GAMING_TIME=15; const setUser = useUserStore((state) => state.setUser); + const resetMatch = useMatchStore((state) => state.resetMatch); + const [count, setCount] = useState(0); const [money, setMoney] = useState(0); @@ -85,13 +89,11 @@ function CookieClicker(props: { navigation: any}){ let tmp: User | null; tmp=MANAGER_USER.getCurrentUser(); if (tmp!=null){ - /* - if (match.getTabUsers().includes(tmp)){ - match.updatePostMatch(tmp, count); - setUser(tmp); - + if (useMatchStore().match?.getTabUsers().includes(tmp)){ + useMatchStore().match?.updatePostMatch(tmp, count); + setUser(tmp); } - */ + resetMatch(); navigation.goBack(); } } diff --git a/bob_party/src/components/TopBar.tsx b/bob_party/src/components/TopBar.tsx index c80e775..8e8aeb9 100644 --- a/bob_party/src/components/TopBar.tsx +++ b/bob_party/src/components/TopBar.tsx @@ -13,6 +13,7 @@ import { useSelector } from "react-redux" import { RootState } from "../redux/store" import { MANAGER_USER } from "../../App" import { useUserStore } from "../context/userContext" +import { useMatchStore } from "../context/matchContext" /* Images required @@ -32,6 +33,9 @@ FC<{nav: any, state?: string}> = ({nav, state}) => { + const resetMatch = useMatchStore((state) => state.resetMatch); + + /* The display of this component depends of the screen from where it has been called: * From the Settings (icon) : Name of the page + cross button * From other : skin + Title + parameters icon @@ -49,6 +53,19 @@ FC<{nav: any, state?: string}> = ) + + case 'matchmacking': + return ( + + + + + BOB PARTY + { resetMatch(); nav.goBack()}}> + + + + ) default: return ( diff --git a/bob_party/src/screens/LobbySolo.tsx b/bob_party/src/screens/LobbySolo.tsx index ad51edc..24e32f6 100644 --- a/bob_party/src/screens/LobbySolo.tsx +++ b/bob_party/src/screens/LobbySolo.tsx @@ -1,5 +1,5 @@ import { StatusBar } from 'expo-status-bar' -import { View} from 'react-native' +import { View, Image} from 'react-native' import React from 'react'; import stylesScreen from './style/screens.style' import { TopBar } from '../components/TopBar'; @@ -10,9 +10,6 @@ import { MANAGER_MATCH } from '../../App'; import { useMatchStore } from '../context/matchContext'; - -let tabConv:Conversation[]=[]; - function LobbySolo(props: { navigation: any; }) { const { navigation } = props @@ -21,16 +18,20 @@ function LobbySolo(props: { navigation: any; }) { return ( - - navigation.navigate('GameChoice')} + + + navigation.navigate('GameChoice')} + /> + source={{uri: match?.getGame().getImageSource()}} + /> ); } From 21cf294164a17dfa7048f90140d6d84d7352894f Mon Sep 17 00:00:00 2001 From: Thomas Chazot Date: Tue, 6 Dec 2022 15:35:31 +0100 Subject: [PATCH 13/15] la map --- bob_party/src/screens/GameChoice.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bob_party/src/screens/GameChoice.tsx b/bob_party/src/screens/GameChoice.tsx index 7f15669..2f14155 100644 --- a/bob_party/src/screens/GameChoice.tsx +++ b/bob_party/src/screens/GameChoice.tsx @@ -13,7 +13,11 @@ import { GameSolo } from '../core/gameSolo'; let tabConv:Conversation[]=[]; -const cookieClicker= new GameSolo(1, "Cookie Clicker", "https://codefirst.iut.uca.fr/git/BOB_PARTEAM/BOB_PARTY/raw/branch/typescript/bob_party/assets/ImagesJeux/Pong.png", "/Games/CookieClicker/cookieClicker.tsx", 1, 1, new Map); +const cookieClicker= new GameSolo(1, "Cookie Clicker", "https://codefirst.iut.uca.fr/git/BOB_PARTEAM/BOB_PARTY/raw/branch/typescript/bob_party/assets/ImagesJeux/Pong.png", "/Games/CookieClicker/cookieClicker.tsx", 1, 1, new Map([ + [100, 100], + [1000, 300], + [10000, 200] +])); function GameChoice(props: { navigation: any; }) { From ac9440bfe28c6a606669039b26af6506fd4fd718 Mon Sep 17 00:00:00 2001 From: aguilhot Date: Tue, 6 Dec 2022 15:32:52 +0100 Subject: [PATCH 14/15] ADD: Navigation jeu --- bob_party/src/components/GameComponent.tsx | 2 +- bob_party/src/navigation/AppNavigator.tsx | 23 +++++++++++++++++----- bob_party/src/screens/LobbySolo.tsx | 11 ++++++----- 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/bob_party/src/components/GameComponent.tsx b/bob_party/src/components/GameComponent.tsx index 1cb3990..8b5579b 100644 --- a/bob_party/src/components/GameComponent.tsx +++ b/bob_party/src/components/GameComponent.tsx @@ -33,7 +33,7 @@ FC<{game: Game, nav: any}> = let match=await m.createMatch(tmp, game); MANAGER_MATCH.setCurrentMatch(match); setMatch(match); - nav.navigate("LobbySolo"); + nav.navigate("GameSolo"); } } diff --git a/bob_party/src/navigation/AppNavigator.tsx b/bob_party/src/navigation/AppNavigator.tsx index 1debeaa..142751d 100644 --- a/bob_party/src/navigation/AppNavigator.tsx +++ b/bob_party/src/navigation/AppNavigator.tsx @@ -13,7 +13,7 @@ import GameChoice from '../screens/GameChoice' import SignIn from '../screens/SignIn' import SignUp from '../screens/SignUp' import LobbySolo from '../screens/LobbySolo' - +import CookieClicker from '../Games/CookieClicker/cookieClicker' const HomeStack = createStackNavigator(); @@ -78,13 +78,26 @@ const GameChoiceStack = createStackNavigator(); */ function GameChoiceStackScreen() { return ( - - - - + + + + ); } +const GameSoloStack = createStackNavigator(); + +/* + Stack of screens for the profile and the changement of informations +*/ +function GameSoloStackScreen() { + return ( + + + + + ); +} const Tab = createBottomTabNavigator() /* diff --git a/bob_party/src/screens/LobbySolo.tsx b/bob_party/src/screens/LobbySolo.tsx index 24e32f6..7609175 100644 --- a/bob_party/src/screens/LobbySolo.tsx +++ b/bob_party/src/screens/LobbySolo.tsx @@ -23,15 +23,16 @@ function LobbySolo(props: { navigation: any; }) { state='matchmacking' /> - navigation.navigate('GameChoice')} - /> + navigation.navigate(match?.getGame().getName().replace(/\s/g, ''))} + /> + /> ); } From d2829c3fbf5012e7be86cf9a27153f1a84e8bd19 Mon Sep 17 00:00:00 2001 From: Thomas Chazot Date: Tue, 6 Dec 2022 15:36:14 +0100 Subject: [PATCH 15/15] changement style cookie clicker --- bob_party/src/Games/CookieClicker/cookieClicker.tsx | 2 +- bob_party/src/screens/GameChoice.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bob_party/src/Games/CookieClicker/cookieClicker.tsx b/bob_party/src/Games/CookieClicker/cookieClicker.tsx index d2a0bd1..5bb8fd5 100644 --- a/bob_party/src/Games/CookieClicker/cookieClicker.tsx +++ b/bob_party/src/Games/CookieClicker/cookieClicker.tsx @@ -182,7 +182,7 @@ function CookieClicker(props: { navigation: any}){ const styles = StyleSheet.create({ container: { - top: 5, + top: 20, margin: 10, flex: 1, justifyContent: 'center', diff --git a/bob_party/src/screens/GameChoice.tsx b/bob_party/src/screens/GameChoice.tsx index 2f14155..068c3c1 100644 --- a/bob_party/src/screens/GameChoice.tsx +++ b/bob_party/src/screens/GameChoice.tsx @@ -16,7 +16,7 @@ let tabConv:Conversation[]=[]; const cookieClicker= new GameSolo(1, "Cookie Clicker", "https://codefirst.iut.uca.fr/git/BOB_PARTEAM/BOB_PARTY/raw/branch/typescript/bob_party/assets/ImagesJeux/Pong.png", "/Games/CookieClicker/cookieClicker.tsx", 1, 1, new Map([ [100, 100], [1000, 300], - [10000, 200] + [10000, 400] ]));